Michael Kennedy and Brian Okken

Python Bytes

Developer headlines delivered directly to your earbuds
Python Bytes


Python Bytes is a weekly podcast hosted by Michael Kennedy and Brian Okken. The show is a short discussion on the headlines and noteworthy news in the Python, developer, and data science space.

Link: http://pythonbytes.fm/




#175 Python string theory with superstring.py

Apr 1, 2020 00:32:43


Sponsored by Datadog: pythonbytes.fm/datadog

Special Guest: Matt Harrison

Topic #0: Quick chat about COVID 19.

What does your world look like? Amusing to see news channels, daily shows, etc, learning what we podcasters have figured out years ago

Brian #1: Dictionary Merging and Updating in Python 3.9

Yong Cui, Ph.D. Python 3.9, scheduled for Oct release, will introduce new merge (|) and update (|=) operators, a.k.a. union operators Available in alpha 4 and later see also pep 584 # merge d1 = {'a': 1, 'b': 2} d2 = {'c': 3, 'd': 4} d3 = d1 | d2 # d3 is now {'a': 1, 'b': 2, 'c': 3, 'd': 4} # update d1 = {'a': 1, 'b': 2} d1 |= {'c': 3, 'd': 4} # d1 is now {'a': 1, 'b': 2, 'c': 3, 'd': 4} # last one wins if contention for both | and |= d1 = {'a': 1, 'b': 2} d1 |= {'a': 10, 'c': 3, 'd': 4} # d1 is now {'a': 10, 'b': 2, 'c': 3, 'd': 4}

Matt #2: superstring

An efficient library for heavy-text manipulation in Python, that achieves a remarkable memory and CPU optimization. Uses Rope (data structure) and optimization techniques. Performance comparisons for 50,000 char text memory: 1/20th speed: 1/5th Features Fast and Memory-optimized Rich API concatenation (a + b) len() and .length() indexing slicing strip lower upper Similar functionalities to python built-in string Easy to embed and use. I wonder if any of these optimizations could be brought into CPython Beware, it’s lacking tests

Michael #3: New pip resolver to roll out this year

via PyCoders The developers of pip are in the process of developing a new resolver for pip (as announced on the PSF blog last year). As part of that work, there will be some major changes to how pip determines what to install, based on package requirements. What will change: It will reduce inconsistency: it will no longer install a combination of packages that is mutually inconsistent. It will be stricter - if you ask pip to install two packages with incompatible requirements, it will refuse (rather than installing a broken combination, like it does now). What you can do to help First and most fundamentally, please help us understand how you use pip by talking with our user experience researchers. Even before we release the new resolver as a beta, you can help by running **pip check** on your current environment. Please make time to test the new version of pip, probably in May. Spread the word! And if you develop or support a tool that wraps pip or uses it to deliver part of your functionality, please make time to test your integration with our beta in May

Matt #4: Covid-19 Data

Think global act local Problem - No local data Made my own plots - current status no predictions ML works ok for basic model Implementing SIR Model with ordinary differential equations scipy odeint function

Brian #5: Why does all() return True if the iterable is empty?

Carl Johnson Q: “Why does all() return True if the iterable is empty? Shouldn’t it return False just like if my_list:would evaluate to False if the list is empty? What’s the thinking behind it returning True?” Lesson 1: "… basically doesn’t matter. The Python core team chose to make all([])return True, and whatever their reasons, you can program your way around by adding wrapper functions or if tests. ” Lesson 2: “all unicorns are blue” Lesson 3: “This is literally a 2,500 year old debate in philosophy. The ancients thought “all unicorns are blue” should be false because there are no unicorns, but modern logic says it is true because there are no unicorns that aren’t blue. Python is just siding with modern predicate logic, but your intuition is also quite common and was the orthodox position until the last few hundred years.” Blog post goes into teaching about predicate logic, Socrates, Aristotelean syllogisms, and such. And, really, no answer to why. But now, I’ll never forget that all([]) == True.

Michael #6: pytest-monitor

written by Jean-Sébastien Dieu pytest plugin for analyzing resource usage during test sessions Analyze your resources consumption through test functions: memory consumption time duration CPU usage Keep a history of your resource consumption measurements. Compare how your code behaves between different environments. Usage: Simply run pytest as usual: pytest-monitor is active by default as soon as it is installed. After running your first session, a .pymon sqlite database will be accessible in the directory where pytest was run. You will need a valid Python 3.5+ interpreter. To get measures, we rely on: psutil to extract CPU usage memory_profiler to collect memory usage and pytest (obviously!)



switchlang is now on pypi : pip install switchlang markdown-subtemplate is now on pypi: pip install markdown-subtemplate


Light timer fix: https://twitter.com/Sarcastic_Pharm/status/1238060786658009089

#174 Happy developers use Python 3

Mar 26, 2020 00:47:44


Sponsored by us! Talk Python courses & pytest book.

Topic #0: Quick chat about COVID 19.

Brian #1: Documentation as a way to build Community

Melissa Mendonça “… educational materials can have a huge impact and effectively bring people into the community.” Quality documentation for OSS is often lacking due to: decentralized development documentation is not as glamorous or as praised as new features or major bug fixes “Even when the community is welcoming, documentation is often seen as a "good first issue", meaning that the docs end up being written by the least experienced contributors in the community.” Possible solution: organize/re-organize docs into: tutorials how-tos reference guide explanations consequences: Improving on the quality and discoverability Clear difference between docs aimed at different users Give users more opportunities to contribute, generating content that can be shared directly on the official documentation Building a documentation team as a first-class team in the project, which helps create an explicit role as documentation creator. This helps people better identify how they can contribute beyond code. Diversifying our contributor base, allowing people from different levels of expertise and different life experiences to contribute. This is also extremely important so that we have a better understanding of our community and can be accessible, unbiased and welcoming to all people. Referenced in article: "What nobody tells you about documentation"

Michael #2: The Django Speed Handbook: making a Django app faster

By Shibel Mansour Speed of your app is very important: 100ms is an eternity. SEO, user conversions, bounce rates, etc. Use the tried-and-true django-debug-toolbar. Analyze your request/response cycles and see where most of the time is spent. Provides database query execution times and provides a nice SQL EXPLAIN in a separate pane that appears in the browser. ORM/Database: Two ORM functionalities I want to mention first: these are select_related and prefetch_related. Nice 24x perf improvement example in the article. Basically, beware of the N+1 problem. Indexes: Be sure to add them but they slow writes. Pagination: Use it if you have lots of data Async / background tasks. Content size: Shrunk 9x by adding gzip middleware Static files: minify and bundle as you can, cache, serve through nginx, etc. At Python Bytes, Talk Python, etc, we use webassets, cssmin, and jsmin. PageSpeed from Google, talk python’s ranking. ImageOptim (for macOS, others) Lazy-loading images: Lazily loading images means that we only request them when or a little before they enter the client’s (user’s) viewport. With excellent, dependency-free JavaScript libraries like LazyLoad, there really isn’t an excuse to not lazy-load images. Moreover, Google Chrome natively supports the lazy attribute. Remember: Test and measure everything, before and after.

Brian #3: dacite: simplifies creation of data classes from dictionaries

Konrad Hałas dataclasses are awesome quick and easy fields can have default values be excluded from comparison and/or repr and more data often gets to us in dictionaries Converting from dict to dataclass is trivial for trivial cases: x = MyClass(**data_as_dict) For more complicated conversions, you need dacite dacite.from_dict supports: nested structures optional fields and unions collections type_hooks, which allow you to have custom converters for certain types strict mode. Normally allows extra input data that is just ignored if it doesn’t match up with fields. But you can use strict to not allow that. Raises exceptions when something weird happens, like the wrong type, missing values, etc.

Michael #4: How we retired Python 2 and improved developer happiness

By Barry Warsaw The Python Clock is at 0:00. In 2018, LinkedIn embarked on a multi-quarter effort to fully transition to a Python 3 code base. In total, the effort entailed the migration of about 550 code repositories. They don't use Python in our product or as a monolithic web service, and instead have hundreds of independent microservices and tools, and dozens of supporting libraries, all owned by independent teams in separate repositories. In the early days, most of internal libraries were ported to be “bilingual,” meaning they could be used in either Python 2 or 3. Given that the migration affected all of LinkedIn engineering across so many disparate teams and thousands of engineers, the effort was overseen by our Horizontal Initiatives (HI) program. Phase 1: In the first quarter of 2019, we performed detailed dependency graphing, identifying a number of repositories that were more foundational, and thus needed to be fully ported first because they blocked the ports of everything that depended on them. Phase 2: In the second quarter of 2019, we identified the remainder of repositories that needed porting Post-migration reflections: Our primary indicator for completing the migration of a multiproduct was that it built successfully and passed its unit and integration tests. For other organizations planning or in the midst of their own migration paths, we offer the following guidelines: Plan early, and engage your organization’s Python experts. Find and leverage champions in your affected teams, and promote the benefits of Python 3. Adopt the bilingual approach to supporting libraries so that consumers of your libraries can port to Python 3 on their own schedules. Invest in tests and code coverage—these will be your best success metrics. Ensure that your data models are explicit and clear, especially in identifying which data are bytes and which are human-readable text. Benefits: No longer have to worry about supporting Python 2 and have seen our support loads decrease. Can now depend on the latest open source libraries and tools, and free from the constrictions of having to write bilingual Python. Opportunistically and enthusiastically adopting type hinting and the mypy type checker, improving the overall quality, craft, and readability of Python code bases.

Brian #5: The Troublesome Active Record Pattern

Cal Paterson "Object relational mappers" (ORMs) exist to bridge the gap between the programmers' friend (the object), and the database's primitive (the relation). Examples include Django ORM and SQLAlchemy The Active Record pattern of data access is marked by: A whole-object basis Access by key (mostly primary key) Problem: Queries that don’t need all information for objects retrieve it all anyway, and it’s easy to code for loops to select or collect info that are wildly inefficient. how many books are there how many books about software testing written by Oregon authors Problem: transactions. people can forget to use transactions, some ORMs don’t support them, they are not taught in beginner tutorials, etc. SQLAlchemy has sessions Django has atomic() REST APIs can suffer the same problems. Solutions: just use SQL first class queries first class transactions avoid Active Record style access patterns Be careful with REST APIs Alternatives: GraphQL RPC-style APIs

Michael #6: Types at the edges in Python

By Steve Brazier For a new web service in python there are 3 things to start with: Pydantic mypy Production error tracking of some kind Why: Because what is this about? AttributeError: 'NoneType' object has no attribute 'strip' It should be: none is not an allowed value (type=type_error.none.not_allowed) We then launch this code into production and our assumptions are tested against reality. If we’re lucky our assumptions turn out to be correct. If not we likely encounter some cryptic NoneType errors like the one at the start of this post. Pydantic can help by formalizing our assumptions. mypy carries on helping: Once you see the error at the start of this post (thanks error reporting) you know what is wrong about assumptions. Make the following change to your code: field: typing.Optional[str] BTW: FastAPI integrates with Pydantic out of the box. A mini-kata like exercise here that can be worked through: meadsteve/types-at-the-edges-minikata



Python Bytes Awesome Package List by Jack Mckew Visual Basic Will Stall Out With .NET 5 COVID 19 data sets New course in dev: Adding a CMS to Your Data-Driven Web App [in Pyramid|Flask]


#173 You test deserves a fluent flavor

Mar 19, 2020 00:28:38


Sponsored by Datadog: pythonbytes.fm/datadog

Brian #1: Advanced usage of Python requests - timeouts, retries, hooks

Dani Hodovic, @DaniHodovic “While it's easy to immediately be productive with requests because of the simple API, the library also offers extensibility for advanced use cases. If you're writing an API-heavy client or a web scraper you'll probably need tolerance for network failures, helpful debugging traces and syntactic sugar.” Lots of cool tricks I didn’t know you could do with requests. Using hooks to call raise_for_status() on every call. Using sessions and setting base URLs Setting default timeouts with transport adapters Retry on failure, with gobs of configuration options. Combining timeouts and retries Debugging http requests by printing out headers or printing everything. Testing and mocking requests Mimicking browser behaviors by overriding the User-Agent header request

Michael #2: Fluent Assertions

Via Dean Agan fluentcheck helps you reducing the lines of code providing a human-friendly and fluent way to make assertions. Example (for now): def my_function(n, obj): assert n is not None assert instanceof(n, float) assert 0. < n < 1 assert obj is not None assert isinstance(obj, MyCustomType)

can be

def my_function(n, obj): Check(n).is_not_None().is_float().is_between(0., 1.) Check(obj).is_not_None().is_subtype_of(MyCustomType)

With a PR I’m working on (now accepted), it’ll support:

def my_function(n, obj): Is(n).not_none.float.between(0., 1.) Is(obj).not_none.subtype_of(MyCustomType)

Brian #3: Python in GitHub Actions

Hynek Schlawack, @hynek “for an open source Python package, … my current recommendation for most people is to switch to GitHub Actions for its simplicity and better integration.” vs Azure Pipelines. Article describes how to get started and some basic configuration for: Running tests through tox, including coverage, for multiple Python versions. Including yml config and tox.ini changes necessary. Nice reminder to clean out old configurations for other CIs. Combining coverage reports and pushing code coverage info to Codecov Building the package. Running twine check to check the long description. Checking the install on Linux, Windows, and Mac Related: How to write good quality Python code with GitHub Actions

Michael #4: VCR.py

via Tim Head VCR.py simplifies and speeds up tests that make HTTP requests. The first time you run code that is inside a VCR.py context manager or decorated function, VCR.py records all HTTP interactions that take place through the libraries it supports and serializes and writes them to a flat file (in yaml format by default). Intercept any HTTP requests that it recognizes from the original test run and return the responses that corresponded to those requests. This means that the requests will not actually result in HTTP traffic, which confers several benefits including: The ability to work offline Completely deterministic tests Increased test execution speed If the server you are testing against ever changes its API, all you need to do is delete your existing cassette files, and run your tests again. Test and Code 102 pytest-vcr: pytest plugin for managing VCR.py cassettes @pytest.mark.vcr() def test_iana(): response = urlopen('http://iana.org/domains/reserved').read() assert b'Example domains' in response

Brian #5: 8 Coolest Python Programming Language Features

Jeremy Grifski, @RenegadeCoder94 Nice reminder of why I love Python and things I miss when I use other languages. The list list comprehensions generator expressions slice assignment iterable unpacking negative indexing dictionary comprehensions chaining comparisons f-strings

Michael #6: Bento

Find Python web-app bugs delightfully fast, without changing your workflow Find bugs that matter: Checks find security and reliability bugs in your code. They’re vetted across thousands of open source projects and never nit your style. Upgrade your tooling: You don’t have to fix existing bugs to adopt Bento. It’s diff-centric, finding new bugs introduced by your changes. And there’s zero config. Go delightfully fast: Run Bento automatically locally or in CI. Either way, it runs offline and never sends your code anywhere. Checks: https://bento.dev/checks/



#172 Floating high above the web with Helium

Mar 13, 2020 00:32:54


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Michael #1: Python in Production Hynek

Missing a key part from the public Python discourse and I would like to help to change that. Hynek was listening to a podcast about running Python services in production. Disagreed with some of the choices they made, it acutely reminded me about what I’ve been missing in the past years from the public Python discourse. And yet despite the fact that the details aren’t relevant to me, the mindsets, thought processes, and stories around it captivated me and I happily listened to it on my vacation. Python conferences were a lot more like this. I remember startups and established companies alike to talk about running Python in production, lessons learned, and so on. (Instagram and to a certain degree Spotify being notable exceptions) An Offer: So in a completely egoistical move, I would like to encourage people who do interesting stuff with Python to run websites or some kind of web and network services to tell us about it at PyCons, meetups, and in blogs. Dan Bader and I covered this back on Talk Python, episode 215.

Brian #2: How to cheat at unit tests with pytest and Black

Simon Willison Premise: “In pure test-driven development you write the tests first, and don’t start on the implementation until you’ve watched them fail.” too slow, so …, “cheat” write a pytest test that calls the function you are working on and compares the return value to something obviously wrong. when it fails, copy the actual output and paste it into your test now it should pass run black to reformat the huge return value to something manageable Brian’s comments: That’s turning exploratory and manual testing into automated regression tests, not cheating. There is no “pure test-driven development”, we still can’t agree on what a unit is or if mocks are good or evil.

Michael #3: Goodbye Microservices: From 100s of problem children to 1 superstar

Retrospective by Alexandra Noonan Javascript but the lessons are cross language Microservices is the architecture du jour Segment adopted this as a best practice early-on, which served us well in some cases, and, as you’ll soon learn, not so well in others. Microservices is a service-oriented software architecture in which server-side applications are constructed by combining many single-purpose, low-footprint network services. Touted benefits are improved modularity, reduced testing burden, better functional composition, environmental isolation, and development team autonomy. Instead of enabling us to move faster, the small team found themselves mired in exploding complexity. Essential benefits of this architecture became burdens. As our velocity plummeted, our defect rate exploded. Her post is the story of how we took a step back and embraced an approach that aligned well with our product requirements and needs of the team.

Brian #4: Helium

Michael #5: uncertainties package

From Tim Head on upcoming Talk Python Binder episode. Do you know how uncertainty flows through calculations? Example: Jane needs to calculate the volume of her pool, so that she knows how much water she'll need to fill it. She measures the length, width, and height: length L = 5.56 +/- 0.14 meters = 5.56 m +/- 2.5% width W = 3.12 +/- 0.08 meters = 3.12 m +/- 2.6% depth D = 2.94 +/- 0.11 meters = 2.94 m +/- 3.7%

One can find the percentage uncertainty in the result by adding together the percentage uncertainties in each individual measurement:

percentage uncertainty in volume = (percentage uncertainty in L) + (percentage uncertainty in W) + (percentage uncertainty in D) = 2.5% + 2.6% + 3.7% = 8.8% We don’t want to deal with these manually! So we use the uncertainties package. Example of using the library: >>> from uncertainties import ufloat >>> from uncertainties.umath import * # sin(), etc. >>> x = ufloat(1, 0.1) # x = 1+/-0.1 >>> print 2*x 2.00+/-0.20 >>> sin(2*x) # In a Python shell, "print" is optional 0.9092974268256817+/-0.08322936730942848

Brian #6: Personalize your python prompt

Arpit Bhayani Those three >>> in the interactive Python prompt. you can muck with those by changing sys.ps1 Fun. But you can also implement dynamic behavior by creating class and putting code in the __str__ method. Very clever. note to self: task for the day: reproduce the windows command prompt with directory listing and slashes in the other direction.



Now that Python for Absolute Beginners is out, starting on a new course: Hybrid Data-Driven + CMS web apps.

Joke: A Python Editor Limerick

via Alexander A.


To this day, some prefer BBEdit. VSCode is now getting some credit. Vim and Emacs are fine; so are Atom and Sublime. Doesn't matter much, if you don't let it.

But wait! Let's not forget IDEs! Using PyCharm sure is a breeze! Komodo, Eclipse, and IDEA; CLion is my panacea, and XCode leaves me at ease.

But Jupyter Notebook is also legit! Data scientists must prefer it. In the browser, you code; results are then showed. But good luck when you try to use git.

#171 Chilled out Python decorators with PEP 614

Mar 5, 2020 00:34:34


Sponsored by Datadog: pythonbytes.fm/datadog

Special guest: David Amos

David #1: PEP 614 – Relaxing Grammar Restrictions on Decorators

Python currently requires that all decorators consist of a dotted name, optionally followed by a single call. E.g., can’t use subscripts or chained calls PEP proposes allowing any valid expression. Motivation for limitation is not a technical requirement: “I have a gut feeling about this one. I'm not sure where it comes from, but I have it... So while it would be quite easy to change the syntax in the future, I'd like to stick to the more restricted form unless a real use case is presented where [changing the syntax] would increase readability.” (Guido van Rossom, Source) Use case highlighted by PEP: List of Qt buttons: buttons = [button0, button1, …] Decorator is a method on a class attribute: button.clicked.connect Under current restrictions you can’t do @button[0].clicked.connect Workarounds involve assigning list element to a variable first: button0 = buttons[0] @button0.clicked.connect Author points out grammar is already loose enough to hack around: Define function def _(x): return x Then use _ as your decorator: @_(buttons[0].clicked.connect) That’s less readable than just using the subscript PEP proposes relaxing grammar to “any valid expression” (sort of), i.e. anything that you can use as a test in if, elif, or while blocks (as opposed to valid string input to eval) Some things wouldn’t be allowed, though E.g., tuples require parentheses, @f, g doesn’t make sense Does a tuple as a decorator make sense in the first place, though? CPython implementation on GitHub: https://github.com/brandtbucher/cpython/tree/decorators

Michael #2: Create a macOS Menu Bar App with Python (Pomodoro Timer)

by Camillo Visini Nice article: Learn how to create your very own macOS Menu Bar App using Python, rumps and py2app The mac menu bar is super useful. I leverage the heck out of this thing. Why not write Python for it? Tools: Python 3 and PyCharm as an IDE Rumps → Ridiculously Uncomplicated macOS Python Statusbar apps py2app → For creating standalone macOS apps from Python code (how cool is that?) Get started with the code: app = rumps.App("Pomodoro", "🍅") app.run() Then easily use Py2App to convert this into a full macOS app. Would love to see somebody try to submit one of these to the mac app store.

Brian #3: Conditional Coverage

Nikita Sobolev - CTO of wemake.services announcement post, repo suggested from @OpensourceF: https://twitter.com/OpensourceF/status/1232264318323957760 From README.md: Conditional coverage based on any rules you define! Some project have different parts that relies on different environments: Python version, some code is only executed on specific versions and ignored on others OS version, some code might be Windows, Mac, or Linux only External packages, some code is only executed when some 3rd party package is installed Traditional method: combine coverage data before reporting. This works ok on CI systems or with tox for multiple Python/package version. Doesn’t help much locally if wanting split is due to OS dependencies Requires multiple test runs to get full coverage New coverage plugin allows you to maintain coverage while developing locally. single test run and a reasonable coverage report So cool. Recommend to keep conditionals to a minimum and somewhat isolated. I wouldn’t want this all over my code base. Still want real full coverage on CI.

David #4: Pycel – A library for compiling excel spreadsheets to python code & visualizing them as a graph

Compile an Excel file with formulas as a Python object The compiler converts formulas in the spreadsheet to executable code Once compiled, you can set values for cells and inspect the output in other cells This is all happening in Python now, not touching Excel anymore You can visualize all of the formulas as a graph to explore how formulas depend on one another The author of the package wrote it to solve a problem in civilian aerospace engineering Blog post here: https://dirkgorissen.com/2011/10/19/pycel-compiling-excel-spreadsheets-to-python-and-making-pretty-pictures/ From 2011, but still relevant! Finally, with all the formulas compiled, the package can solve for variables using an optimization process In original use case this was to optimize engineering parameters to produce aircraft that could actually fly Author describes how using Python he increased the cases that could be optimized from 65% to 98% and reduced calculation time from 10 minutes to around 30 seconds to 1 minute.

Michael #5: markdown-subtemplate

A template engine to render Markdown with external template imports and basic variable replacements. Choice between data-driven server apps (typical Flask app), CMSes that let us edit content on the web such as WordPress, and even flat file systems like Pelican. This should not be a black and white decision. Here's how it works: You write standard markdown files for content. Markdown files can be shared and imported into your top-level markdown. Fragments of HTML can be used when css classes and other specializations are needed, but generally HTML is avoided. A dictionary of variables and their values to replace in the merged markdown is processes. Markdown content is converted to HTML and embedded in your larger site layout (e.g. within a Jinja2 template). Markdown transforms are cached to achieve very high performance regardless of the complexity of the content. Extensible logging and caching. Extensible storage coming soon. PRs and contributions are welcome. More to come

Brian #6: FlakeHell

wemake.services, from Conditional Coverage, also makes the wemake-python-styleguide, and recommends using FlakeHell Allows you to configure flake8 and plugins more easily in pyproject.toml files. Provides a ramp to start using linting tools with “legacy first”: flakehell baseline > .flakehell_baseline specify that file in your pyproject.toml flakehell lint will run your liniting tools and only report new failures you can start fixing older stuff later, or just apply style guide to new code. Lots of awesome shortcuts for configuration with wildcards and such. Can specify a shared config in one repo and use it multiple projects as a starting point with local changes. FlakeHell: It's a Flake8 wrapper to make it cool. Shareable and remote configs. Legacy-friendly: ability to get report only about new errors. Caching for much better performance. Use only specified plugins, not everything installed. Manage codes per plugin. Enable and disable plugins and codes by wildcard. Make output beautiful. pyproject.toml support. Show codes for installed plugins. Show all messages and codes for a plugin. Check that all required plugins are installed. Syntax highlighting in messages and code snippets. PyLint integration. Allow codes intersection for different plugins.



Lots of great new content weekly on Test & Code Podcast


Qt follow up Moon base geekout


PyTexas 2020 Registration Opening Registration page


Why does it work!?!

#169 Jupyter Notebooks natively on your iPad

Feb 19, 2020 00:25:44


Sponsored by Datadog: pythonbytes.fm/datadog

Brian #1: D-Tale

suggested by @davidouglasmit via twitter “D-Tale is the combination of a Flask back-end and a React front-end to bring you an easy way to view & analyze Pandas data structures. It integrates seamlessly with ipython notebooks & python/ipython terminals. Currently this tool supports such Pandas objects as DataFrame, Series, MultiIndex, DatetimeIndex & RangeIndex.” way cool UI for visualizing data Live Demo shows Describe shows column statistics, graph, and top 100 values filter, correlations, charts, heat map

Michael #2: Carnets

by Nicolas Holzschuch A standalone Jupyter notebooks implementation for iOS. The power of Jupyter notebooks. In your pocket. Anywhere. Everything runs on your device. No need to setup a server, no need for an internet connection. Standard packages like Numpy, Matplotlib, Sympy and Pandas are already installed. You're ready to edit notebooks. Carnets uses iOS 11 filesharing ability. You can store your notebooks in iCloud, access them using other apps, share them. Extended keyboard on iPads, you get an extended toolbar with basic actions on your keyboard. Install more packages: Add more Python packages with %pip (if they are pure Python). OpenSource: Carnets is entirely OpenSource, and released under the FreeBSD license.

Brian #3: BeeWare Podium

suggested by Katie McLaughlin, @glasnt on twitter NOT a pip install, download a binary from https://github.com/beeware/podium/releases Linux and macOS Still early, so you gotta do the open and trust from the apps directory thing for running stuff not from the app store. But Oh man is it worth it. HTML5 based presentation frameworks are cool. run a presentation right in your browser. My favorite has been remark.js presenter mode, notes are especially useful while practicing a talk running timer super helpful while giving a talk write talk in markdown, so it’s super easy to version control issues: presenter mode, full screen, with extended monitor hard to do. notes and timer on laptop, full presentation on extended screen super cool but requires full screening with mouse Podium uses similar syntax as remark.js and I think uses remark under the hood. but it’s a native app, not a browser Handles the presenter mode and extended screen smoothly, like keynote and others. Removes the need for boilerplate html in your markdown file (remark.js md files have cruft). Can’t wait to try this out for my next presentation

Michael #4: pytest-mock-resources

via Daniel Cardin pytest fixture factories to make it easier to test against code that depends on external resources like Postgres, Redshift, and MongoDB. Code which depends on external resources such a databases (postgres, redshift, etc) can be difficult to write automated tests for. Conventional wisdom might be to mock or stub out the actual database calls and assert that the code works correctly before/after the calls. Whether the actual query did the correct thing truly requires that you execute the query. Having tests depend upon a real postgres instance running somewhere is a pain, very fragile, and prone to issues across machines and test failures. Therefore pytest-mock-resources (primarily) works by managing the lifecycle of docker containers and providing access to them inside your tests.

Brian #5: How James Bennet is testing in 2020

Follow up from Testing Django applications in 2018 Favors unittest over pytest. tox for testing over multiple Django and Python versions, including tox-travis plugin pyenv for local Python installation management and pyenv-virtualenv plugin for venvs. Custom runtests.py for setting up environment and running tests. Changed to src/ directory layout. Coverage and reporting failure if coverage dips, with a healthy perspective: “… this isn’t because I have 100% coverage as a goal. Achieving that is so easy in most projects that it’s meaningless as a way to measure quality. Instead, I use the coverage report as a canary. It’s a thing that shouldn’t change, and if it ever does change I want to know, because it will almost always mean something else has gone wrong, and the coverage report will give me some pointers for where to look as I start investigating.” Testing is more than tests, it’s also black, isort, flake8, mypy, and even spell checking sphinx documentation. Using tox.ini for utility scripts, like cleanup, pipupgrade, …

Michael #6: Python and PyQt: Building a GUI Desktop Calculator

by by Leodanis Pozo Ramos at realpython Some interesting take-aways: Basics of PyQt Widgets: QWidget is the base class for all user interface objects, or widgets. These are rectangular-shaped graphical components that you can place on your application’s windows to build the GUI. Layout Managers: Layout managers are classes that allow you to size and position your widgets at the places you want them to be on the application’s form. Main Windows: Most of the time, your GUI applications will be Main Window-Style. This means that they’ll have a menu bar, some toolbars, a status bar, and a central widget that will be the GUI’s main element. Applications: The most basic class you’ll use when developing PyQt GUI applications is QApplication. This class is at the core of any PyQt application. It manages the application’s control flow as well as its main settings. Signals and Slots: PyQt widgets act as event-catchers. Widgets always emit a signal, which is a kind of message that announces a change in its state. Due to Qt licensing, you can only use the free version for non-commercial projects or internal non-redistributed or purchase a commercial license for $5,500/yr/dev.



PyCascades 2020 livestream videos of day 1 & day 2 are available. Huge shout-out and thank you to all of the volunteers for this event. In particular Nina Zakharenko for calming me down before my talk.


Recording for Python for .NET devs webcast available. Take some of our free courses with our mobile app.


Why do programmers confuse Halloween with Christmas? Because OCT 31 == DEC 25. Speed dating is useless. 5 minutes is not enough to properly explain the benefits of the Unix philosophy.

#167 Cheating at Kaggle and uWSGI in prod

Feb 3, 2020 00:28:30


Sponsored by Datadog: pythonbytes.fm/datadog

Special guest: Vicki Boykis: @vboykis

Michael #1: clize: Turn functions into command-line interfaces

via Marcelo Follow up from Typer on episode 164. Features Create command-line interfaces by creating functions and passing them to [clize.run](https://clize.readthedocs.io/en/stable/api.html#clize.run). Enjoy a CLI automatically created from your functions’ parameters. Bring your users familiar --help messages generated from your docstrings. Reuse functionality across multiple commands using decorators. Extend Clize with new parameter behavior. I love how this is pure Python without its own API for the default case

Vicki #2: How to cheat at Kaggle AI contests

Kaggle is a platform, now owned by Google, that allows data scientists to find data sets, learn data science, and participate in competitions Many people participate in Kaggle competitions to sharpen their data science/modeling skills Recently, a competition that was related to analyzing pet shelter data resulted in a huge controversy Petfinder.my is a platform that helps people find pets to rescue in Malaysia from shelters. In 2019, they announced a collaboration with Kaggle to create a machine learning predictor algorithm of which pets (worldwide) were more likely to be adopted based on the metadata of the descriptions on the site. The total prize offered was $25,000 After several months, a contestant won. He was previously a Kaggle grandmaster, and won $10k. A volunteer, Benjamin Minixhofer, offered to put the algorithm in production, and when he did, he found that there was a huge discrepancy between first and second place Technical Aspects of the controversy: The data they gave asked the contestants to predict the speed at which a pet would be adopted, from 1-5, and included input features like type of animal, breed, coloration, whether the animal was vaccinated, and adoption fee The initial training set had 15k animals and the teams, after a couple months, were then given 4k animals that their algorithms had not seen before as a test of how accurate they were (common machine learning best practice). In a Jupyter notebook Kernel on Kaggle, Minixhofer explains how the winning team cheated First, they individually scraped Petfinder.my to find the answers for the 4k test data Using md5, they created a hash for each unique pet, and looked up the score for each hash from the external dataset - there were 3500 overlaps Did Pandas column manipulation to get at the hidden prediction variable for every 10th pet and replaces the prediction that should have been generated by the algorithm with the actual value Using mostly: obfuscated functions, Pandas, and dictionaries, as well as MD5 hashes Fallout: He was fired from H20.ai Kaggle issued an apology

Michael #3: Configuring uWSGI for Production Deployment

We run a lot of uWSGI backed services. I’ve spoken in-depth back on Talk Python 215: The software powering Talk Python courses and podcast about this. This is guidance from Bloomberg Engineering’s Structured Products Applications group We chose uWSGI as our host because of its performance and feature set. But, while powerful, uWSGI’s defaults are driven by backward compatibility and are not ideal for new deployments. There is also an official Things to Know doc. Unbit, the developer of uWSGI, has “decided to fix all of the bad defaults (especially for the Python plugin) in the 2.1 branch.” The 2.1 branch is not released yet. Warning, I had trouble with die-on-term and systemctl Settings I’m using: # This option tells uWSGI to fail to start if any parameter # in the configuration file isn’t explicitly understood by uWSGI. strict = true # The master uWSGI process is necessary to gracefully re-spawn # and pre-fork workers, consolidate logs, and manage many other features master = true # uWSGI disables Python threads by default, as described in the Things to Know doc. enable-threads = true # This option will instruct uWSGI to clean up any temporary files or UNIX sockets it created vacuum = true # By default, uWSGI starts in multiple interpreter mode single-interpreter = true # Prevents uWSGI from starting if it is unable to find or load your application module need-app = true # uWSGI provides some functionality which can help identify the workers auto-procname = true procname-prefix = pythonbytes- # Forcefully kill workers after 60 seconds. Without this feature, # a stuck process could stay stuck forever. harakiri = 60 harakiri-verbose = true

Vicki #4: Thinc: A functional take on deep learning, compatible with Tensorflow, PyTorch, and MXNet

A deep learning library that abstracts away some TF and Pytorch boilerplate, from Explosion Already runs under the covers in SpaCy, an NLP library used for deep learning type checking, particularly helpful for Tensors: PyTorchWrapper and TensorFlowWrapper classes and the intermingling of both Deep support for numpy structures and semantics Assumes you’re going to be using stochastic gradient descent And operates in batches Also cleans up the configuration and hyperparameters Mainly hopes to make it easier and more flexible to do matrix manipulations, using a codebase that already existed but was not customer-facing. Examples and code are all available in notebooks in the GitHub repo

Michael #5: pandas-vet

via Jacob Deppen A plugin for Flake8 that checks pandas code Starting with pandas can be daunting. The usual internet help sites are littered with different ways to do the same thing and some features that the pandas docs themselves discourage live on in the API. Makes pandas a little more friendly for newcomers by taking some opinionated stances about pandas best practices. The idea to create a linter was sparked by Ania Kapuścińska's talk at PyCascades 2019, "Lint your code responsibly!"

Vicki #6: NumPy beginner documentation

NumPy is the backbone of numerical computing in Python: Pandas (which I mentioned before), scikit-learn, Tensorflow, and Pytorch, all lean heavily if not directly depend on its core concepts, which include matrix operations through a data structure known as a NumPy array (which is different than a Python list) - ndarray Anne Bonner wrote up new documentation for NumPy that introduces these fundamental concepts to beginners coming to both Python and scientific computing Before, you went directly to the section about arrays and had to search through it find what you wanted. The new guide, which is very nice, includes a step-by-step on how arrays work, how to reshape them, and illustrated guides on basic array operations.



I write a newsletter, Normcore Tech, about all things tech that I’m not seeing covered in the mainstream tech media. I’ve written before about machine learning, data for NLP, Elon Musk memes, and Nginx. There’s a free version that goes out once a week and paid subscribers get access to one more newsletter per week, but really it’s more about the idea of supporting in-depth writing about tech. vicki.substack.com


pip 20.0 Released - Default to doing a user install (as if --user was passed) when the main site-packages directory is not writeable and user site-packages are enabled, cache wheels built from Git requirements, and more. Homebrew: brew install python@3.8


An SEO expert walks into a bar, bars, pub, public house, Irish pub, tavern, bartender, beer, liquor, wine, alcohol, spirits...

#166 Misunderstanding software clocks and time

Jan 27, 2020 00:28:21


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Michael #1: Amazon is now offering quantum computing as a service

Amazon Braket – A fully managed service that allows scientists, researchers, and developers to begin experimenting with computers from multiple quantum hardware providers in a single place. We all know about bits. Quantum computers use a more sophisticated data representation known as a qubit or quantum bit. Each qubit can exist in state 1 or 0, but also in superpositions of 1 and 0, meaning that the qubit simultaneously occupies both states. Such states can be specified by a two-dimensional vector that contains a pair of complex numbers, making for an infinite number of states. Each of the complex numbers is a probability amplitude, basically the odds that the qubit is a 0 or a 1, respectively. Amazon Braket is a new service designed to let you get some hands-on experience with qubits and quantum circuits. You can build and test your circuits in a simulated environment and then run them on an actual quantum computer. See linked announcement. Language looks familiar: [1]: bell = Circuit().h(0).cnot(0, 1) print(device.run(bell, s3_folder).result().measurement_counts()) How it Works: Quantum computers work by manipulating the amplitudes of the state vector. To program a quantum computer, you figure out how many qubits you need, wire them together into a quantum circuit, and run the circuit. When you build the circuit, you set it up so that the correct answer is the most probable one, and all the rest are highly improbable.

Brian #2: A quick-and-dirty guide on how to install packages for Python

Brett Cannon Good modern intro to venv use. Pro short. simple. quick uses --prompt in every example (more people need to use this) and suggests using the directory name containing the env. send it to all your co-workers that STILL aren’t using virtual environments hints at an improved form of --prompt coming in Python 3.9 Con uses .venv, I’m a venv (no dot kinda guy) hints at an improved form of --prompt coming in Python 3.9 --prompt . will deduce the directory name. In 3.8 it just names your env “.”.

Michael #3: Say No to the no code movement

Article by Alex Hudson 2020 is going to be the year of “no code”: the movement that say you can write business logic and even entire applications without having the training of a software developer. Every company is a software company But software devs are in short supply and outcomes are variable two distinct benefits to transitioning business processes into the software domain “change control” becomes a software problem rather than a people problem. it’s easier to innovate on what makes a business distinct. The basic problem with “no code” the idea of writing business logic in text form according to the syntax of a technical programming language is anathema. The “simpler abstraction” misconception The “simpler syntax” misconception Configuration over code: Many No Code advocates are building significant systems by pulling together off-the-shelf applications and integrating them. But the logic has been implemented as configuration as opposed to code. The equivalence of code: There are reasons why developers still use plain text, if something came along that was better, many (not all!) developers would drop text like a hot rock. Where does “No code” fail in practice? 80% there and then … Where does “No code” succeed? “No Code” systems are extremely good for putting together proofs-of-concept which can demonstrate the value of moving forward with development.

Brian #4: What I learned going from prison to Python

Shadeed “Sha” Wallace-Stepter Presented at North Bay Python I got this recommended to be by many people, even those not in the Python community, including my good friends Chuck Forbes and Dr. Donna Beegle, who work to fight poverty. Amazing story. Go listen to it.

Michael #5: A real QUICK → Qt5 based gUI generator for ClicK

Via Ricky Teachey. Inspired by Gooey, the GUI generator for classical Python argparse-based command line programs. Take a standard Click-based app, add --gui to the command line and you get a GUI!

Brian #6: Falsehoods programmers believe about time

also More falsehoods programmers believe about time; “wisdom of the crowd” edition

All of these assumptions are wrong

There are always 24 hours in a day. Months have either 30 or 31 days.

A week always begins and ends in the same month.

The system clock will always be set to the correct local time The system clock will always be set to a time that is not wildly different from the correct local time. If the system clock is incorrect, it will at least always be off by a consistent number of seconds.

It will never be necessary to set the system time to any value other than the correct local time. Ok, testing might require setting the system time to a value other than the correct local time but it will never be necessary to do so in production.

Human-readable dates can be specified in universally understood formats such as 05/07/11.

… from more …

The day before Saturday is always Friday.

Two subsequent calls to a getCurrentTime() function will return distinct results. The second of two subsequent calls to a getCurrentTime() function will return a larger result. The software will never run on a space ship that is orbiting a black hole.



REMI GUI editor



#165 Ranges as dictionary keys - oh my!

Jan 21, 2020 00:28:45


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Brian #1: iterators, generators, coroutines

Cool quick read article by Mark McDonnell. Starts with an attempt at a gentle introduction to the iterator protocol (why does everyone think that users need to start with this info?) Muscle through this part or just skim it. Should be an appendix. Generators (start here): functions that use yield Unbound generators: they don’t stop Generator Expressions: Like for v in ("foo" for i in range(5)): … Use parens instead of brackets, otherwise they are like list comprehensions. Specifically: (expression for item in collection if condition) Generators using generators / nested generators : yield from Given bar() and baz() are generators, this works: def foo(): yield from bar() yield from baz() Coroutines are an extension of generators “Generators use the yield keyword to return a value at some point in time within a function, but with coroutines the yield directive can also be used on the right-hand side of an = operator to signify it will accept a value at that point in time.” Then….. coroutine example, some asyncio stuff, … honestly I got lost. Bottom line: I’m still looking for a great tutorial on coroutines that doesn’t explain the iterator protocol (boring!) shows an example NOT using asyncio and NOT a REPL example I want to know how I can make use of coroutines in an actual program (toy ok) where the use of coroutines actually helps the structure and makes it more maintainable, etc.

Michael #2: requests-toolbelt

A toolbelt of useful classes and functions to be used with requests multipart/form-data encoder - The main attraction is a streaming multipart form-data object, MultipartEncoder. User-Agent constructor - You can easily construct a requests-style User-Agent string SSLAdapter - Allows the user to choose one of the SSL protocols made available in Python's ssl module for outgoing HTTPS connections ForgetfulCookieJar - prevents a particular requests session from storing cookies

Brian #3: Pandas Validation

We covered Bulwark in episode 162 There are other approaches and projects looking at the same problem. pandas-validation Suggested by Lance “… pandas-validation lets you create a template of what your pandas dataframe should look like and it'll validate the entire dataframe against that template. So if you have a dataframe with first column being strings second column being dates and the third being address, you can use a mixture of built in validate types to ensure your data conforms to that. It will even let you set up some regex and make sure that the data in a column conforms to that regex.” - Lance supports dates, timestamps, numeric values, strings pandera “pandera provides a flexible and expressive API for performing data validation on tidy (long-form) and wide data to make data processing pipelines more readable and robust." “pandas data structures contain information that pandera explicitly validates at runtime. This is useful in production-critical or reproducible research settings. “pandera enables users to: Check the types and properties of columns in a DataFrame or values in a Series. Perform more complex statistical validation. Seamlessly integrate with existing data analysis/processing pipelines via function decorators.” A few different approaches. I can’t really tell from the outside if there is a clear winner or solution that’s working better for most cases. I’d like to hear from listeners which they use, if any. Or if we missed the obvious validation method most people are using.

Michael #4: qtpy

I have been inspired to check out Qt again, but the libraries and versions a confusing. Provides an uniform layer to support PyQt5, PySide2, PyQt4 and PySide with a single codebase Basically, you can write your code as if you were using PySide2 but import Qt modules from qtpy instead of PySide2 (or PyQt5).

Brian #5: pylightxl

Viktor Kis submission “A light weight, zero dependency, minimal functionality excel read/writer python library” Well. Reader right now. Writing coming soon. :) Some cool examples in the docs to get you started grabbing data from spreadsheets right away. Features: Zero non-standard library dependencies Single source code that supports both Python37 and Python27. The light weight library is only 3 source files that can be easily copied directly into a project for those that have installation/download restrictions. In addition the library’s size and zero dependency makes pyinstaller compilation small and easy! 100% test-driven development for highest reliability/maintainability with 100% coverage on all supported versions API aimed to be user friendly, intuitive and to the point with no bells and whistles. Structure: database > worksheet > indexing example: db.ws('Sheet1').index(row=1,col=2) or db.ws('Sheet1').address(address='B1') Read excel files (.xlsx, .xlsm), all sheets or selective few for speed/memory management Index cells data by row/col number or address Calling an entire row/col of data returns an easy to use list output: db.ws('Sheet1').row(1) or db.ws('Sheet1').rows Worksheet data size is consistent for each row/col. Any data that is empty will return a ‘’

Michael #6: python-ranges

via Aiden Price Continuous Range, RangeSet, and RangeDict data structures for Python Best understood as an example: tax_info = RangeDict({ Range(0, 9701): (0, 0.10, 0), Range(9701, 39476): (970, 0.12, 9700), ... }) income = int(input("What is your income? $")) base, marginal_rate, bracket_floor = tax_info[income] Range and RangeSet objects are mutually compatible for things like union(), intersection(), difference(), and symmetric_difference()


Brian: pytest-check works with pytest-rerunfailures - with other plugins, it may not. - known incompatibility with flaky and retry Michael: Pandas goes 1.0 (via Jeremy Schendel). Just put out a release candidate for 1.0, and will be using SemVer going forward. PyCharm security from Anthony Shaw. Video for Python for Decision Makers webcast is out.


Optimist: The glass is half full. Pessimist: The glass is half empty. Engineer: The glass is twice as large as it needs to be.

#164 Use type hints to build your next CLI app

Jan 16, 2020 00:29:02


Sponsored by Datadog: pythonbytes.fm/datadog

Michael #1: Data driven journalism via cjworkbench

via Michael Paholski The data journalism platform with built in training Think spreadsheet + ETL automation Designed around modular tools for data processing -- table in, table out -- with no code required Features include: Modules to scrape, clean, analyze and visualize data An integrated data journalism training program Connect to Google Drive, Twitter, and API endpoints. Every action is recorded, so all workflows are repeatable and transparent All data is live and versioned, and you can monitor for changes. Write custom modules in Python and add them to the module library

Brian #2: remi: A Platform-independent Python GUI library for your applications.

Python REMote Interface library. “Remi is a GUI library for Python applications which transpiles an application's interface into HTML to be rendered in a web browser. This removes platform-specific dependencies and lets you easily develop cross-platform applications in Python!” No dependencies. pip install git+https://github.com/dddomodossola/remi.git doesn’t install anything else. Yes. Another GUI in a web page, but for quick and dirty internal tools, this will be very usable. Basic app: import remi.gui as gui from remi import start, App class MyApp(App): def __init__(self, *args): super(MyApp, self).__init__(*args) def main(self): container = gui.VBox(width=120, height=100) self.lbl = gui.Label('Hello world!') self.bt = gui.Button('Press me!') self.bt.onclick.do(self.on_button_pressed) container.append(self.lbl) container.append(self.bt) return container def on_button_pressed(self, widget): self.lbl.set_text('Button pressed!') self.bt.set_text('Hi!') start(MyApp)

Michael #3: Typer

Build great CLIs. Easy to code. Based on Python type hints. Typer is FastAPI's little sibling. And it's intended to be the FastAPI of CLIs. Just declare once the types of parameters (arguments and options) as function parameters. You do that with standard modern Python types. You don't have to learn a new syntax, the methods or classes of a specific library, etc. Based on Click Example (min version) import typer def main(name: str): typer.echo(f"Hello {name}") if __name__ == "__main__": typer.run(main)

Brian #4: Effectively using Matplotlib

Chris Moffitt “… I think I was a little premature in dismissing matplotlib. To be honest, I did not quite understand it and how to use it effectively in my workflow.” That very much sums up my relationship with matplotlib. But I’m ready to take another serious look at it. one reason for complexity is 2 interfaces MATLAB like state-based interface object based interface (use this) recommendations: Learn the basic matplotlib terminology, specifically what is a Figure and an Axes . Always use the object-oriented interface. Get in the habit of using it from the start of your analysis. Start your visualizations with basic pandas plotting. Use seaborn for the more complex statistical visualizations. Use matplotlib to customize the pandas or seaborn visualization. Runs through an example Describes figures and plots Includes a handy reference for customizing a plot. Related: StackOverflow answer that shows how to generate and embed a matplotlib image into a flask app without saving it to a file. Style it with pylustrator.readthedocs.io :)

Michael #5: Django Simple Task

django-simple-task runs background tasks in Django 3 without requiring other services and workers. It runs them in the same event loop as your ASGI application. Here’s a simple overview of how it works: On application start, a queue is created and a number of workers starts to listen to the queue When defer is called, a task(function or coroutine function) is added to the queue When a worker gets a task, it runs it or delegates it to a threadpool On application shutdown, it waits for tasks to finish before exiting ASGI server It is required to run Django with ASGI server. Example from django_simple_task import defer def task1(): time.sleep(1) print("task1 done") async def task2(): await asyncio.sleep(1) print("task2 done") def view(requests): defer(task1) defer(task2) return HttpResponse(b"My View")

Brian #6: PyPI Stats at pypistats.org

Simple interface. Pop in a package name and get the download stats. Example use: Why is my open source project now getting PRs and issues? I’ve got a few packages on PyPI, not updated much. cards and submark are mostly for demo purposes for teaching testing. pytest-check is a pytest plugin that allows multiple failures per test. I only hear about issues and PRs on one of these. So let’s look at traffic. cards: downloads day: 2 week: 24 month: 339 submark: day: 5 week: 9 month: 61 pytest-check: day: 976 week: 4,524 month: 19,636 That totally explains why I need to start actually supporting pytest-check. Cool. Note: it’s still small. Top 20 packages are all downloaded over 1.3 million times per day.


Comment from January Python PDX West meetup “Please remember to have one beginner friendly talk per meetup.” Good point. Even if you can’t present here in Portland / Hillsboro, or don’t want to, I’d love to hear feedback of good beginner friendly topics that are good for meetups.

PyCascades 2020

discount code listeners-at-pycascades for 10% off

FireFox 72 is out with anti-fingerprinting and PIP - Ars Technica


Language essays comic

#163 Meditations on the Zen of Python

Jan 9, 2020 00:23:49


Sponsored by us! Support us by visiting pythonbytes.fm/biz [courses] and pythonbytes.fm/pytest [book], or becoming a patron at patreon.com/pythonbytes

Brian #1: Meditations on the Zen of Python

Moshe Zadka The Zen of Python is not "the rules of Python" or "guidelines of Python". It is full of contradiction and allusion. It is not intended to be followed: it is intended to be meditated upon. Moshe give some of his thoughts on the different lines of the Zen of Python. Full Zen of Python can be found here or in a REPL with import this A few Beautiful is better than ugly Consistency helps. So black, flake8, pylint are useful. “But even more important, only humans can judge what humans find beautiful. Code reviews and a collaborative approach to writing code are the only realistic way to build beautiful code. Listening to other people is an important skill in software development.” Complex is better than complicated. “When solving a hard problem, it is often the case that no simple solution will do. In that case, the most Pythonic strategy is to go "bottom-up." Build simple tools and combine them to solve the problem.” Readability counts “In the face of immense pressure to throw readability to the side and just "solve the problem," the Zen of Python reminds us: readability counts. Writing the code so it can be read is a form of compassion for yourself and others.”

Michael #2: nginx raided by Russian police

Russian police have raided today the Moscow offices of NGINX, Inc., a subsidiary of F5 Networks and the company behind the internet's most popular web server technology. Russian search engine Rambler.ru claims full ownership of NGINX code. Rambler claims that Igor Sysoev developed NGINX while he was working as a system administrator for the company, hence they are the rightful owner of the project. Sysoev never denied creating NGINX while working at Rambler. In a 2012 interview, Sysoev claimed he developed NGINX in his free time and that Rambler wasn't even aware of it for years. Update Promptly following the event we took measures to ensure the security of our master software builds for NGINX, NGINX Plus, NGINX WAF and NGINX Unit—all of which are stored on servers outside of Russia. No other products are developed within Russia. F5 remains committed to innovating with NGINX, NGINX Plus, NGINX WAF and NGINX Unit, and we will continue to provide the best-in-class support you’ve come to expect.

Brian #3: I'm not feeling the async pressure

Armin Ronacher “Async is all the rage.” But before you go there, make sure you understand flow control and back pressure. “…back pressure is resistance that opposes the flow of data through a system. Back pressure sounds quite negative … but it's here to save your day.” If parts of your system are async, you have to make sure the entire flow throw the system doesn’t have overflow points. An example shown with reader/writer that is way hairier than you’d think it should be. “New Footguns: async/await is great but it encourages writing stuff that will behave catastrophically when overloaded.” “So for you developers of async libraries here is a new year's resolution for you: give back pressure and flow control the importance they deserve in documentation and API.”

Michael #4: codetiming from Real Python

via Doug Farrell A flexible, customizable timer for your Python code For a complete tutorial on how codetiming works, see Python Timer Functions: Three Ways to Monitor Your Code on Real Python. Time your code via A timer class A decorator A context manager

Brian #5: Making Python Programs Blazingly Fast

Martin Heinz Seemed like a good followup to the last topic Profiling with command line time python something.py python -m cProfile -s time something.py timing functions with wrapper Misses timeit, but see that also, https://docs.python.org/3.8/library/timeit.html How to make things faster: use built in types over custom types caching/memoization with lru_cache use local variables and local aliases when looping use functions… (kinda duh, but sure). don’t repeatedly access attributes in loops use f-strings over other formatting use generators. or at least experiment with them. the memory savings could result in speedup

Michael #6: LocalStack

via Graham Williamson and Jan 'oglop' Gazda A fully functional local AWS cloud stack. Develop and test your cloud & Serverless apps offline! LocalStack spins up the following core Cloud APIs on your local machine: S3, DynamoDB, Lambda, Elasticsearch see many more services paid one has more LocalStack builds on existing best-of-breed mocking/testing tools, most notably kinesalite/dynalite and moto. While these tools are awesome (!), they lack functionality for certain use cases. LocalStack combines the tools, makes them interoperable, and adds important missing functionality on top of them Has lots of config and knobs, but runs in docker so that helps


Python Job Board


Guido interviewed for JavaScript language! Microsoft: We're creating a new Rust-based programming language for secure coding New webcast: Python for the .NET developer Ace Python Interviews free course

Joke: Types of software jobs.

#162 Retrofitting async and await into Django

Jan 3, 2020 00:23:09


Sponsored by DataDog: pythonbytes.fm/datadog

Special guest: Aly

Aly #1: Andrew Godwin - Just Add Await: Retrofitting Async into Django — DjangoCon 2019

Andrew is leading the implementation of asynchronous support for Django Overview of Async Landscape How synchronous and asynchronous code interact Async functions are different than sync functions which makes it hard to design APIs Difficulties in adding Async support to Django Django is a project that a lot of people are familiar with; it’s new async implementation also needs to feel familiar Plan was Implement async capabilities in three phases Phase 1: ASGI Support (Django 3.0) This phase lays the groundwork for future changes ORM is async-aware: using it from async code raises a SynchronousOnlyOperation exception Phase 2: Async Views, Async Handlers, and Async Middleware (Django 3.1) Add async capabilities for the core part of the request path There is a branch where things are mostly working, just need to fix a couple of tests Phase 3: Async ORM (Django 3.2 / 4.0) Largest, most difficult and most unbounded part of the project ORM queries can result in lots of database lookups; have to be careful here Async Project Wiki - project status, find out how to contribute

Brian #2: gamesbyexample

Al Sweigart “PythonStdioGames : A collection of games (with source code) to use for example programming lessons. Written in Python 3. Click on the src folder to view all of the programs.” I first learned programming by modifying games written by others and seeing what the different parts do when I change them. For me it was Lunar Lander on a TRS-80, and it took forever to type in the listing from the back of a magazine. But now, you can just clone a repo and play with existing files. Cool features: They're short, with a limit of 256 lines of code. They fit into a single source code file and have no installer. They only use the Python standard library. They only use stdio text; print() and input() in Python. They're well commented. They use as few programming concepts as possible. If classes, list comprehensions, recursion, aren't necessary for the program, then they are't used. Elegant and efficient code is worthless next to code that is easy to understand and readable. These programs are for education, not production. Standard best practices, like not using global variables, can be ignored to make it easier to understand. They do input validation and are bug free. All functions have docstrings. There’s also a todo list if people want to help out.

Aly #3: Bulwark

Open-source library that allows users to property test pandas DataFrames Goal is to make it easy for data analysts and data scientists to write tests Tests around data are different; they are not deterministic, they requires us to think about testing in a different way With property tests, we can check an object has a certain property Property tests for DataFrames includes validating the shape of the DataFrame, checking that a column is within a certain range, verifying a DataFrame has no NaNs, etc Bulwark allows you to implement property tests as checks. Each check Takes a DataFrame and optional arguments The check will make an assertion about a DataFrame property If the assertion passes, the check will return the original, unaltered DataFrame If the check fails, an AssertionError is raised and you have context around why it failed Bulwark also allows you to implement property checks as decorators This is useful if you design data pipelines as functions Each function take in input data, performs an action, returns output Add decorators validate properties of input DataFrame to pipeline functions Lots of builtin checks and decorators; easy to add your own Slides with example usage and tips: Property Testing with Pandas with Bulwark

Brian #4: Poetry 1.0.0

Sebastien Eustace caution: not backwards compatible full change log Highlights: Poetry is getting serious. more ways to manage environments switch between python versions in a project with poetry env use /path/to/python or poetry env use python3.7 Imroved support for private indices (instead of just pypi) can specify index per dependency can specify a secondary index can specify a non-pypi index as default, avoiding pypi Env variable support to more easily work with poetry in a CI environment Improved add command to allow for constraints, paths, directories, etc for a dependency publishing allows api tokens marker specifiers on dependencies.

Aly #5: Kubernetes for Full-Stack Developers

With the rise of containers, Kubenetes has become the defacto platform for running and coordinating containerized applications across multiple machines With the rise of containers, Kubenetes is the defacto platform for running and coordinating applications across multiple machines This guide follows steps new users would take when learning how to deploy applications to Kubernetes: Learn Kubernetes core concepts Build modern 12 Factor web applications Get applications working inside of containers Deploy applications to Kubernetes Manage cluster operations New to containers? Check out my Introduction to Docker talk

Brian #6: testmon: selects tests affected by changed files and methods

On a previous episode (159) we mentioned pytest-picked and I incorrectly assumed it would run tests related to code that has changed, ‘cause it says “Run the tests related to the unstaged files or the current branch (according to Git)”. I was wrong, Michael was right. It runs the tests that are in modified test files. What I was thinking of is “testmon” which does what I was hoping for. “pytest-testmon is a pytest plugin which selects and executes only tests you need to run. It does this by collecting dependencies between tests and all executed code (internally using Coverage.py) and comparing the dependencies against changes. testmon updates its database on each test execution, so it works independently of version control.” If you had tried testmon before, like me, be aware that there have been significant changes in 1.0.0 Very cool to see continued effort on this project.



Finding local Python User Groups PyCon.org Events Calendar Meetup.com search for Python PyTennessee 2019 on March 7 - 8. Tickets on sale now! I will be giving a talk on the Facade Design Pattern


Next episode is planned to be a live recording during the Jan 7 Python PDX West meetup. There will also be 1-2 other talks.


From Tyler Matteson Two coroutines walk into a bar. RuntimeError: 'bar' was never awaited. From Ben Sandofsky Q: How many developers on a message board does it take to screw in a light bulb? A: “Why are you trying to do that?”

#161 Sloppy Python can mean fast answers!

Dec 18, 2019 00:30:15


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Special guest: Anthony Herbert

Anthony #1: Larry Hastings - Solve Your Problem With Sloppy Python - PyCon 2018

Michael’s personal automation things that I do all the time stripe to sheets automation urlify tons of reporting wakeup - to get 100 on Lighthouse deploy (on my servers) creating import data for video courses measuring duration of audio files

Michael #2: Introduction to ASGI: Emergence of an Async Python Web Ecosystem

by Florimond Manca Python growth is not just data science Python web development is back with an async spin, and it's exciting. One of the main drivers of this endeavour is ASGI , the Asynchronous Standard Gateway Interface. A guided tour about what ASGI is and what it means for modern Python web development. Since 3.5 was released, the community has been literally async-ifying all the things. If you're curious, a lot of the resulting projects are now listed in aio-libs and awesome-asyncio . An overview of ASGI Why should I care? Interoperability is a strong selling point, there are many more advantages to using ASGI-based components for building Python web apps. Speed: the async nature of ASGI apps and servers make them really fast (for Python, at least) — we're talking about 60k-70k req/s (consider that Flask and Django only achieve 10-20k in a similar situation). Features: ASGI servers and frameworks gives you access to inherently concurrent features (WebSocket, Server-Sent Events, HTTP/2) that are impossible to implement using sync/WSGI. Stability: ASGI as a spec has been around for about 3 years now, and version 3.0 is considered very stable. Foundational parts of the ecosystem are stabilizing as a result. To get your hands dirty, try out any of the following projects: uvicorn: ASGI server. Starlette: ASGI framework. TypeSystem: data validation and form rendering Databases: async database library. orm: asynchronous ORM. HTTPX: async HTTP client w/ support for calling ASGI apps (useful as a test client).

Anthony #3: Python Insights

Michael #4: Assembly

via Luiz Honda Assembly is a Pythonic Object-Oriented Web Framework built on Flask, that groups your routes by class Assembly is a pythonic object-oriented, mid stack, batteries included framework built on Flask, that adds structure to your Flask application, and group your routes by class. Assembly allows you to build web applications in much the same way you would build any other object-oriented Python program. Assembly helps you create small to enterprise level applications easily. Decisions made for you + features: github.com/mardix/assembly#decisions-made-for-you--features

Examples, root URLs:

# Extends to Assembly makes it a route automatically # By default, Index will be the root url class Index(Assembly): # index is the entry route # -> / def index(self): return "welcome to my site" # method name becomes the route # -> /hello/ def hello(self): return "I am a string" # undescore method name will be dasherize # -> /about-us/ def about_us(self): return "I am a string"

Example of /blog.

# The class name is part of the url prefix # This will become -> /blog class Blog(Assembly): # index will be the root # -> /blog/ def index(self): return [ { "title": "title 1", "content": "content" }, ... ] # with params. The order will be respected # -> /comments/1234/ # 1234 will be passed to the id def comments(self, id): return [ { comments... } ]

Anthony #5: Building a Standalone GPS Logger with CircuitPython using @Adafruit and particle hardware

Michael #6: 10 reasons python is good to learn

Python is popular and good to learn because, in Michael’s words, it’s a full spectrum language. And the reasons are: Python Is Free and Open-Source Python Is Popular, Loved, and Wanted Python Has a Friendly and Devoted Community Python Has Elegant and Concise Syntax Python Is Multi-Platform Python Supports Multiple Programming Paradigms Python Offers Useful Built-In Libraries Python Has Many Third-Party Packages Python Is a General-Purpose Programming Language Python Plays Nice with Others



I was just on .NET Rocks podcast talking about Python for the .NET Developer New Python for the .NET Developer 9-hour course New Python for Decision Makers course, 2.5 hours of exploring Python for your org. Hidden files in Finder: use shortcut cmd+shift+.


Pretty Printed YouTube channel

Joke: The failed pickup line

A girl is hanging out at a bar with her friends. Some guy comes up to her an says: “You are the ; to my line of code.” She responds, “Get outta here creep, I code in Python.”

#160 Your JSON shall be streamed

Dec 12, 2019 00:28:43


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Brian #1: Type Hints for Busy Python Programmers

Al Sweigart, @AlSweigart We’ve (Michael and myself, of course) convinced you that type hints might be a good thing to help reduce bugs or confusion or whatever. Now what? Al’s got your back with this no nonsense guide to get you going very quickly. Written as a conversation between a programmer and an type hint expert. Super short. Super helpful. typing and mypy are the modules you need. There are other tools, but let’s start there. Doesn’t affect run time, so you gotta run the tool. Gradually add, don’t have to do everything in one go. Covers the basics And then the “just after basics” stuff you’ll run into right away when you start, like: Allowing a type and None: Union[int, NoneType] Optional parameters Shout out to Callable, Sequence, Mapping, Iterable, available in the documentation when you are ready for them later Just really a great get started today guide.

Michael #2: auto-py-to-exe

A .py to .exe converter using a simple graphical interface built using Eel and PyInstaller in Python. Using the Application Select your script location (paste in or use a file explorer) Outline will become blue when file exists Select other options and add things like an icon or other files Click the big blue button at the bottom to convert Find your converted files in /output when complete Short 3 min video.

Brian #3: How to document Python code with Sphinx

Moshe Zadka, @moshezadka I’m intimidated by sphinx. Not sure why. But what I’ve really just wanted to do is to use it for this use of generating documentation of code based on the code and the docstrings. Many of the tutorials I’ve looked at before got me stuck somewhere along the way and I’ve given up. But this looks promising. Example module with docstring shown. Simple docs/index.rst, no previous knowledge of restructured text necessary. Specifically what extensions do I need: autodoc, napolean, and viewcode example docs/conf.py that’s really short setting up tox to generate the docs and the magic command like incantation necessary: sphinx-build -W -b html -d {envtmpdir}/doctrees . {envtmpdir}/html That’s it. (well, you may want to host the output somewhere, but I can figure that out. ) Super simple. Awesome

Michael #4: Snek is a cross-platform PowerShell module for integrating with Python

via Chad Miars Snek is a cross-platform PowerShell module for integrating with Python. It uses the Python for .NET library to load the Python runtime directly into PowerShell. Using the dynamic language runtime, it can then invoke Python scripts and modules and return the result directly to PowerShell as managed .NET objects. Kind of funky syntax, but that’s PowerShell for you ;) Even allows for external packages installed via pip

Brian #5:How to use Pandas to access databases

Irina Truong, @irinatruong You can use pandas and sqlalchemy to easily slurp tables right out of your db into memory. But don’t. pandas isn’t lazy and reads everything, even the stuff you don’t need. This article has tips on how to do it right. Recommendation to use the CLI for exploring, then shift to pandas and sqlalchemy. Tips (with examples, not shown here): limit the fields to just those you care about limit the number of records with limit or by selecting only rows where a particular field is a specific value, or something. Let the database do joins, even though you can do it in pandas Estimate memory usage with small queries and .memory_usage().sum(). Tips on reading chunks and converting small int types into small pandas types instead of 64 bit types.

Michael #6: ijson — Iterative JSON parser with a standard Python iterator interface

Iterative JSON parser with a standard Python iterator interface Most common usage is having ijson yield native Python objects out of a JSON stream located under a prefix. Here’s how to process all European cities: // from: { "earth": { "europe": [ ... ] } }

stream each entry in europe as item:

objects = ijson.items(f, 'earth.europe.item') cities = (o for o in objects if o['type'] == 'city') for city in cities: do_something_with(city)



Python decision makers webcast on January 14th, 9:30am US Pacific Guido steps down from Steering Council via Vincent POULAILLEAU GitHub Archive Program, Preserving open source software for future generations, video Python 2.7 will be removed from Homebrew, via Allan Hansen Django 3.0 released


Question: "What is the best prefix for global variables?" Answer: #

via shinjitsu

A web developer walks into a restaurant. He immediately leaves in disgust as the restaurant was laid out in tables.

via shinjitsu

#159 Brian's PR is merged, the src will flow

Dec 3, 2019 00:33:18


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Michael #1: Final type

PEP 591 -- Adding a final qualifier to typing This PEP proposes a "final" qualifier to be added to the typing module---in the form of a final decorator and a Final type annotation---to serve three related purposes: Declaring that a method should not be overridden Declaring that a class should not be subclassed Declaring that a variable or attribute should not be reassigned Some situations where a final class or method may be useful include: A class wasn’t designed to be subclassed or a method wasn't designed to be overridden. Perhaps it would not work as expected, or be error-prone. Subclassing or overriding would make code harder to understand or maintain. For example, you may want to prevent unnecessarily tight coupling between base classes and subclasses. You want to retain the freedom to arbitrarily change the class implementation in the future, and these changes might break subclasses. # Example for a class: from typing import final @final class Base: ... class Derived(Base): # Error: Cannot inherit from final class "Base" ...

And for a method:

class Base: @final def foo(self) -> None: ... class Derived(Base): def foo(self) -> None: # Error: Cannot override final attribute "foo" # (previously declared in base class "Base") ... It seems to also mean const RATE: Final = 3000 class Base: DEFAULT_ID: Final = 0 RATE = 300 # Error: can't assign to final attribute Base.DEFAULT_ID = 1 # Error: can't override a final attribute

Brian #2: flit 2

Michael #3: Pint

via Andrew Simon Physical units and builtin unit conversion to everyday python numbers like floats. Receive inputs in different unit systems it can make life difficult to account for that in software. Pint handles the unit conversion automatically in a wide array of contexts – Can add 2 meters and 5 inches and get the correct result without any additional work. The integration with numpy and pandas are seamless, and it’s made my life so much simpler overall. Units and types of measurements Think you need this? How about the Mars Climate Orbiter The MCO MIB has determined that the root cause for the loss of the MCO spacecraft was the failure to use metric units in the coding of a ground software file, “Small Forces,” used in trajectory models. Specifically, thruster performance data in English units instead of metric units was used in the software application code titled SM_FORCES (small forces).

Brian #4: 8 great pytest plugins

Jeff Triplett

Michael #5: 11 new web frameworks

via LuisCarlos Contreras Sanic [flask like] - a web server and web framework that’s written to go fast. It allows the usage of the async / await syntax added in Python 3.5 Starlette [flask like] - A lightweight ASGI framework which is ideal for building high performance asyncio services, designed to be used either as a complete framework, or as an ASGI toolkit. Masonite - A developer centric Python web framework that strives for an actual batteries included developer tool with a lot of out of the box functionality. Craft CLI is the edge here. FastAPI - A modern, high-performance, web framework for building APIs with Python 3.6+ based on standard Python type hints. Responder - Based on Starlette, Responder’s primary concept is to bring the niceties that are brought forth from both Flask and Falcon and unify them into a single framework. Molten - A minimal, extensible, fast and productive framework for building HTTP APIs with Python. Molten can automatically validate requests according to predefined schemas. Japronto - A screaming-fast, scalable, asynchronous Python 3.5+ HTTP toolkit integrated with pipelining HTTP server based on uvloop and picohttpparser. Klein [flask like] - A micro-framework for developing production-ready web services with Python. It is ‘micro’ in that it has an incredibly small API similar to Bottle and Flask. Quart [flask like]- A Python ASGI web microframework. It is intended to provide the easiest way to use asyncio functionality in a web context, especially with existing Flask apps. BlackSheep - An asynchronous web framework to build event based, non-blocking Python web applications. It is inspired by Flask and ASP.NET Core. BlackSheep supports automatic binding of values for request handlers, by type annotation or by conventions. Cyclone - A web server framework that implements the Tornado API as a Twisted protocol. The idea is to bridge Tornado’s elegant and straightforward API to Twisted’s Event-Loop, enabling a vast number of supported protocols.

Brian #6: Raise Better Exceptions in Python



Naming venvs --prompt Another new course coming soon: Python for decision makers and business leaders Some random interview over at Real Python: Python Community Interview With Brian Okken


via Daniel Pope What's a tractor's least favorite programming language? Rust.

#158 There's a bounty on your open-source bugs!

Nov 27, 2019 00:26:05


This episode is sponsored by DigitalOcean - pythonbytes.fm/digitalocean

Brian #1: Python already replaced Excel in banking

“If you wanted to prove your mettle as an entry-level banker or trader it used to be the case that you had to know all about financial modeling in Excel. Not any more. These days it's all about Python, especially on the trading floor. "Python already replaced Excel," said Matthew Hampson, deputy chief digital officer at Nomura, speaking at last Friday's Quant Conference in London. "You can already walk across the trading floor and see people writing Python code...it will become much more common in the next three to four years."

Michael #2: GitHub launches 'Security Lab' to help secure open source ecosystem

At the GitHub Universe developer conference, GitHub announced the launch of a new community program called Security Lab GitHub says Security Lab founding members have found, reported, and helped fix more than 100 security flaws already. Other organizations, as well as individual security researchers, can also join. A bug bounty program with rewards of up to $3,000 is also available, to compensate bug hunters for the time they put into searching for vulnerabilities in open source projects. Bug reports must contain a CodeQL query. CodeQL is a new open source tool that GitHub released today; a semantic code analysis engine that was designed to find different versions of the same vulnerability across vasts swaths of code. Starting today automated security updates are generally available and have been rolled out to every active repository with security alerts enabled. Once a security flaw is fixed, the project owner can publish the security, and GitHub will warn all upstream project owners who are using vulnerable versions of the original maintainer's code. But before publishing a security advisory, project owners can also request and receive a CVE number for their project's vulnerability directly from GitHub. And last, but not least, GitHub also updated Token Scanning, its in-house service that can scan users' projects for API keys and tokens that have been accidentally left inside their source code.

Brian #3: pybit.es now has some test challenges

Uses pytest, coverage.py, and mutpy (for mutation testing) Most other challenges have tests that validate the code you write. New challenges (3 so far) have you write the tests for existing code. Tests are evaluated with both coverage.py and mutpy another mutation testing tool is mutmut, written about earlier this year by Ned Badtchelder.

Michael #4: pyhttptest - a command-line tool for HTTP tests over RESTful APIs

via Florian Dahlitz A command-line tool for HTTP tests over RESTful APIs Tired of writing test scripts against your RESTFul APIs anytime? Describe an HTTP Requests test cases in a simplest and widely used format JSON within a file. Run one command and gain a summary report. Example { "name": "TEST: List all users", "verb": "GET", "endpoint": "users", "host": "https://github.com", "headers": { "Accept-Language": "en-US" }, "query_string": { "limit": 5 } }

Brian #5: xarray

suggested by Guido Imperiale xarray is a mature library that builds on top of numpy, pandas and dask to offer arrays that are n-dimensional (numpy and dask do it, but pandas doesn't) self-described and indexed (pandas does it, but numpy and dask don't) out-of-memory, multi-threaded, and cloud-distributed (dask does it, but numpy and pandas don't). Additionally, xarray can semi-transparently swap numpy with other backends, such as sparse , while retaining the same API.

Michael #6: Animated SVG Terminals

Florian Dahlitz termtosvg is a Unix terminal recorder written in Python that renders your command line sessions as standalone SVG animations. Features: Produce lightweight and clean looking animations or still frames embeddable on a project page Custom color themes, terminal UI and animation controls via user-defined SVG templates Rendering of recordings in asciicast format made with asciinema Examples: nbedos.github.io/termtosvg/pages/examples.html


pytest 5.3.0 released, please read changelog if you use pytest, especially if you use it with CI and depend on --junitxml, as they have changed the format to a newer version.


PyCon registration is open (via Jacqueline Wilson) Facebook: Microsoft's Visual Studio Code is now our default development platform Black friday at Talk Python Training! New course coming soon: Python for the .NET developer


What do you get when you put root beer in a square glass? Beer.

Q: What do you call optimistic front-end developers?

A: Stack half-full developers.

Also, I was going to tell a version control joke, but they are only funny if you git them.

#157 Oh hai Pandas, hold my hand?

Nov 20, 2019 00:23:32


This episode is sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Michael #1: pydantic

via Colin Sullivan Data validation and settings management using python type annotations. (We covered Cerberus, this is similar) pydantic enforces type hints at runtime, and provides user friendly errors when data is invalid. class User(pydantic.BaseModel): id: int name = 'John Doe' signup_ts: datetime = None friends: List[int] = [] external_data = { 'id': '123', 'signup_ts': '2019-06-01 12:22', 'friends': [1, 2, '3'] } user = User(**external_data) id is of type int; the annotation-only declaration tells pydantic that this field is required. Strings, bytes or floats will be coerced to ints if possible; otherwise an exception will be raised. name is inferred as a string from the provided default; because it has a default, it is not required. signup_ts is a datetime field which is not required (and takes the value None if it's not supplied). Why use it? There's no new schema definition micro-language to learn. In benchmarks pydantic is faster than all other tested libraries. Use of recursive pydantic models, typing's standard types (e.g. List, Tuple, Dict etc.) and validators allow complex data schemas to be clearly and easily defined, validated, and parsed. As well as BaseModel, pydantic provides a [dataclass](https://pydantic-docs.helpmanual.io/usage/dataclasses/) decorator which creates (almost) vanilla python dataclasses with input data parsing and validation.

Brian #2: Coverage.py 5.0 beta 1 adds context support

Please try out the beta, even without trying contexts, as it helps Ned Batchelder to make sure it’s as backwards compatible as possible while still adding this super cool functionality. Coverage 5.0 beta 1 announcement The changes. Measurement contexts in depth. Trying out contexts with pytest and pytest-cov: (venv) $ pip install coverage==5.0b1 (venv) $ pip install pytest-cov (venv) $ pytest --cov=foo --cov-context=test test_foo.py (venv) $ coverage html --show-contexts (venv) $ open htmlcov/index.html results in coverage report that has little dropdowns on the right for lines that are covered, and what context they were covered. For the example above, with pytest-cov, it shows what test caused each line to be hit. Contexts can do way more than this. One example, split up different levels of tests, to see which lines are only hit by unit tests, indicating missing higher level tests, or the opposite. The stored db could also possibly be mined to see how much overlap there is between tests, and maybe help with higher level tools to predict the harm or benefit from removing some tests. I’m excited about the future, with contexts in place. Even if you ignore contexts, please go try out the beta ASAP to make sure your old use model still works.

Michael #3: PSF is seeking developers for paid contract improving pip

via Brian Rutledge The Python Software Foundation Packaging Working Group is receiving funding to work on the design, implementation, and rollout of pip's next-generation dependency resolver. This project aims to complete the design, implementation, and rollout of pip's next-generation dependency resolver. Lower the barriers to installing Python software, empowering users to get a version of a package that works. It will also lower the barriers to distributing Python software, empowering developers to make their work available in an easily reusable form. Because of the size of the project, funding has been allocated to secure two contractors, a senior developer and an intermediate developer, to work on development, testing and building test infrastructure, code review, bug triage, and assisting in the rollout of necessary features. Total pay: Stage 1: $116,375, Stage 2: $103,700

Brian #4: dovpanda - Directions OVer PANDAs

Dean Langsam “Directions are hints and tips for using pandas in an analysis environment. dovpanda is an overlay for working with pandas in an analysis environment. "If you think your task is common enough, it probably is, and Pandas probably has a built-in solution. dovpanda is an overlay module that tries to understand what you are trying to do with your data, and help you find easier ways to write your code.” “The main usage of dovpanda is its hints mechanism, which is very easy and works out-of-the-box. Just import it after you import pandas, whether inside a notebook or in a console.” It’s like training wheels for pandas to help you get the most out of pandas and learn while you are doing your work. Very cool.

Michael #5: removestar

via PyCoders newsletter Tool to automatically replace 'import *' in Python files with explicit imports Report only mode and modify in place mode.

Brian #6: pytest-quarantine : Save the list of failing tests, so that they can be automatically marked as expected failures on future test runs.

Brian Rutlage Really nice email from Brian: >"Hi Brian! We've met a couple times at PyCon in Cleveland. Thanks for your podcasts, and your book. I've gone from being a complete pytest newbie, to helping my company adopt it, to writing a plugin. The plugin was something I developed at work, and they let me open-source it. I wanted to share it with you as a way of saying "thank you", and because you seem to be a bit of connoisseur of pytest plugins. ;)" Here it is: https://github.com/EnergySage/pytest-quarantine/” pytest has a cool feature called xfail, to allow you to mark tests you know fail. pytest-quarantine allows you to run your suite and generate a file of all failures, then use that to mark the xfails. Then you or your team can chip away at these failures until you get rid of them. But in the meantime, your suite can still be useful for finding new failures. And, the use of an external file to mark failures makes it so you don’t have to edit your test files to mark the tests that are xfail.


MK: Our infrastructure is fully carbon neutral!


A cop pulls Dr. Heisenberg over for speeding. The officer asks, "Do you know how fast you were going?" Heisenberg pauses for a moment, then answers, "No, but I know where I am.” [1]

See Uncertainty principle, also called Heisenberg uncertainty principle or indeterminacy principle, statement, articulated (1927) by the German physicist Werner Heisenberg, that the position and the velocity of an object cannot both be measured exactly, at the same time, even in theory.

#156 All the programming LOLs

Nov 15, 2019 00:28:27


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Special guests:

Dan Bader Cecil Philip

Dan #1: Why You Should Use python -m pip


Cecil #2: Visual Studio Online: Web-Based IDE & Collaborative Code Editor


Michael #3: Python Adopts a 12-month Release Cycle

The long discussion on changing the Python project's release cadence has come to a conclusion: the project will now be releasing new versions on an annual basis. Described in PEP 602 The steering council thinks that having a consistent schedule every year when we hit beta, RC, and final it will help the community: Know when to start testing the beta to provide feedback Known when the expect the RC so the community can prepare their projects for the final release Know when the final release will occur to coordinate their own releases (if necessary) when the final release of Python occurs Allow core developers to more easily plan their work to make sure work lands in the release they are targeting Make sure that core developers and the community have a shorter amount of time to wait for new features to be released

Dan #4: Black 19.10b0 Released — stable release coming soon

https://twitter.com/llanga/status/1188968251918819329 “Black Friday” release date? https://twitter.com/llanga/status/1189145837991014402 Playground: https://black.now.sh/

Cecil 5: Navigating code on GitHub

Example: https://github.com/talkpython/100daysofcode-with-python-course/blob/master/days/10-12-pytest/guess/guess.py

Michael #6: lolcommits: selfies for software developers.

lolcommits takes a snapshot with your webcam every time you git commit code, and archives a lolcat style image with it. git blame has never been so much fun. Infinite uses: Animate your progress through a project and watch as you age. See what you looked like when you broke the build. Keep a joint lolrepository for your entire company. Plugins: Lolcommits allows a growing list of plugins to perform additional work on your lolcommit image after capturing. Animate: Configure lolcommits to generate an animated GIF with each commit for extra lulz!



Article & Course on Python 3.8 https://realpython.com/python38-new-features/ https://realpython.com/courses/cool-new-features-python-38/


Twitch learning Python channel


New Anvil course, free one - https://talkpython.fm/anvil PSF yearly survey is out: https://twitter.com/thepsf/status/1190004772704784385



#155 Guido van Rossum retires

Nov 6, 2019 00:32:06


Sponsored by Datadog: pythonbytes.fm/datadog

Michael #1: Guido retires

Guido van Rossum has left DropBox and retired (post) Let’s all take a moment to say thank you. I wonder what will come next in terms of creative projects Some comments from community members (see Twitter thread)

Brian #2: SeleniumBase

Automated UI Testing with Selenium WebDriver and pytest. Very expressive and intuitive automation library built on top of Selenium WebDriver. method overview very readable (this is a workflow test, but still, quite readable): from seleniumbase import BaseCase class MyTestClass(BaseCase): def test_basic(self): self.open("https://xkcd.com/353/") self.assert_title("xkcd: Python") self.assert_element('img[alt="Python"]') self.click('a[rel="license"]') self.assert_text("free to copy and reuse") self.go_back() self.click("link=About") self.assert_text("xkcd.com", "h2") self.open("https://store.xkcd.com/collections/everything") self.update_text("input.search-input", "xkcd book\n") self.assert_exact_text("xkcd: volume 0", "h3") includes plugins for including screenshots in test results. supports major CI systems some cool features that I didn’t expect user onboarding demos assisted QA (partially automated with manual questions) support for selenium grid logs of command line options, including headless

Michael #3: Reimplementing a Solaris command in Python gained 17x performance improvement from C

Postmortem by Darren Moffat Is Python slow? A result of fixing a memory allocation issue in the /usr/bin/listusers command Decided to investigate if this ancient C code could be improved by conversion to Python. The C code was largely untouched since 1988 and was around 800 lines long, it was written in an era when the number of users was fairly small and probably existed in the local files /etc/passwd or a smallish NIS server. It turns out that the algorithm to implement the listusers is basically some simple set manipulation. Rewrite of listusers in Python 3 turned out to be roughly a 10th of the number of lines of code But Python would be slower right ? Turns out it isn't and in fact for some of my datasets (that had over 100,000 users in them) it was 17 times faster. A few of the comments asked about the availability of the Python version. The listusers command in Oracle Solaris 11.4 SRU 9 and higher. Since we ship the /usr/bin/listusers file as the Python code you can see it by just viewing the file in an editor. Note though that is not open source and is covered by the Oracle Solaris licenses.

Brian #4: 20 useful Python tips and tricks you should know

I admit it, I’m capable of getting link-baited by the occasional listicle. Some great stuff, especially for people coming from other languages. Chained assignment: x = y = z = 2 Chained comparison: 2 < x <= 8 2 < x > 4 0 < x < 4 < y < 16 Multiple assignment: x, y, z = 2, 4, 8 More Advanced Multiple Assignment: x, *y, z = 2, 4, 8, 16 I’ve been using the * for unpacking a lot, especially with *_ Merge dictionaries: z = {**x, **y} Join strings: '_'.join(['u', 'v', 'w']) using list(set(something)) to remove duplicates. aggregate elements. using zip to element-wise combine two or more iterables. >>> x = [1, 2, 3] >>> y = ['a', 'b', 'c'] >>> zip(x, y) [(1, 'a'), (2, 'b'), (3, 'c')] and then some other weird stuff that I don’t find that useful.

Michael #5: Complexity Waterfall

via Ahrem Ahreff Heavy use of wemake-python-styleguide Code smells! Use your refactoring tools and write tests. Automation enable an opportunity of “Continuous Refactoring” and “Architecture on Demand” development styles.

Brian #6: Plynth

Plynth is a GUI framework for building cross-platform desktop applications with HTML, CSS and Python. Plynth has integrated the standard CPython implementation with Chromium's rendering engine. You can run your python scripts seamlessly with HTML/CSS instead of using Javascript with modules from pip Plynth uses Chromium/Electron for its rendering. With Plynth, every Javascript library turns into a Python module. Not open source. But free for individuals, including commercial use and education. A bunch of tutorial videos that are not difficult to follow, and not long, but… not really obvious code either. Python 3.6 and 3.7 development kits available



Google Is Uncovering Hundreds Of Race Conditions Within The Linux Kernel


Q: What's a web developer's favorite tea? A: URL gray via Aideen Barry

#154 Code, frozen in carbon, on display for all

Oct 29, 2019 0:32:19


Sponsored by Datadog: pythonbytes.fm/datadog

Special guest: Bob Belderbos

Brian #1: Lesser Known Coding Fonts

Interesting examination of some coding fonts. Link to a great talk called Cracking the Code, by Jonathan David Ross, about coding fonts and Input.

I’m trying out Input Mono right now, and quite like it.

Fira code: https://github.com/tonsky/FiraCode

Bob #2: Django Admin Handbook

As a Django developer knowing the admin is pretty important. Free ebook of 40 or so pages, you can consume it in one evening. There are a lot of good tricks, 3 I liked: How to optimize queries in Django admin (override get_queryset) How to export CSV from Django admin (useful for data analysis in Jupyter for example) How to override save behaviour for Django admin (used this to notify users upon publishing a new exercise on our platform) Some more cool ebooks on that site, e.g. Tweetable #Python.

Michael #3: Your Guide to the CPython Source Code

Let’s talk about exploring the CPython code You’ll want to get the code: git clone https://github.com/python/cpython Compile the code (Anthony gives lots of steps for macOS, Windows, and Linux) Structure: cpython/ │ ├── Doc ← Source for the documentation ├── Grammar ← The computer-readable language definition ├── Include ← The C header files ├── Lib ← Standard library modules written in Python ├── Mac ← macOS support files ├── Misc ← Miscellaneous files ├── Modules ← Standard Library Modules written in C ├── Objects ← Core types and the object model ├── Parser ← The Python parser source code ├── PC ← Windows build support files ├── PCbuild ← Windows build support files for older Windows versions ├── Programs ← Source code for the python executable and other binaries ├── Python ← The CPython interpreter source code └── Tools ← Standalone tools useful for building or extending Python Some cool “hidden” goodies. For example, check out Lib/concurrent/futures/process.py, it comes with a cool ascii diagram of the process. Lots more covered, that we don’t have time for The Python Interpreter Process The CPython Compiler and Execution Loop Objects in CPython The CPython Standard Library Installing a custom version

Brian #4: Six Django template tags not often used in tutorials

Here’s a few: {% empty %}, for use in for loops when the array is empty {% lorem \[count\] [method] [random] %} for automatically filling with Lorem Ipsum text. {% verbatim %} … {% endverbatim %}, stop the rendering engine from trying to parse it and replace stuff. https://hipsum.co/

Bob #5: Beautiful code snippets with Carbon

Beautiful images, great for teaching Python / programming. Used by a lot of developer, nice example I spotted today. Supports typing and drag and drop, just generated this link by dropping a test module onto the canvas! Great to expand Twitter char limit (we use it to generate Python Tip images). Follow the project here, seems they now integrate with Github.

Michael #6: Researchers find bug in Python script may have affected hundreds of studies

More info via Mike Driscoll at Thousands of Scientific Papers May be Invalid Due to Misunderstanding Python In a paper published October 8, researchers at the University of Hawaii found that a programming error in a set of Python scripts commonly used for computational analysis of chemistry data returned varying results based on which operating system they were run on. Scientists did not understand that Python’s glob.glob() does not return sorted results Throwing doubt on the results of more than 150 published chemistry studies. the researcher were trying to analyze results from an experiment involving cyanobacteria discovered significant variations in results run against the same nuclear magnetic resonance spectroscopy (NMR) data. The scripts, called the "Willoughby-Hoye" scripts after their creators, were found to return correct results on macOS Mavericks and Windows 10. But on macOS Mojave and Ubuntu, the results were off by nearly a full percent. The module depends on the operating system for the order in which the files are returned. And the results of the scripts' calculations are affected by the order in which the files are processed. The fix: A simple list.sort()! Williams said he hopes the paper will get scientists to pay more attention to the computational side of experiments in the future.


Nov 5 is the next Python PDX West Using Big Tech Tools

Working on: PyBites platform: added flake8/ black code formatting, UI enhancements.


Bezos DDoS'd: Amazon Web Services' DNS systems knackered by hours-long cyber-attack PyPI Just Crossed the 200,000 Packages Threshold! (via RP) XKCD Date — via André Jaenisch, Enter https://explainxkcd.com/wiki/index.php/1425:_Tasks and learn, that it was published on 24th Sep 2014.


Q: What did the Network Administrator say when they caught a nasty virus? A: It hurts when IP

#153 Auto format my Python please!

Oct 23, 2019 0:26:57


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Michael #1: Building a Python C Extension Module

Tutorial, learn to use the Python API to write Python C extension modules. And Invoke C functions from within Python Pass arguments from Python to C and parse them accordingly Raise exceptions from C code and create custom Python exceptions in C Define global constants in C and make them accessible in Python Test, package, and distribute your Python C extension module Extending Your Python Program there may be other lesser-used system calls that are only accessible through C Steps: Writing a Python Interface in C Figure out the arguments (e.g. int fputs(const char *, FILE *) ) Implement in C: #include Python.h static PyObject *method_fputs(PyObject *self, PyObject *args) { char *str, *filename = NULL; int bytes_copied = -1; /* Parse arguments */ if(!PyArg_ParseTuple(args, "ss", &str, &filename)) { return NULL; } FILE *fp = fopen(filename, "w"); bytes_copied = fputs(str, fp); fclose(fp); return PyLong_FromLong(bytes_copied); } In line 2, you declare the argument types you wish to receive from your Python code line 6, then you’ll see that PyArg_ParseTuple() copies into the char*’s Write regular C code (fopen, fputs) Return: PyLong_FromLong() creates a PyLongObject, which represents an integer object in Python. a few extra functions that are necessary write definitions of your module and the methods it contains Before you can import your new module, you first need to build it. You can do this by using the Python package distutils.

Brian #2: What’s New in Python 3.8 - docs.python.org

We’ve already talked about the big hitters:

assignment expressions, (the walrus operator) positional only parameters, (the / in the param list) f-strings support = for self-documenting expressions and debugging

There are a few more goodies I wanted to quickly mention:

More async: python -m asyncio launches a native async REPL More helpful warnings and messages when using is and is not to compare strings and integers and other types intended to be compared with == and != Missing the comma in stuff like [(1,2) (3,4)]. Happens all the time with parametrized testing you can do iterable unpacking in a yield or return statement x = (1, 2, 3) a, *b = x return a, *b <- this used to be a syntax error you had to do return (a, *b) New module importlib.metadata lets you access things like version numbers or dependent library required version numbers, and cool stuff like that. quite a few more goodies. I run through all my favorites on testandcode.com/91

Michael #3: UK National Cyber Security Centre (NCSC) is warning developers of the risks of sticking with Python 2.7, particularly for library writers

NCSC likens companies continuing to use Python 2 past its EOL to tempting another WannaCry or Equifax incident. Equifax details: a vulnerability, dubbed CVE-2017-5638, was discovered in Apache Struts, an open source development framework for creating enterprise Java applications that Equifax, along with thousands of other websites, uses… Quote: "If you're still using 2.x, it's time to port your code to Python 3," the NCSC said. "If you continue to use unsupported modules, you are risking the security of your organisation and data, as vulnerabilities will sooner or later appear which nobody is fixing." Moreover: "If you maintain a library that other developers depend on, you may be preventing them from updating to 3," the agency added. "By holding other developers back, you are indirectly and likely unintentionally increasing the security risks of others.” "If migrating your code base to Python 3 is not possible, another option is to pay a commercial company to support Python 2 for you," the NCSC said. NCSC: If you don't migrate, you should expect security incidents Python's popularity makes updating code imperative: The reason the NCSC is warning companies about Python 2's impending EOL is because of the language's success.

Brian #4: Pythonic News

Sebastian A. Steins “A Hacker News lookalike written in Python/Django” “ powering https://news.python.sc" Cool that it’s open source, and on github Was submitted to us by Sebastian, and a few others too, so there is excitement. It’s like 6 days old and has 153 stars on github, 4 contributors, 18 forks. Fun.

Michael #5: Deep Learning Workstations, Servers, Laptops, and GPU Cloud

GPU-accelerated with TensorFlow, PyTorch, Keras, and more pre-installed. Just plug in and start training. Save up to 90% by moving off your current cloud and choosing Lambda. They offer: TensorBook: GPU Laptop for $2,934 Lambda Quad: 4x GPU Workstation for $21,108 (yikes!) All in: Lambda Hyperplane: 8x Tesla V100 Server, starting at $114,274 But compare to: AWS EC2: p3.8xlarge @ $12.24 per Hour => $8,935 / month

Brian #6: Auto formatters for Python

A comparison of autopep8, yapf, and black Auto formatters are super helpful for teams. They shut down the unproductive arguments over style and make code reviews way more pleasant. People can focus on content, not being the style police. We love black. But it might be a bit over the top for some people. Here are a couple of other alternatives. autopep8 - mostly focuses on PEP8 “autopep8 automatically formats Python code to conform to the PEP 8 style guide. It uses the pycodestyle utility to determine what parts of the code needs to be formatted. autopep8 is capable of fixing most of the formatting issues that can be reported by pycodestyle.” black - does more doesn’t have many options, but you can alter line length, can turn of string quote normalization, and you can limit or focus the files it sees. does a cool “check that the reformatted code still produces a valid AST that is equivalent to the original.” but you can turn that off with --fast yapf - way more customizable. Great if you want to auto format to a custom style guide. “The ultimate goal is that the code YAPF produces is as good as the code that a programmer would write if they were following the style guide. It takes away some of the drudgery of maintaining your code.” Article is cool in that it shows some sample code and how it’s changed by the different formatters.



New courses coming Financial Aid Launches for PyCon US 2020!


American Py Song

From Eric Nelson:

Math joke. “i is as complex as it gets. jk.”

#152 You have 35 million lines of Python 2, now what?

Oct 15, 2019 0:26:01


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Michael #1: JPMorgan’s Athena Has 35 Million Lines of Python 2 Code, and Won’t Be Updated to Python 3 in Time

With 35 million lines of Python code, the Athena trading platform is at the core of JPMorgan's business operations. A late start to migrating to Python 3 could create a security risk. Athena platform is used internally at JPMorgan for pricing, trading, risk management, and analytics, with tools for data science and machine learning. This extensive feature set utilizes over 150,000 Python modules, over 500 open source packages, and 35 million lines of Python code contributed by over 1,500 developers, according to data presented by Misha Tselman, executive director at J.P. Morgan Chase in a talk at PyData 2017. And JPMorgan is going to miss the deadline Roadmap puts "most strategic components" compatible with Python 3 by the end of Q1 2020 JPMorgan uses Continuous Delivery, with 10,000 to 15,000 production changes per week "If you maintain a library that other developers depend on," the post states, "you may be preventing them from updating to 3. By holding other developers back, you are indirectly and likely unintentionally increasing the security risks of others," adding that developers who do not publish code publicly should "consider your colleagues who may also be using your code internally."

Brian #2: organize

suggested by Ariel Barkan a Python based file management automation tool configuration is via a yml file command line tool to organize your file system examples: move all of your screenshots off of your desktop into a screenshots folder move old incomplete downloads into trash remove empty files from certain folders organize receipts and invoices into date based folders

Michael #3: PEP 589 – TypedDict: Type Hints for Dictionaries With a Fixed Set of Keys

Author: Jukka Lehtosalo Sponsor: Guido van Rossum Status: Accepted Version: 3.8 PEP 484 defines the type Dict[K, V] for uniform dictionaries, where each value has the same type, and arbitrary key values are supported. It doesn't properly support the common pattern where the type of a dictionary value depends on the string value of the key. Core idea: Consider creating a type to validate an arbitrary JSON document with a fixed schema Proposed syntax: from typing import TypedDict class Movie(TypedDict): name: str year: int movie: Movie = {'name': 'Blade Runner', 'year': 1982} Operations on movie can be checked by a static type checker movie['director'] = 'Ridley Scott' # Error: invalid key 'director' movie['year'] = '1982' # Error: invalid value type ("int" expected)

Brian #4: gazpacho

gazpacho is a web scraping library “It replaces requests and BeautifulSoup for most projects. “ “gazpacho is small, simple, fast, and consistent.” example of using gazpacho to scrape hockey data for fantasy sports. simple interface, short scripts, really beginner friendly retrieve with get, parse with Soup. I don’t think it will completely replace the other tools, but for simple get/parse/find operations, it may make for slimmer code. Note, I needed to update certificates to get this to work. see this.

Michael #5: How pip install Works

via PyDist What happens when you run pip install [somepackage]? First pip needs to decide which distribution of the package to install. This is more complex for Python than many other languages There are 7 different kinds of distributions, but the most common these days are source distributions and binary wheels. A binary wheel is a more complex archive format, which can contain compiled C extension code. Compiling, say, numpy from source takes a long time (~4 minutes on my desktop), and it is hard for package authors to ensure that their source code will compile on other people's machines. Most packages with C extensions will build multiple wheel distributions, and pip needs to decide which if any are suitable for your computer. To find the distributions available, pip requests https://pypi.org/simple/[somepackage], which is a simple HTML page full of links, where the text of the link is the filename of the distribution. To select a distribution, pip first determines which distributions are compatible with your system and implementation of python. binary wheels, it parses the filenames according to PEP 425, extracting the python implementation, application binary interface, and platform. All source distributions are assumed to be compatible, at least at this step in the process Once pip has a list of compatible distributions, it sorts them by version, chooses the most recent version, and then chooses the "best" distribution for that version It prefers binary wheels if there are any Determining the dependencies for this distribution is not simple either. For binary wheels, the dependencies are listed in a file called METADATA. But for source distributions the dependencies are effectively whatever gets installed when you execute their setup.py script with the install command. What happens though if one of the distributions pip finds violates the requirements of another? It ignores the requirement and installs idna anyway! Next pip has to actually build and install the package. it needs to determine which library directory to install the package in—the system's, the user's, or a virtualenvs? Controlled by sys.prefix, which in turn is controlled by pip's executable path and the PYTHONPATH and PYTHONHOME environment variables. Finally, it moves the wheel files into the appropriate library directory, and compiles the python source files into bytecode for faster execution. Now your package is installed!

Brian #6: daily pandas tricks

Kevin Markham is sending out one pandas tip or trick per day via twitter. It’s been fun to watch and learn new bits. The link is a sampling of a bunch of them. Here’s just one example: Need to rename all of your columns in the same way? Use a string method: Replace spaces with _: df.columns = df.columns.str.replace(' ', '_') Make lowercase & remove trailing whitespace: df.columns = df.columns.str.lower().str.rstrip()



Switched to Adobe Audition Azure Databricks drops Python 2 Better Jupyter in VS Code macOS Catalina (so far so good)


via Sarcastic Pharmacist Hard to distinguish hard from easy in programming

#151 Certified! It works on my machine

Oct 10, 2019 0:25:47


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Brian #1: Python alternative to Docker

Matt Layman Using Shiv, from LinkedIn Mentioned briefly in episode 114 Shiv uses zipapp, PEP 441. Execute code directly from a zip file. App code and dependencies can be bundled together. “Having one artifact eliminates the possibility of a bad interaction getting to your production system.” article includes an example of all the steps for packaging a Django app with Gunicorn. includes talking about deployment. Matt includes shoutouts to: Platform as a Service providers Manual steps to do it all. Docker Compares the process against Docker and discusses when to choose one over the other. Also an interesting read: Docker is in deep trouble

Michael #2: How to support open-source software and stay sane

via Jason Thomas written by Anna Nowogrodzki Releasing lab-built open-source software often involves a mountain of unforeseen work for the developers. Article opens: “On 10 April, astrophysicists announced that they had captured the first ever image of a black hole. This was exhilarating news, but none of the giddy headlines mentioned that the image would have been impossible without open-source software.” The image was created using Matplotlib, a Python library for graphing data, as well as other components of the open-source Python ecosystem. Just five days later, the US National Science Foundation (NSF) rejected a grant proposal to support that ecosystem, saying that the software lacked sufficient impact. Open-source software is widely acknowledged as crucially important in science, yet it is funded non-sustainably. “It’s sort of the difference between having insurance and having a GoFundMe when their grandma goes to the hospital,” says Anne Carpenter Challenges Scientists writing open-source software often lack formal training in software engineering. Yet poorly maintained software can waste time and effort, and hinder reproducibility. If your research group is planning to release open-source software, you can prepare for the support work Obsolescence isn’t bad, she adds: knowing when to stop supporting software is an important skill. However long your software will be used for, good software-engineering practices and documentation are essential. These include continuous integration systems (such as TravisCI), version control (Git) and unit testing. To facilitate maintenance, Varoquaux recommends focusing on code readability over peak performance.

Brian #3: The Hippocratic License

Coraline Ada Ehmke Interesting idea to derive from MIT, but add restrictions. This license adds these restrictions: “The software may not be used by individuals, corporations, governments, or other groups for systems or activities that actively and knowingly endanger, harm, or otherwise threaten the physical, mental, economic, or general well-being of individuals or groups in violation of the United Nations Universal Declaration of Human Rights” I could see others with different restrictions, or this but more.

Michael #4: MATLAB vs Python: Why and How to Make the Switch

MATLAB® is widely known as a high-quality environment for any work that involves arrays, matrices, or linear algebra. I personally used it for wavelet-decomposition of real time eye measurements during cognitively intensive human workloads… That toolbox costs $2000 per user. Difference in philosophy: Closed, paid vs. open source. Since Python is available at no cost, a much broader audience can use the code you develop Also, there is GNU Octave is a free and open-source clone of MATLAB apparently

Brian #5: PyperCard - Easy GUIs for All

Nicholas Tollervey Came up on episode 143 Also, episode 89 of Test & Code Really easy to quickly set up a GUI specified by a list of “Card” objects. (different from cards project) Simple examples are choose your own adventure type applications, where one button takes you to another card, and another button, a different card. However, the “next card” could be a Python function that can do anything, as long as it returns a string with the name of the next card. Lots of potential here, especially with input boxes, images, sound, and more. Super fun, but also might have business use.

Michae #6: pynode

Article: Bridging Node.js and Python with PyNode to Predict Home Prices Call python code from node.js Define a Python method In node: require pynode: const pynode = require('@fridgerator/pynode') Start an interpreter: pynode.startInterpreter() Call the function pynode.call('add', 1, 2, (err, result) => { if (err) return console.log('error : ', err) result === 3 // true })


The "Works on My Machine" Certification Program, get certified!

#150 Winning the Python software interview

Oct 5, 2019 0:23:57


Sponsored by Datadog: pythonbytes.fm/datadog

Michael #1: How to Stand Out in a Python Coding Interview

Real Python, by James Timmins Are tech interviews broken? Well at least we can try to succeed at them anyway You’ve made it past the phone call with the recruiter, and now it’s time to show that you know how to solve problems with actual code… Interviews aren’t just about solving problems: they’re also about showing that you can write clean production code. This means that you have a deep knowledge of Python’s built-in functionality and libraries. Things to learn Use enumerate() to iterate over both indices and values Debug problematic code with breakpoint() Format strings effectively with f-strings Sort lists with custom arguments Use generators instead of list comprehensions to conserve memory Define default values when looking up dictionary keys Count hashable objects with the collections.Counter class Use the standard library to get lists of permutations and combinations

Brian #2: The Python Software Foundation has updated its Code of Conduct

There’s now one code of conduct for PSF and PyCon US and other spaces sponsored by the PSF This includes some regional conferences, such as PyCascades, and some meetup groups, (ears perk up) The docs Code of Conduct Enforcement Guidelines Reporting Guidelines Do we need to care? all of us, yes. If there weren’t problems, we wouldn’t need these. attendees, yes. Know before you go. organizers, yes. Better to think about it ahead of time and have a plan than have to make up a strategy during an event if something happens. me, in particular, and Michael. Ugh. yes. our first meetup is next month. I’d like to be in line with the rest of Python. So, yep, we are going to have to talk about this and put something in place.

Michael #3: The Interview Study Guide For Software Engineers

A checklist on my last round of interviews that covers many of the popular topics. Warm Up With The Classics Fizz Buzz 560. Subarray Sum Equals K Arrays: Left Rotation Strings: Making Anagrams Nth Fibonacci Many many videos on interview topics and ideas Data Structures Algorithms Big O Notation Dynamic Programming String Manipulation System Design Operating Systems Threads Object Oriented Design Patterns SQL Fun conversation in the comments

Brian #4: re-assert : “show where your regex match assertion failed”

Anthony Sotille “re-assert provides a helper class to make assertions of regexes simpler.” The Matches objects allows for useful pytest assertion messages In order to get my head around it, I looked at the test code: https://raw.githubusercontent.com/asottile/re-assert/master/tests/re_assert_test.py and modified it to remove all of the with pytest.raises(AssertionError)… to actually get to see the errors and how to use it. def test_match_old(): > assert re.match('foo', 'fob') E AssertionError: assert None E + where None = [HTML_REMOVED]('foo', 'fob') E + where [HTML_REMOVED] = re.match test_re.py:8: AssertionError ____________ test_match_new ___________________ def test_match_new(): > assert Matches('foo') == 'fob' E AssertionError: assert Matches('foo') ^ == 'fob' E -Matches('foo') E - # regex failed to match at: E - # E - #> fob E - # ^ E +'fob'

Michael #5: awesome-python-typing

Collection of awesome Python types, stubs, plugins, and tools to work with them. Taxonomy Static type checkers Stub packages Tools Integrations Articles Communities Related Static type checkers: mypy - Optional static typing for Python 3 and 2 (PEP 484). Stub packages: Typeshed - Collection of library stubs for Python, with static types. Tools (super category): pytest-mypy - Mypy static type checker plugin for Pytest. Articles: Typechecking Django and DRF - Full tutorial about type-checking django.

Brian #6: Developer Advocacy: Frequently Asked Questions

Dustin Ingram I know a handful of people who have this job title. What is it? disclaimer: Dustin is a DA at Google. Other companies might be different What is it? “I help represent the Python community at [company]" “part of my job is to be deeply involved in the Python community.” working on projects that help Python, PyPI, packaging, etc. speaking at conferences talking to people. customers and non-customers talking to product teams being “user zero” for new products and features paying attention to places users might raise issues about products working in open source creating content for Python devs being involved in the community as a company rep representing Python in the company coordinating with other DAs


Not all DAs travel all the time. that was my main question.

Talk Python episode: War Stories of the Developer Evangelists




requests moves to PSF


via https://twitter.com/NotGbo/status/1173667028965777410

Web Dev Merit Badges

#149 Python's small object allocator and other memory features

Sep 25, 2019 0:37:18


Sponsored by Datadog: pythonbytes.fm/datadog

Brian #1: Dropbox: Our journey to type checking 4 million lines of Python

Continuing saga, but this is a cool write up. Benefits “Experience tells us that understanding code becomes the key to maintaining developer productivity. Without type annotations, basic reasoning such as figuring out the valid arguments to a function, or the possible return value types, becomes a hard problem. Here are typical questions that are often tricky to answer without type annotations: Can this function return None? What is this items argument supposed to be? What is the type of the id attribute: is it int, str, or perhaps some custom type? Does this argument need to be a list, or can I give a tuple or a set?” Type checker will find many subtle bugs. Refactoring is easier. Running type checking is faster than running large suites of unit tests, so feedback can be faster. Typing helps IDEs with better completion, static error checking, and more. Long story, but really cool learnings of how and why to tackle adding type hints to a large project with many developers. Conclusion. mypy is great now, because DropBox needed it to be.

Michael #2: Setting Up a Flask Application in Visual Studio Code

Video, but also as a post Follow on to the same in PyCharm: video and post Steps outside VS Code Clone repo Create a virtual env (via venv) Install requirements (via requirements.txt) Setup flask app ENV variable flask deploy ← custom command for DB VS Code Open the folder where the repo and venv live Open any Python file to trigger the Python subsystem Ensure the correct VENV is selected (bottom left) Open the debugger tab, add config, pick Flask, choose your app.py file Debug menu, start without debugging (or with) Adding tests via VS Code Open command pallet (CMD SHIFT P), Python: Discover Tests, select framework, select directory of tests, file pattern, new tests bottle on the right bar

Brian #3: Multiprocessing vs. Threading in Python: What Every Data Scientist Needs to Know

How data scientists can go about choosing between the multiprocessing and threading and which factors should be kept in mind while doing so. Does not consider async, but still some great info. Overview of both concepts in general and some of the pitfalls of parallel computing. The specifics in Python, with the GIL Use threads for waiting on IO or waiting on users. Use multiprocessing for CPU intensive work. The surprising bit for me was the benchmarks Using something speeds up the code. That’s obvious. The difference between the two isn’t as great as I would have expected. A discussion of merits and benefits of both. And from the perspective of data science. A few more examples, with code, included.

Michael #4: ORM - async ORM

And https://github.com/encode/databases The orm package is an async ORM for Python, with support for Postgres, MySQL, and SQLite. SQLAlchemy core for query building. databases for cross-database async support. typesystem for data validation. Because ORM is built on SQLAlchemy core, you can use Alembic to provide database migrations. Need to be pretty async savy

Brian #5: Getting Started with APIs

dataquest.io post Conceptual introduction of web APIs Discussion of GET status codes, including a nice list with descriptions. examples: 301: The server is redirecting you to a different endpoint. This can happen when a company switches domain names, or an endpoint name is changed. 400: The server thinks you made a bad request. This can happen when you don’t send along the right data, among other things. endpoints endpoints that take query parameters JSON data Examples in Python for using: requests to query endpoints. json to load and dump JSON data.

Michael #6: Memory management in Python

This article describes memory management in Python 3.6. Everything in Python is an object. Some objects can hold other objects, such as lists, tuples, dicts, classes, etc. such an approach requires a lot of small memory allocations To speed-up memory operations and reduce fragmentation Python uses a special manager on top of the general-purpose allocator, called PyMalloc. Layered managers RAM OS VMM C-malloc PyMem Python Object allocator Object memory Three levels of organization To reduce overhead for small objects (less than 512 bytes) Python sub-allocates big blocks of memory. Larger objects are routed to standard C allocator. three levels of abstraction — arena, pool, and block. Block is a chunk of memory of a certain size. Each block can keep only one Python object of a fixed size. The size of the block can vary from 8 to 512 bytes and must be a multiple of eight A collection of blocks of the same size is called a pool. Normally, the size of the pool is equal to the size of a memory page, i.e., 4Kb. The arena is a chunk of 256kB memory allocated on the heap, which provides memory for 64 pools. Python's small object manager rarely returns memory back to the Operating System. An arena gets fully released If and only if all the pools in it are empty.



Tuesday, Oct 6, Python PDX West, Thursday, Sept 26, I’ll be speaking at PDX Python, downtown. Both events, mostly, I’ll be working on new programming jokes unless I come up with something better. :)


Gitbook Call for Proposals for PyCon 2020 Is Open

Jokes: A few I liked from the dad joke list.

What do you call a 3.14 foot long snake? A π-thon What if it’s 3.14 inches, instead of feet? A μ-π-thon Why doesn't Hollywood make more Big Data movies? NoSQL. Why didn't the div get invited to the dinner party? Because it had no class.

#148 The ASGI revolution is upon us!

Sep 18, 2019 0:24:03


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Brian #1: Annual Release Cycle for Python - PEP 602

Under discussion Annual release cadence Seventeen months to develop a major version 5 months unversioned, 7 months alpha releases when new features and fixes come in, 4 months of betas with no new features, 1 month final RCs. One year of full support, four more years of security fixes. Rationale/Goals smaller releases features and fixes to users sooner more gradual upgrade path predictable calendar releases that line up will with sprints and PyConUS explicit alpha phase decrease pressure and rush to get features into beta 1 Risks Increase concurrent supported versions from 4 to 5. Test matrix increase for integrators and distributions. PEP includes rejected ideas like: 9 month cadence keep 18 month cadence

Michael #2: awesome-asgi

A curated list of awesome ASGI servers, frameworks, apps, libraries, and other resources ASGI is a standard interface positioned as a spiritual successor to WSGI. It enables communication and interoperability across the whole Python async web stack: servers, applications, middleware, and individual components. Born in 2016 to power the Django Channels project, ASGI and its ecosystem have been expanding ever since, boosted by the arrival of projects such as Starlette and Uvicorn in 2018. Frameworks for building ASGI web applications. Bocadillo - Fast, scalable and real-time capable web APIs for everyone. Powered by Starlette. Supports HTTP (incl. SSE) and WebSockets. Channels - Asynchronous support for Django, and the original driving force behind the ASGI project. Supports HTTP and WebSockets with Django integration, and any protocol with ASGI-native code. FastAPI - A modern, high-performance web framework for building APIs with Python 3.6+ based on standard Python type hints. Powered by Starlette and Pydantic. Supports HTTP and WebSockets. Quart - A Python ASGI web microframework whose API is a superset of the Flask API. Supports HTTP (incl. SSE and HTTP/2 server push) and WebSockets. Responder - A familiar HTTP Service Framework for Python, powered by Starlette. (ASGI 2.0 only, ed.) Starlette - Starlette is a lightweight ASGI framework/toolkit, which is ideal for building high performance asyncio services. Supports HTTP and WebSockets.

Brian #3: Jupyter meets the Earth

Lindsey Heagy & Fernando Pérez “We are thrilled to announce that the NSF is funding our EarthCube proposal “Jupyter meets the Earth: Enabling discovery in geoscience through interactive computing at scale” “ “This project provides our team with $2 Million in funding over 3 years as a part of the NSF EarthCube program. It also represents the first time federal funding is being allocated for the development of core Jupyter infrastructure.” “Our project team includes members from the Jupyter and Pangeo communities, with representation across the geosciences including climate modeling, water resource applications, and geophysics. Three active research projects, one in each domain, will motivate developments in the Jupyter and Pangeo ecosystems. Each of these research applications demonstrates aspects of a research workflow which requires scalable, interactive computational tools.” “The adoption of open languages such as Python and the coalescence of communities of practice around open-source tools, is visible in nearly every domain of science. This is a fundamental shift in how science is conducted and shared.” Geoscience use cases climate data analysis hydrologic modeling geophysical inversions User-Centered Development data discovery scientific discovery through interactive computing established tools and data visualization using and managing shared computational infrastructure

Michael #4: Asynchronous Django

via Jose Nario Python compatibility Django 3.0 supports Python 3.6, 3.7, and 3.8. We highly recommend and only officially support the latest release of each series The Django 2.2.x series is the last to support Python 3.5. Other items but Big news: ASGI support Django 3.0 begins our journey to making Django fully async-capable by providing support for running as an ASGI application. This is in addition to our existing WSGI support. Django intends to support both for the foreseeable future. Note that as a side-effect of this change, Django is now aware of asynchronous event loops and will block you calling code marked as “async unsafe” - such as ORM operations - from an asynchronous context.

Brian #5: The 1x Engineer

Fun take on 10x. List actually looks like probably a 3-4x to me, maybe even 8x or more. How high does this scale go anyway? non-exhaustive list qualities, here’s a few. Has a life outside engineering. Writes code that others can read. Doesn't act surprised when someone doesn’t know something. Asks for help when they need it. Is able to say "I don't know." Asks questions. Constructively participates in code reviews. Can collaborate with others. Supports code, even if they did not write it. Can feel like an impostor at times. Shares knowledge. Never stops learning. [obviously listens to Python Bytes, Talk Python, and Test & Code] Is willing to leave their comfort zone. Contributes to the community. Has productive and unproductive days. Doesn't take themselves too seriously. Fails from time to time. Has a favorite editor, browser, and operating system, but realizes others do too.

Michael #6: Sunsetting Python 2

January 1, 2020, will be the day that we sunset Python 2 Why are you doing this? We need to sunset Python 2 so we can help Python users. How long is it till the sunset date? pythonclock.org will tell you. What will happen if I do not upgrade by January 1st, 2020? If people find catastrophic security problems in Python 2, or in software written in Python 2, then most volunteers will not help fix them. I wrote code in Python 2. How should I port it to Python 3? Please read the official "Porting Python 2 Code to Python 3" guide. I didn't hear anything about this till just now. Where did you announce it? We talked about it at software conferences, on the Python announcement mailing list, on official Python blogs, in textbooks and technical articles, on social media, and to companies that sell Python support.



working on a Portland Westside Python Meetup, info will be at pythonpdx.com Hoping to get something ready for Oct. But… if not, hopefully by Nov.


Humble Level Up Your Python Bundle

#147 Mocking out AWS APIs

Sep 11, 2019 0:25:19


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Brian #1: rapidtables

“rapidtables … converts lists of dictionaries to pre-formatted tables. And it does the job as fast as possible.” Also can do color formatting if used in conjunction with termcolor.colored, but I’m mostly excited about really easily generating tabular data with print. Can also format to markdown or reStructured text, and can do alignment, …

Michael #2: httpx

A next generation HTTP client for Python. 🦋 HTTPX builds on the well-established usability of requests, and gives you: A requests-compatible API. HTTP/2 and HTTP/1.1 support. Support for issuing HTTP requests in parallel. (Coming soon) Standard synchronous interface, but with [async](https://www.encode.io/httpx/async/)/[await](https://www.encode.io/httpx/async/) support if you need it. Ability to make requests directly to WSGI or ASGI applications. This is particularly useful for two main use-cases: Using httpx as a client, inside test cases. Mocking out external services, during tests or in dev/staging environments. Strict timeouts everywhere. Fully type annotated. 100% test coverage. Lovely support for “parallel requests” without full asyncio (at the API level). Also pairs with async / await with async client. Plus all the requests features

Brian #3: Quick and dirty mock service with Starlette

Matt Layman Mock out / fake a third party service in a testing environment. Starlette looks fun, but the process can be used with other API producing server packages. We tell people to do things like this all the time, but there are few examples showing how to. This example also introduces a delay because the service used in production takes over a minute and part of the testing is to make sure the system under test handles that delay gracefully. Very cool, easy to follow write up. (Should probably have Matt on a Test & Code episode to talk about this strategy.)

Michael #4: Mocking out AWS APIs

via Giuseppe Cunsolo A library that allows you to easily mock out tests based on AWS infrastructure. Lovely use of a decorator to mock out S3 Moto isn't just for Python code and it isn't just for S3. Look at the standalone server mode for more information about running Moto with other languages. Be sure to check out very important note.

Brian #5: μMongo: sync/async ODM

“μMongo is a Python MongoDB ODM. It inception comes from two needs: the lack of async ODM and the difficulty to do document (un)serialization with existing ODMs.” works with common mongo drivers such as PyMongo, TxMongo, motor_asyncio, and mongomock. (Hadn’t heard of mongomock before, I’ll have to try that out.) Note: We’ve discussed MongoEngine before. (I’m curious what Michael has to say about uMongo.)

Michael #6: Single Responsibility Principle in Python

via Tyler Matteson I’m a big fan of the SOLID principles They even come in demotivator style posters DI Liskov Substitution Principle Open/Closed Principle Single Responsibility Principle Interface Segregation Principle This article will guide you through a complex process of writing simple code.



Code Challenge Bite 220. Analyzing @pythonbytes RSS feed


Q: What do you get when you cross a computer and a life guard?

A: A screensaver!

Q: What do you get when you cross a computer with an elephant?

A: Lots of memory!

via https://github.com/wesbos/dad-jokes

Anti-joke (we ready for those yet?): A Python developer, a PHP developer, a C# developer, and a Go developer went to lunch together. They had a nice lunch and got along fine.

#146 Slay the dragon, learn the Python

Sep 8, 2019 0:23:35


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Special guest: Trey Hunner

Brian #1: Positional-only arguments in Python

by Sanket Feature in 3.8 “To specify arguments as positional-only, a / marker should be added after all those arguments in the function definition. “ Great example of a pow(x, y, /, mod=None) function where the names x and y are meaningless and if given in the wrong order would be confusing.

Trey #2: django-stubs

Type checking for Django! It’s new and from my very quick testing on my Django site it definitely doesn’t work with everything yet, but it’s promising I don’t use type annotations in Django yet, but I very well might eventually

Michael #3: CodeCombat

Super fun game for learning to code Real code but incredibly easy coding Can subscribe or use the free tier Just got $6M VC funding

Brian #4: Four Use Cases for When to Use Celery in a Flask Application

or really any web framework by Nick Janetakis “Celery helps you run code asynchronously or on a periodic schedule which are very common things you'd want to do in most web projects.” examples: sending emails out connecting to 3rd party APIs. performing long running tasks. Like, really long. Running tasks on a schedule.

Trey #5: pytest-steps

Created by smarie Can use a generator syntax with yield statements to break a big test up into multiple named “steps” that’ll show up in your pytest output If one step fails, the rest of the steps will be skipped by default You can also customize it to make optional steps, which aren’t required for future steps to run, or steps which depend on other optional steps explicitly The documentation shows a lot of different ways to use it, but the generator approach looks by far the most readable to me (also state is shared between steps with this approach whereas the others require some fancy state-capturing object which looks confusing to me) I haven’t tried this, but my use case would be my end-to-end/functional tests, which would work great with steps because I’m often using Selenium to navigate between a number of different pages and forms, one click at a time.

Michael #6: docassemble

Created by Jonathan Pyle A free, open-source expert system for guided interviews and document assembly, based on Python, YAML, and Markdown. Features WYSIWYG: Compose your templates in .docx (with help of a Word Add-in) or .pdf files. Signatures: Gather touchscreen signatures and embed them in documents. Live chat: Assist users in real time with live chat, screen sharing, and remote screen control. AI: Use machine learning to process user input. SMS: Send text messages to your users E-mail: Send and receive e-mails in your interviews. OCR: Use optical character recognition to process images uploaded by the user. Multilingual: Offer interviews in multiple languages. Multiuser: Develop applications that involve more than one user, such as mediation or counseling interviews. Extensible: Use the power of Python to extend the capabilities of your interviews. Open: Package your interviews and use GitHub and PyPI to share your work with the docassemble user community. Background Tasks: Do things behind the scenes of the interview, even when the user is not logged in. Scalable: Deploy your interviews on multiple machines to handle high traffic. Secure: Protect user information with server-side encryption, two-factor authentication, document redaction, and other security features. APIs: Integrate with third-party applications using the API, or send your interviews input and extract output using code.



PyPI closes in on 200k NumPy 1.17.0 released Python 3.8.0b4 is out


via Avram Lubkin

Knock! Knock! Who's there? Recursive function. Recursive function who? Knock! Knock!

Nice. to get that joke, you’ll have to understand recursion. to understand recursion,

either google “recursion”, and click on “did you mean “recursion”” learn it in small steps. step one, recursion

text conversation:

first person: “Hey, what’s your address?” second: [HTML_REMOVED] first: “No. Your local address” second: first: “No. Your physical address” second: [HTML_REMOVED]

#145 The Python 3 “Y2K” problem

Aug 31, 2019 0:34:24


Sponsored by Datadog: pythonbytes.fm/datadog

Special guests

Matt Harrison Anthony Sottile

Michael #1: friendly-traceback

via Jose Carlos Garcia (I think 🙂 ) Aimed at Python beginners: replacing standard traceback by something easier to understand Shows help for exception type Shows local variable values Shows code in a cleaner form with more context 3 ways to install As an exception hook Explicit explain When running an app

Matt #2: Pandas Users Survey

Most use it almost everyday but have less than 2 years experience Linux 61%, Windows 60%, Mac 42% 93% Python 3

Anthony #3: python3 “Y2K” problem (python3.10 / python4.0)

with python3.8 close to release and python3.9 right around the corner, what comes after? both python3.10 and python4.0 present some problems sys.version[:3] which will suddenly report '``3.1``' in 3.10 a lot of code (including six.PY3!) uses sys.version_info[0] == 3 which will suddenly be false in python4.0 (and start running python2 code!) early-to-mid 2020 we should start seeing the next version in the wild as python3.9 reaches beta easy ways to start testing this early: python3.10 - a build of cpython for ubuntu with the version number changed flake8-2020 - a flake8 plugin which checks for these common issues-

Michael #4: pypi research

via Adam (Codependent Codr) Really interesting research paper on the current state of Pypi from a couple authors at the University of Michigan: "An Empirical Analysis of the Python Package Index" - https://arxiv.org/pdf/1907.11073.pdf Comprehensive empirical summary of the Python Package Repository, PyPI, including both package metadata and source code covering 178,592 packages, 1,745,744 releases, 76,997 contributors, and 156,816,750 import statements. We provide counts and trends for packages, releases, dependencies, category classifications, licenses, and package imports, as well as authors, maintainers, and organizations. Within PyPI, we find that the growth of the repository has been robust under all measures, with a compound annual growth rate of 47% for active packages, 39% for new authors, and 61% for new import statements over the last 15 years. In 2005, there were 96 active packages, 96! MIT is the most common license (Matt) I saw this and was surprised at most commonly used libraries. What do you think the most common 3rd party library is?

Matt #5: DaPy

“Pandas for humans” - Matt’s words Has portions of pandas, scikit-learn, yellowbrick, and numpy Designed for “data analysis, not for coders”

Anthony #6: python-remote-pdb

very small over-the-network remote debugger thin wrapper around pdb in a single file (easy to drop the file on PYTHONPATH if you can’t pip install) not as fully featured as other remote debuggers such as pudb / rpdb / pycharm’s debugger but very easy to drop in fully supports [breakpoint()](https://www.python.org/dev/peps/pep-0553/) (python3.7+ or via future-breakpoint) access pdb via telnet / nc / socat I’m using it to debug a text editor I’m writing to learn curses!



Hacker Gets $12,000 In Parking Tickets After 'NULL' License Plate Trick Backfires PyCon 2020 site is up


http://bit.ly/psxgb - My new course on Machine Learning with XGBoost


https://github.com/DRMacIver/hecate “like selenium webdriver for the terminal”


Michael: Two mathematicians are sitting at a table in a pub having an argument about the level of math education among the general public.

The one defending overall math knowledge gets up to go to the washroom. On the way back, he encounters their waitress and says, "I'll add an extra $10 to your tip, if you'll answer a question for me when I ask it. All you have to say is 'x-squared'." She agrees.

A few minutes later the populist mathematician says to his buddy, "I'll bet you $20 that even our waitress can tell us the integral of 2x." The cynic agrees to the bet.

So the schemer beckons the waitress to their table and asks the question, to which she replies "x-squared". As he begins to gloat and demand his winnings, the waitress continues, "Plus a constant."

Anthony: I had a golang joke prepared, but then I panic()d

#144 Are you mocking me? It won't work!

Aug 23, 2019 00:25:46


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Chris #1: Why your mock doesn’t work

Ned Batchelder TDD is an important practice for development, and as my team is finding out, mocking objects is not as easy at it seems at first. I love that Ned gives an overview of how Mock works But also gives two resources to show you alternatives to Mock, when you really don’t need it. From reading these articles and video, I’ve learned that it’s hard to make mocks but it’s important to: Create only one mock for each object you’re mocking that mocks only what you need have tests that run the mock against your code and your mock against the third party

Mahmoud #2: Vermin

By Morten Kristensen Rules-based Python version compatibility detector caniuse is cool, but it’s based on classifiers. When it comes to your own code, it’ll only tell you what you tell it. If you’ve got legacy libraries, or like most companies, an application, then you’ll need something more powerful. Vermin tells you the minimum compatible Python version, all the way down to the module and even function level.

Brian #3: The nonlocal statement in Python

Abhilash Raj When global is too big of a hammer. This doesn’t work: def function(): x = 100 def incr(y): x = x + y incr(100) This does: def function(): x = 100 def incr(y): nonlocal x x = x + y incr(100) print(x)

Chris #4: twitter.com/brettsky/status/1163860672762933249

Brett Cannon Microsoft Azure improves python support 2 key points about the new Python support in Azure Functions: it's debuting w/ 3.6, but 3.7 support is actively being worked on and 3.8 support won't take nearly as long, and native async/await support!

Mahmoud #5: Awesome Python Applications update

Presented at PyBay 2019 Slides/summary (video forthcoming): http://sedimental.org/talks.html#ask-the-ecosystem-lessons-from-250-foss-python-applications 250+ applications, dating back to 1998 (mailman, gedit) 95% of applications have commits in 2019 65% of applications support Python 3 (even the ones with a long history!) Other interesting findings Presenting these findings and more at PyGotham 2019. NYC in early October.

Brian #6: pre-commit now has a quick start guide

Wanna use pre-commit but don’t know how to start? Here ya go! Runs through install configuration installing hooks running hooks against your project I’d like to add Add hooks to your project one at a time For each new hook add to pre-commit-config.yml run pre-commit install to install hook run pre-commit run --``all-files review changes made to your project if good, commit if bad revert modify config of tools, such as pyproject.toml for black, .flake8 for flake8, etc. try again



Humble Bundle by No Starch supports the Python Software Foundation https://codechalleng.es/ released Newbie Bites… challenges that are intended for people brand new to python. [[direct link](https://gumroad.com/l/Xhxeo)]


PyGotham 2019 October (Maintainers Conf in Washington DC, too) Real Python Pandas course


http://py3readiness.org/ shows 360 of the top downloaded Python packages are all Python 3 ready.


I was looking for some programming one liners online; looked on a reddit thread; read a great answer; which was “any joke can be a one-liner with enough semicolons.” A SQL statement walks into to a bar and up to two tables and asks, “Mind if I join you?”

#143 Spike the robot, powered by Python!

Aug 14, 2019 00:33:19


Special guest: Kelly Schuster-Paredes

Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Brian #1: Keynote: Python 2020 - Łukasz Langa - PyLondinium19

Enabling Python on new platforms is important. Python needs to expand further than just CPython. Web, 3D games, system orchestration, mobile, all have other languages that are more used. Perhaps it’s because the full Python language, like CPython in full is more than is needed, and a limited language is necessary. MicroPython and CircuitPython are successful. They are limited implementations of Python Łukasz talks about many parts of Python that could probably be trimmed to make targeted platforms very usable without losing too much. It’d be great if more projects tried to implement Python versions for other platforms, even if the Python implementation is limited.

Kelly #2: Mu Editor

by Nicholas Tollervey Lots of updates happening to the Code with Mu software Mu is a Python code editor for beginner programmers originally created as a contribution from the Python Software Foundation for the BBC’s micro:bit project Code with Mu presented at EuroPython and shared a lot of interesting updates and things in the alpha version of Mu, available on code with Mu website. Mu is a modal editor: BBC Microbit Circuit Python ESP Micropython Pygame Zero Python 3 Tiago Monte’s recorded presentation at EuroPython Game with Turtle Flask — release notes Made with Mu at EuroPython videos Hot off the press: Nick just released Pypercard a HyperCard inspired GUI framework for BEGINNER developers in Python based off of Adafruit’s release. It is a “PyperCard is a HyperCard inspired Pythonic and deliberately constrained GUI framework for beginner programmers. linked repos on GitHub. module re-uses the JSON specification used to create HyperCard The concept allows user to “create Hypercard like stacks of states” to allow beginner coders to create choose their own adventure games.

Michael #3: Understanding the Python Traceback

by Chad Hansen The Python traceback has a wealth of information that can help you diagnose and fix the reason for the exception being raised in your code. What do we learn right away? The type of error A description of the error (hopefully, sometimes) The line of code the error occurred on The call stack (filenames, line numbers, and module names) If the error happened while handling another error Read from bottom to top — that was weird to me Most common error? AttributeError: 'NoneType' object has no attribute 'an_attribute' Article talks about other common errors Are you creating custom exceptions to make your packages more useful?

Brian #4: My oh my, flake8-mypy and pytest-mypy

contributed by Ray Cote via email “For some reason, I continually have problems running mypy, getting it to look at the correct paths, etc. However, when I run it from flake8-mypy, I'm getting reasonable, actionable output that is helping me slowly type hint my code (and shake out a few bugs in the process). There's also a pytest-mypy, which I've not yet tried. “ - Ray flake8-mypy ** Maintained by Łukasz Langa “The idea is to enable limited type checking as a linter inside editors and other tools that already support Flake8 warning syntax and config.” pytest-mypy Maintained by Dan Bader and David Tucker “Runs the mypy static type checker on your source files as part of your pytest test runs.” Remind me to do a PR against the README to make pytest lowercase.

Kelly #5: Lego Education and Spike

In March of this year, Lego Education gave news of a new robot being released since the EV3 released of Mindstorms in 2013. Currently the EV3 Mindstorm can be coded with Python and it is assumed that Spike Prime can be as well. The current EV3 robots can currently be coded in python thanks to Nigel Ward. He created a site back in 2016 or earlier; through a program called the EV3Dev project. ev3dev is a Debian Linux-based operating system Until recently, Lego had not endorsed the use of Python or had they released documentation. Lego released a Getting started with EV3 MicroPython 59 page guide Version 1.0.0 EV3 MicroPython runs on top of ev3dev with a new Pybricks MicroPython runtime and library. has its own Visual Studio Code extension no need for terminal Has instruction and lists of different features and classes used to program the PyBricks API- A python wrapper for the Databricks Rest API. Pybricks is on GitHub from one contributor, Sebastien Thomas under MIT license David Lechner, Laurens Valk, and Anton Vanhoucke are contributors of the Lego MicroPython release. This opens up opportunities for students that compete in the First Lego League Competition to code in Python. Example code for the Gyrobot

Michael #6: Python 3 at Mozilla

From January 2019. Mozilla uses a lot of Python. In mozilla-central there are over 3500 Python files (excluding third party files), comprising roughly 230k lines of code. Additionally there are 462 repositories labelled with Python in the Mozilla org on Github That’s a lot of Python, and most of it is Python 2. But before tackling those questions, I want to address another one that often comes up right off the bat: Do we need to be 100% migrated by Python 2’s EOL? No. But punting the migration into the indefinite future would be a big mistake: Python 2 will no longer receive security fixes. All of the third party packages we rely on (and there are a lot of them) will also stop being supported Delaying means more code to migrate Opportunity cost: Python 3 was first released in 2008 and in that time there have been a huge number of features and improvements that are not available in Python 2. The best time to get serious about migrating to Python 3 was five years ago. The second best time is now. Moving to Python 3 We stood up some linters. One linter that makes sure Python files can at least get imported in Python 3 without failing One that makes sure Python 2 files use appropriate __future__ statements to make migrating that file slightly easier in the future. Pipenv & poetry & Jetty: a little experiment I’ve been building. It is a very thin wrapper around Poetry



Python 3.8.0b3 “We strongly encourage maintainers of third-party Python projects to test with 3.8 during the beta phase and report issues …”


pipx now has shell completions


Teaching Python podcast


via Real Python and Nick Spirit Python private method → Joke cartoon image.

#142 There's a bandit in the Python space

Aug 6, 2019 00:30:31


Special guest: Brett Thomas

Sponsored by Datadog: pythonbytes.fm/datadog

Brian #1: Writing sustainable Python scripts

Vincent Bernat Turning a quick Python script into a maintainable bit of software. Topics covered: Documentation as a docstring helps future users/maintainers know what problem you are solving. CLI arguments with defaults instead of hardcoded values help extend the usability of the script. Logging. Including debug logging (and how to turn them on with CLI arguments), and system logging for unattended scripts. Tests. Simple doctests, and pytest tests utilizing parametrize to have one test and many test cases.

Brett #2: Static Analysis and Bandit

Michael #3: jupyter-black

Black formatter for Jupyter Notebook One of the big gripes I have about these online editors is their formatting (often entirely absent) Then the extension provides a toolbar button a keyboard shortcut for reformatting the current code-cell (default: Ctrl-B) a keyboard shortcut for reformatting whole code-cells (default: Ctrl-Shift-B)

Brian #4: Report Generation workflow with papermill, jupyter, rclone, nbconvert, …

Chris Moffitt articles Automated Report Generation with Papermill: Part 1 Automated Report Generation with Papermill: Part 2 Jupyter Notebooks used to create a report with pandas and matplotlib nbconvert to create an html report Papermill to parametrize the process with different data, and execute the notebook Copy the reports to shared cloud folders using Rclone. Set up a process to automate everything. Hook it up to cron to run regularly

Brett #5: Rant on time deltas

datetime.timedelta(months=1) # Boom, too bad. Use: https://dateutil.readthedocs.io/en/stable/

Michael #6: How — and why — you should use Python Generators

by Radu Raicea Generator functions allow you to declare a function that behaves like an iterator. They allow programmers to make an iterator in a fast, easy, and clean way. They only compute it when you ask for it. This is known as lazy evaluation. If you’re not using generators, you’re missing a powerful feature Often they result in simpler code than with lists and standard functions



PyPI now supports uploading via API token also on Test PyPI


Chocolatey package manager on windows via Prayson Daniel GvM’s Next PEG article


A good programmer is someone who always looks both ways before crossing a one-way street.

(reminds me of another joke: Adulthood is like looking both ways before crossing the street, then getting hit by an airplane)

Little bobby tables

#141 Debugging with f-strings coming in Python 3.8

Jul 29, 2019 00:30:45


Sponsored by Datadog: pythonbytes.fm/datadog

Brian #1: Debugging with f-strings in Python 3.8

We’ve talked about the walrus operator, :=, but not yet “debug support for f-strings” this: print(f'foo={foo} bar={bar}') can change to this: print(f'{foo=} {bar=}') and if you don’t want to print with repr() you can have str() be used with !s. print(f'{foo=!s} {bar=!s}') also !f can be used for float modifiers: >>> import math >>> print(f'{math.pi=!f:.2f}') math.pi=3.14 one more feature, space preservation in the f-string expressions: >>> a = 37 >>> print(f'{a = }, {a = }') a = 37, a = 37

Michael #2: Am I "real" software developer yet?

by Sun-Li Beatteay To new programmers joining the field, especially those without CS degrees, it can feel like the title is safe-guarded. Only bestowed on the select that have proven themselves. Sometimes manifests itself as Impostor Syndrome Focused on front-end development as I had heard that HTML, CSS and JavaScript were easy to pick up That was when I decided to create a portfolio site for my wife, who was a product designer. Did my best to surround myself with tech culture. Watched YouTube videos listened to podcasts read blog posts from experienced engineers to keep myself motivated. Daydreamed what it would be like to stand in their shoes. My wife’s website went live in July of that year. I had done it. Could I finally start calling myself something of a Software Engineer? “Web development isn’t real programming” Spent the next 18 months studying software development full time. I quit my job and moved in with my in-laws — which was a journey in-and-of itself. Software engineer after 1-2 years? No so fast (says the internet) The solution that I found for myself was simple yet terrifying: talking to people MK: BTW, I don’t really like the term “engineer”

Brian #3: Debugging with local variables and snoop

debugging tools ex: “You want to know which lines are running and which aren't, and what the values of the local variables are.” Throw a @snoop decorator on a function and the function lines and local variable values will be dumped to stderr during run. Even showing loops a bunch of times. It’s tools to almost debug as if you had a debugger, without a debugger, and without having to add a bunch of logging or print statements. Lots of other use models to allow more focus. wrap just part of your function with a with snoop block only watch certain local variables. turn off reporting for deep function/block levels.

Michael #4: New home for Humans

This came out of the blue with some trepidation: kennethreitz commented 6 days ago:

In the spirit of transparency, I'd like to (publicly) find a new home for my repositories. I want to be able to still make contributions to them, but no longer be considered the "owner" or "arbiter" or "BDFL" of these repositories.

Some notable repos:

https://github.com/kennethreitz/requests https://github.com/kennethreitz/records https://github.com/kennethreitz/requests-html https://github.com/kennethreitz/setup.py https://github.com/kennethreitz/legit


Lots of back and forth until Ernest jumped in.

The Python Software Foundation would like to offer to accept transfers of these repositories into the @psf GitHub organization. This organization was recently acquired by the Python Software Foundation and intended to provide administrative backstopping for projects in the ecosystem; existing maintainers of various projects will remain and the PSF staff will be available to manage repositories and teams as necessary.

Brian #5: The Backwards Commercial License

Eran Hammer - open source dev, including hapi.js Interesting idea to make open source projects maintainable Three phases of software lifecycle for some projects: first: project created to fill a need in one project/team/company, a single use case second: used by many, active community, growing audience three: work feels finished. bug fixes, security issues, minor features continue, but most people can stay on old stable versions During the “done” phase, companies would like to have bug fixes but don’t want to have to keep changing their code to keep up. Idea: commercial license to support old stable versions. “If you keep up with the latest version, you do not require a license (unless you want the additional benefits it will provide).” “However, very few companies can quickly migrate every time there is a new major release of a core component. Engineering resources are limited and in most cases, are better directed at building great products than upgrading supporting infrastructure. The backwards license provides this exact assurance. You can stay on any version you would like knowing that you are still running supported, well-maintained, and secure code.” “The new commercial license will include additional benefits focused on providing enterprise customers the assurances needed to rely on these critical components for many years to come. “

Michael #6: Switching Python Parsers?

via Gi Bi, article by Guido van Rossum Alternative to the home-grown parser generator that I developed 30 years ago when I started working on Python. (That parser generator, dubbed “pgen”, was just about the first piece of code I wrote for Python.) Here are some of the issues with pgen that annoy me. The “1” in the LL(1) moniker implies that it uses only a single token lookahead, and this limits our ability of writing nice grammar rules. Because of the single-token lookahead, the parser cannot determine whether it is looking at the start of an expression or an assignment. So how does a PEG parser solve these annoyances? By using an infinite lookahead buffer! The typical implementation of a PEG parser uses something called “packrat parsing”, which not only loads the entire program in memory before parsing it, but also allows the parser to backtrack arbitrarily. Why not sooner? Memory! But that is much less of an issue now. My idea now, putting these things together, is to see if we can create a new parser for CPython that uses PEG and packrat parsing to construct the AST directly during parsing, thereby skipping the intermediate parse tree construction, possibly saving memory despite using an infinite lookahead buffer



Plone 5.2 https://plone.org/news/2019/plone-5-2-the-future-proofing-release Plone is a content management system built on top of Zope, a web application server framework. Plone 5.2 supports Python 3.6, 3.7, 3.8 uses Zope 4, which also support Python 3 Multi-year effort Interview with Philip Bauer, organizer of 5.2.


Building Dab and T-Pose Controlled Lights - Make Art with Python


A couple of quick ones:

“What is a whale’s favorite language?” “C” — via Eric Nelson Why does Pythons live on land? Because it is above C-level! — via Jesper Kjær Sørensen @JKSlonester

#140 Becoming a 10x Developer (sorta)

Jul 23, 2019 00:24:39


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Brian #1: Becoming a 10x Developer : 10 ways to be a better teammate

Kate Heddleston “A 10x engineer isn’t someone who is 10x better than those around them, but someone who makes those around them 10x better.” Create an environment of psychological safety Encourage everyone to participate equally Assign credit accurately and generously Amplify unheard voices in meetings Give constructive, actionable feedback and avoid personal criticism Hold yourself and others accountable Cultivate excellence in an area that is valuable to the team Educate yourself about diversity, inclusivity, and equality in the workplace Maintain a growth mindset Advocate for company policies that increase workplace equality article includes lots of actionable advice on how to put these into practice. examples: Ask people their opinions in meetings. Notice when someone else might be dominating a conversation and make room for others to speak.

Michael #2: quasar & vue.py

via Doug Farrell Quasar is a Vue.js based framework, which allows you as a web developer to quickly create responsive++ websites/apps in many flavours: SPAs (Single Page App) SSR (Server-side Rendered App) (+ optional PWA client takeover) PWAs (Progressive Web App) Mobile Apps (Android, iOS, …) through Apache Cordova Multi-platform Desktop Apps (using Electron) Great for python backends tons of vue components But could it be all python? vue.py provides Python bindings for Vue.js. It uses brython to run Python in the browser. Examples can be found here.

Brian #3: Regular Expressions 101

We talked about regular expressions in episode 138 Some tools shared with me after I shared a regex joke on twitter, including this one. build expressions for Python and also PHP, JavaScript, and Go put in an example, and build the regex to match explanations included match information including match groups and multiple matches quick reference of all the special characters and what they mean generates code for you to see how to use it in Python Also fun (and shared from twitter): Regex Golf see how far you can get matching strings on the left but not the list on the right. I got 3 in and got stuck. seems I need to practice some more

Michael #4: python-diskcache

Caching can be HUGE for perf benefits But memory can be an issue Persistence across executions (e.g. web app redeploy) an issue Servers can be issues themselves Enter the disk! Python disk-backed cache (Django-compatible). Faster than Redis and Memcached. Pure-Python. DigitalOcean and many hosts now offer SSD’s be default Unfortunately the file-based cache in Django is essentially broken. DiskCache efficiently makes gigabytes of storage space available for caching. By leveraging rock-solid database libraries and memory-mapped files, cache performance can match and exceed industry-standard solutions. There's no need for a C compiler or running another process. Performance is a feature Testing has 100% coverage with unit tests and hours of stress. Nice comparison chart

Brian #5: The Python Help System

Overview of the built in Python help system, help() examples to try in a repl help(print) help(dict) help('assert') import math; help(math.log) Also returns docstrings from your non-built-in stuff, like your own methods.

Michael #6: Python Architecture Graphs

by David Seddon Impulse - a CLI which allows you to quickly see a picture of the import graph any installed Python package at any level within the package. Useful to run on an unfamiliar part of a code base, to help get a quick idea of the structure. It's a visual explorer to give you a quick signal on architecture. Import Linter - this allows you to declare and check contracts about your dependency graph, which gives you the ability to lint your code base against architectural rules. Helpful to enforce certain architectural constraints and prevent circular dependencies creeping in.



tabnanny flask course is out, give it a look


Two threads walk into a bar. The barkeeper looks up and yells, 'Hey, I want don't any conditions race like time last!’

A string value walked into a bar, and then was sent to stdout.

#139 f"Yes!" for the f-strings

Jul 18, 2019 00:38:42


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Special guest: Ines Montani

Brian #1: Simplify Your Python Developer Environment

Contributed by Nils de Bruin “Three tools (pyenv, pipx, pipenv) make for smooth, isolated, reproducible Python developer and production environments.” The tools: pyenv - install and manage multiple Python versions and flavors pipx - install a Python application with it’s own virtual environment for use globally pipenv - managing virtual environments, dependencies, on a per project basis Brian note: I’m not sold on any of these yet, but honestly haven’t given them a fair shake either, but also didn’t really know how to try them all out. This is a really good write up to get started.

Ines #2: New fast.ai course: A Code-First Introduction to Natural Language Processing

fast.ai is a really popular, free course for deep learning by Rachel Thomas and Jeremy Howard Also comes with a Python library and lots of notebooks Some influential research developed alongside the course, e.g. ULMFiT (popular algorithm for NLP tasks like text classification) New course on Natural Language Processing: Practical introduction to NLP covering both modern neural network approaches and traditional techniques Highlights: NLP background: topic modeling and linear models Rule-based approaches and real-world problem solving Focus on ethics – videos on bias and disinformation

Michael #3: Cloning the human voice

In 5 minutes, with Python via Brenden Clone a voice in 5 seconds to generate arbitrary speech in real-time An implementation of Transfer Learning from Speaker Verification to Multispeaker Text-To-Speech Synthesis (SV2TTS) with a vocoder that works in real-time. Watch the video: https://www.youtube.com/watch?v=-O_hYhToKoA Also: Fake voices 'help cyber-crooks steal cash

Brian #4: Ab(using) pyproject.toml and stuffing pytest.ini and mypy.ini content into it

Contributed by Andrew Spittlemeister My first reaction is horror, but this is kinda my thought process with this one toml is not ini (but they look close) neither pytest nor mypy support storing configuration in pyproject.toml they both do support using setup.cfg (but flit and poetry projects don’t use that file, or try not to) they both support passing in the config file as a command line argument you can be careful and write a pyproject.toml file that is both toml and ini compliant drat, this is a reasonable idea, if not a little wacky no guarantee that it will keep working one thing to note: use quotes for stuff you normally wouldn’t need to in ini file.

Example ini:

[pytest] addopts = -ra -v

if stuffed in pyproject.toml

[pytest] addopts = "-ra -v"

to run:

> mypy --config-file pyproject.toml module_name > pytest -c pyproject.toml

Ines #5: *Polyaxon*

A platform for reproducing and managing the whole life cycle of machine learning and deep learning applications. We talked to lots of research groups and everyone works with just their GPU on desktop. Super slow – you need to wait for results, schedule next job etc. Polyaxon is a free open source library built on Kubernetes. Really easy to set up, especially on Google Kubernetes Engine. Especially good for hyper-parameter search, where you might not need GPU experiments if you can run lots of experiments in parallel Release v0.5 just came today. Big improvements: Plugins system Local runs, for much easier debugging New workflow engine for chaining things together and run experiments with lots of steps

Michael #6: Flynt for f-strings

A tool to automatically convert old string literal formatting to f-strings F-Strings: Not only are they more readable, more concise, and less prone to error than other ways of formatting, but they are also faster! Converted over 500 lines / expressions in Talk Python Training and Python Bytes. Get started with a pipx install: pipx install flynt Then point it at A file: flynt somefile.py A directory (recursively): flynt ./ Converts code like this: print(``"``Greetings {}, you have found {:,} items!``"``.format(name, count)) To code like this: print(f"Greetings {name}, you have found {count:,} items!") Beware of the digit grouping bug. Good project to jumping in and contributing to open source


Thanks to André Jaenisch for pointing the existence of ReDoS attacks and a good video explaining them.


Python httptoolkit Python Magic’s name via David Martínez Flying Fractals (video and code) Python 3.7.4 is out


Explosion (?) spaCy IRL 2019 our very first conference held on July 6 in Berlin many amazing speakers from research, applied NLP and the community all talks were recorded and will be up on our YouTube channel very soon FastAPI core developer Sebastián Ramírez is joining our team FastAPI was presented by Brian in episode 123 of this podcast we’re big fans and have been switching all our APIs over to FastAPI we’ll keep supporting the project and will definitely give Sebastián enough time to keep working on it


A programmer walks into a bar and orders 1.38 root beers. The bartender informs her it's a root beer float. She says 'Make it a double!’ What do you call a developer without a side project? Well rested.

#138 Will PyOxidizer weld shut one of Python's major gaps?

Jul 8, 2019 00:29:39


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Brian #1: flake8-comprehensions

submitted by Florian Dahlitz I’m already using flake8, so adding this plugin is a nice idea. checks your code for some generator and comprehension questionable code. C400 Unnecessary generator - rewrite as a list comprehension. C401 Unnecessary generator - rewrite as a set comprehension. C402 Unnecessary generator - rewrite as a dict comprehension. C403 Unnecessary list comprehension - rewrite as a set comprehension. C404 Unnecessary list comprehension - rewrite as a dict comprehension. C405 Unnecessary (list/tuple) literal - rewrite as a set literal. C406 Unnecessary (list/tuple) literal - rewrite as a dict literal. C407 Unnecessary list comprehension - '[HTML_REMOVED]' can take a generator. C408 Unnecessary (dict/list/tuple) call - rewrite as a literal. C409 Unnecessary (list/tuple) passed to tuple() - (remove the outer call to tuple()/rewrite as a tuple literal). C410 Unnecessary (list/tuple) passed to list() - (remove the outer call to list()/rewrite as a list literal). C411 Unnecessary list call - remove the outer call to list(). Example: Rewrite list(f(x) for x in foo) as [f(x) for x in foo] Rewrite set(f(x) for x in foo) as {f(x) for x in foo} Rewrite dict((x, f(x)) for x in foo) as {x: f(x) for x in foo}

Michael #2: PyOxidizer (again)

Michael’s assessment - There are three large and looming threats to Python. Lack of A real mobile development story GUI applications on desktop operating systems Sharing your application with users (this is VERY far from deployment to servers) Cover PyOxidizer before but seems to have just rocketed off last couple of weeks. At their PyCon 2019 keynote talk, Russel Keith-Magee identified code distribution as a potential black swan - an existential threat for longevity - for Python. “Python hasn't ever had a consistent story for how I give my code to someone else, especially if that someone else isn't a developer and just wants to use my application.” They announced the first release of PyOxidizer (project, documentation), an open source utility that aims to solve the Python application distribution problem! PyOxidizer's marquee feature is that it can produce a single file executable containing a fully-featured Python interpreter, its extensions, standard library, and your application's modules and resources. You can have a single .exe providing your application. Unlike other tools in this space which tend to be operating system specific, PyOxidizer works across platforms (currently Windows, macOS, and Linux - the most popular platforms for Python today). PyOxidizer loads everything from memory and there is no explicit I/O being performed. When you **import** a Python module, the bytecode for that module is being loaded from a memory address in the executable using zero-copy. This makes PyOxidizer executables faster to start and import - faster than a python executable itself!

Brian #3: Using changedir to avoid the need for src

I’ve been experimenting with combining flit, pytest, tox, and coverage for new projects. And in doing so, ran across a cool feature of tox that I didn’t know about before, changedir. It’s a feature of tox to allow you to run tests in a different directory than the top level project directory. tox changedir docs tox and pytest and changedir I talk about this more in episode 80 of Test & Code. As an example project I build yet another markdown converter using regular expressions. This is funny to me, considering the recent cloudflare outage due to a single regular expression. https://blog.cloudflare.com/cloudflare-outage/ “Tragedy is what happens to me, comedy is what happens to you” - Mel Brooks approximate quote.

Michael #4: WebRTC and ORTC implementation for Python using asyncio

Web Real-Time Communication (WebRTC) - WebRTC is a free, open project that provides browsers and mobile applications with Real-Time Communications (RTC) capabilities via simple APIs. Object Real-Time Communication (ORTC) - ORTC (Object Real-Time Communications) is an API allowing developers to build next generation real-time communication applications for web, mobile, or server environments. The API closely follows its Javascript counterpart while using pythonic constructs: promises are replaced by coroutines events are emitted using pyee.EventEmitter The main WebRTC and ORTC implementations are either built into web browsers, or come in the form of native code. In contrast, the aiortc implementation is fairly simple and readable. Good starting point for programmers wishing to understand how WebRTC works or tinker with its internals. Easy to create innovative products by leveraging the extensive modules available in the Python ecosystem. For instance you can build a full server handling both signaling and data channels or apply computer vision algorithms to video frames using OpenCV.

Brian #5: Apprise - Push Notifications that work with just about every platform!

listener suggestion cool shim project to allow multiple notification services in one app “Apprise allows you to send a notification to almost all of the most popular notification services available to us today such as: Telegram, Pushbullet, Slack, Twitter, etc. One notification library to rule them all. A common and intuitive notification syntax. Supports the handling of images (to the notification services that will accept them).” supports notification services such as discord, gitter, ifttt, mailgun, mattermost, MS teams, twitter, … SMS notification through Twilio, Nexmo, AWS, D7 email notifications

Michael #6: Websauna web framework

Websauna is a full stack Python web framework for building web services and back offices with admin interface and sign up process https://websauna.org "We have web applications 80% figured out. Websauna takes it up to 95%.” Built upon Python 3, Pyramid, and SQLAlchemy. When to use it? Websauna is focused on Internet facing sites where you have a public or private sign up process and an administrative interface. Its sweet spots include custom business portals and software-as-a-service products which are too specialized for off-the-shelf solutions. Benefits Focus on core business logic as Websauna provides basic website building blocks like sign up and sign in. Low learning curve and friendly comprehensive documentation help novice developers Emphasis is on meeting business requirements with reliable delivery times, responsiveness, consistency Site operations is half the story. Websauna provides an automated deployment process and integrates with monitoring, security and other DevOps solutions.



Data driven Flask course is out!


Recent Test & Code episodes were solo because I’m in the middle of a work move and didn’t want to schedule interviews around a crazy work schedule. However, that should settle down in July and I can get back to getting great guests on the show. But I’m also having fun with solo topics, so I’ll keep that in the mix. upshot: if I’ve contacted you or you me about being on the show and you haven’t heard from me lately, give me a nudge with a DM or email or something.


An SQL query goes into a bar, walks up to two tables and asks, 'Can I join you?' Not a joke, really, but along the lines of “comedy when it happens to you”. Reset procedure for GE lightbulbs theregister.co.uk/2019/06/20/ge_lightblulb_reset

#137 Advanced Python testing and big-time diffs

Jul 2, 2019 00:28:05


Sponsored by Rollbar: https://pythonbytes.fm/rollbar

Brian #1: Comparing the Same Project in Rust, Haskell, C++, Python, Scala and OCaml

Tristan Hume, writing about a university project Teams of up to 3 people, multi month, write a Java to x86 compiler in language of choice Needed to pass both known and unknown tests. Secret tests to be run after submission encouraged teams to add more testing than provided. Nothing but standard libraries, and no parsing libraries, even if in standard. Lines of code Rust baseline Haskell: 1-1.6x C++: 1.4x Rust (another team): 3x Scala: 0.7 x OCaml: 1-1.6x Python: about half the size Python version one person used metaprogramming more extra features than any other team passed all public and secret tests

Michael #2 : Pylustrator is a program to style your matplotlib plots

via Len Wanger Pylustrator is a program to style your matplotlib plots for publication. Subplots can be resized and dragged around by the mouse, text and annotations can be added. Changes can be saved to the initial plot file as python code.

Brian #3: MongoDB 4.2

Distributed Transactions extends multi-document ACID transactions across documents, collections, dbs in a replica set, and sharded cluster. Field Level Encryption encryption done on client side satisfies GDPR by allowing customer key destruction rendering server data on customer useless. system administration can be done with no exposure to private data

Michael #4: Deep Difference and search of any Python object/data

via François Leblanc DeepDiff: Deep Difference of dictionaries, iterables, strings and other objects. It will recursively look for all the changes. Lots of nice touches: List difference ignoring order or duplicates Report repetitions Exclude certain types from comparison Exclude part of your object tree from comparison Significant Digits DeepSearch: Search for objects within other objects. DeepHash: Hash of ANY python object based on its contents even if the object is not considered hashable! DeepHash is supposed to be deterministic in order to make sure 2 objects that contain the same data, produce the same hash.

Brian #5: Advanced Python Testing

Josh Peak “This article is mostly for me to process my thoughts but also to pave a path for anyone that wants to follow a similar journey on some more advanced python testing topics.” Learning journey (including some great podcasts and an awesome book on testing) Testing tools basic test structure adding black to testing with pytest-black linting with pylint including a very cool speed up trick to only lint modified files. flake8, including docstring checking tox.ini modifications code coverage goals and how to ratchet up to that goal with --cov-fail-under cool learning: “Increase code coverage by testing more code OR deleting code.” fixtures for database connections utilizing mocks, spies, stubs, and monkey patches, including pytest-mock pytest-vcr to save network interactions and replay them in future test runs, resulting in a 10x speedup. Lots of links and tangents possible from this article.

Michael #6: Understanding Python's del

via Kevin Buchs Official docs General confusion of what this does Looks like memory management, and it mostly isn’t Primary use: remove an item from a list given its index instead of its value or from a dictionary given its key: del person['profession'] # person is a dict del statement can also be used to remove slices from a list del lst[2:4] del can also be used to delete entire variables: del variable Recently covered how The CPython Bytecode Compiler is Dumb. Proactive dels could help.



Pynsource: Reverse engineer Python source code into UML diagrams (via Anders Klint) Language Bar chart race (via Josh Thurston) My Local maximum appearance.


Optimist: The glass is half full. Pessimist: The glass is half empty. Programmer: The glass is twice as large as necessary.

Pragmatist: allowing room for requirements oversights, scope creep, and schedule overrun.

From “The Upside” with Kevin Hart and Bryan Cranston (watched it last night): K: Would you invest in [HTML_REMOVED]? B: That seems too niche. K: What’s “niche” mean? B: It’s the girl version of “nephew”.

#136 A Python kernel rather than cleaning the batteries?

Jun 25, 2019 00:30:27


Brought to you by Datadog: pythonbytes.fm/datadog

Brian #1: Voilà!

“from Jupyter notebooks to standalone applications and dashboards” Turn a notebook into a web app with: custom widgets runnable code (but not editable) interactive plots different custom grid layouts templates

Michael #2: Toward a “Kernel Python”

By Glyph Glyph wants to Marie Kondō the standard library (and I think I agree with him) We have PEP 594 for removing obviously obsolete and unmaintained detritus from the standard library. PEP 594 is great news for Python, and in particular for the maintainers of its standard library, who can now address a reduced surface area. Believes the PEP may be approaching the problem from the wrong direction. One “dead” battery is the colorsys module: why not remove it? “The module is useful to convert CSS colors between coordinate systems. Today, however, the modules you need to convert colors between coordinate systems are only a pip install away. Every little bit is overhead for the core devs, consider the state of PRs Looking at CPython’s keyword-based review queue, we can see that there are 429 tickets currently awaiting review. The oldest PR awaiting review hasn’t been touched since February 2, 2018, which is almost 500 days old. By Glyph’s subjective assessment, on this page of 25 PRs, 14 were about the standard library, 10 were about the core language or interpreter code We need a “kernel” version of Python that contains only the most absolutely minimal library, so that all implementations can agree on a core baseline that gives you a “python” Michael: There will be a cost to beginners. But there is already.

Brian #3: Use __main__.py

I didn’t know it was that easy to get python -m [HTML_REMOVED] to work.

Michael #4: The CPython Bytecode Compiler is Dumb

by Chris Wellons Given multiple ways to express the same algorithm or idea, Chris tends to prefer the one that compiles to the more efficient bytecode. Fortunately CPython, the main and most widely used implementation of Python, is very transparent about its bytecode. It’s easy to inspect and reason about its bytecode. The disassembly listing is easy to read and understand. One fact has become quite apparent: the CPython bytecode compiler is pretty dumb. With a few exceptions, it’s a very literal translation of a Python program, and there is almost no optimization. Darius Bacon points out that Guido van Rossum himself said, “Python is about having the simplest, dumbest compiler imaginable.” So this is all very much by design. The consensus seems to be that if you want or need better performance, use something other than Python. (And if you can’t do that, at least use PyPy.) ← Cython people, Cython. Example def foo(): x = 0 y = 1 return x

Could easily be:

def foo(): return 0

Yet, CPython completely misses this optimization for both x and y:

2 0 LOAD_CONST 1 (0) 2 STORE_FAST 0 (x) 3 4 LOAD_CONST 2 (1) 6 STORE_FAST 1 (y) 4 8 LOAD_FAST 0 (x) 10 RETURN_VALUE

And so on.

Brett Cannot has expressed performance as a major focus for CPython, maybe there is something here?

Brian #5: You can play with EdgeDB now, maybe

A Path to a 10x Database EdgeDB roadmap Alpha 1 is available. “EdgeDB is the next generation relational database based on PostgreSQL. It features a novel data model and an advanced query language.” I’m excited about what their doing. Looking forward to 1.0. Lots of great features listed in the 10x post, but what I’m most intrigued by is their replacement of SQL with a different query language.

Michael #6: 16 Python libraries that helped a healthcare startup grow

via Waqas Younas Worked with a U.S.-based healthcare startup for 7 years. This startup developed a software product that sent appointment reminders to the patients of healthcare facilities; the reminders were sent via email, text, and IVR. Paramiko - A Python implementation of SSHv2. built-in CSV module SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper Requests - HTTP for Humans™ BeautifulSoup - Python library for pulling data out of HTML and XML files. testscenarios - a pyunit extension for dependency injection HL7 - a simple library for parsing messages of Health Level 7 (HL7) version 2.x into Python objects. Python-Phonenumbers - Library for parsing, formatting, and validating international phone numbers gevent - a coroutine -based Python networking library that uses greenlet to provide a high-level synchronous API on top of the libev or libuv event loop. dateutil - powerful extensions to datetime (pip install python-dateutil) Matplotlib - a Python 2D plotting library which produces publication quality figures python-magic - a python interface to the libmagic file type identification library. libmagic identifies file types by checking their headers according to a predefined list of file types. Django - a high-level Python Web framework that encourages rapid development and clean, pragmatic design Boto - a Python package that provides interfaces to Amazon Web Services. Mailgun Python bindings - helped us send appointment reminders seamlessly Twilio’s Python bindings - helped us send appointment reminders seamlessly



United States Digital Service


Difference between ML & AI? Ans.

#135 macOS deprecates Python 2, will stop shipping it (eventually)

Jun 20, 2019 00:32:24


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Special guest Max Sklar

Brian #1: Why do Python lists let you += a tuple, when you can’t + a tuple?

Reuven Lerner >>> x = [1, 2, 3] >>> b = (4, 5, 6) >>> x + b Traceback (most recent call last): File "[HTML_REMOVED]", line 1, in [HTML_REMOVED] TypeError: can only concatenate list (not "tuple") to list >>> x += b >>> x [1, 2, 3, 4, 5, 6] Huh?? “It turns out that the implementation of list.__iadd__ (in place add) takes the second (right-hand side) argument and adds it, one element at a time, to the list. It does this internally, so that you don’t need to execute any assignment after. The second argument to “+=” must be iterable.”

Max #2: R vs Python, R is out of top 20 languages despite statistical boom

Subtitle: is R declining because of Python? First of all, this article is about an index on the popularity of programming languages from an organization TIOBE. They have an index on the popularity of programming languages. Obviously it’s a combination of many different scores, and that could be controversial, but I’m going to assume that they put some thought into how the rankings are calculated, and that it’s as good as any. A few stories here: first Python hit at all time high in their ranking at number 3, beating out c++ I believe for the first time, and only Java and C are above it. The other story is that the statistical language R dipped below 20 to number 21, and the speculation is that Python has sort of taken over as the preferred statistical language to R. Personally, I got into Python much sooner, because I started as a software engineer, and moved into data science and machine learning. So after taking CS, and programming in Java and C for a few years, python came much more naturally. But still - a lot of people who are data-science first (and they have an additional skills to the kind of hybrid that I am) like and prefer R, and they can use it in a specialized way and get good results. Personally, I’m going to stick with python, because there’s so many statistical libraries yet to learn, and it’s served me well thus far. The language I’ve used most in recent years, Scala, is surprisingly down at 31 - not even close! related: https://www.zdnet.com/article/programming-languages-python-predicted-to-overtake-c-and-java-in-next-4-years/

Michael #3: macOS deprecates Python 2, will stop shipping it (eventually)

via Dan Bader, on the heels of WWDC 2019 “Future versions of macOS won’t include scripting language runtimes by default” Contrast this with Windows just now starting to ship with Python 3 In the same announcement: “Use of Python 2.7 isn’t recommended as this version is included in macOS for compatibility with legacy software. Future versions of macOS won’t include Python 2.7. Instead, it’s recommended that you run python3 from within Terminal. (51097165)” Also has impact wider than “us”. E.g. No Ruby or Perl, means home brew doesn’t install easily which is how we get Python 3!

Brian #4: Pythonic Ways to Use Dictionaries

Al Sweigart A few pythonic uses of dictionaries that are not obvious to new people. Use get() and setdefault() with Dictionaries get(key, default=[HTML_REMOVED]) allows you to read a key without checking for it’s existence beforehand. setdefault(key, default=[HTML_REMOVED]) is a bit of a strange duck but still useful. Set the value of something if it doesn’t exist yet. Python Uses Dictionaries Instead of a Switch Statement Just do it a few times to get the hang of it. Then it becomes natural. Michael's switch addition for Python: https://github.com/mikeckennedy/python-switch

Max #5: Things you are probably not using in Python 3 But Should

This is from Datawhatnow.com This is particularly relevant for me, since I used python legacy at Foursquare for many years, and now coming back to it taking another look at python v3. One that looks very useful is f-Strings where you can put the variable name in braces in a string and just have it replaced. I’ve seen things like this in other languages - notably PHP and most front-end scripts. Makes the code very readable. Except I know I’m going to screw up by leaving out that stray “f” in front of the string. It should almost be automatic, because how often are you putting these variable names in braces? Another thing I didn’t know python 3 had - again I’m kind of just get started with python 3 is enumerations. I’ve been using Enums for years in scala (really case classes) to make my code WAY more readable. Will keep that in mind when developing in python 3.

Michael #6: Have a time machine? C++ would get the Python 2 → 3 treatment too

via James Small In a recent CppCast interview, Herb Sutter describes how he would change C/C++ types if he could go back in time. This is almost exactly how things were changed from Python 2 to Python 3 (str split into Unicode strings and byte arrays) So my question to you two is: Why was the transition so hard? Was it just habit and stubbornness? What could the PSF have done?



pip install mystery by Divo Kaplan A random Python package every time. Mystery is a Python package that is instantiated as a different package every time you install it! Inspired by one of our episodes Get our effective pycharm book bundle with the courses over at effectivepycharm.com


Python 3.8.0b1 If you support a package, please test.


The Local Maximum Weekly Podcast that covers both the theoretical issues in probability theory, philosophy, and machine learning, but then applies it in a practical way to things like current events and product development. For example, a few weeks ago I did a show on how to estimate the probably of an event that has never occurred We also cover things like Apple’s decision to breakup iTunes, how the internet is shaping up in places like Cuba, and the controversy around YouTube’s recommendation algorithm.


MK: There are only two hard problems in Computer Science: cache invalidation, naming things and off-by-one-errors.

#134 Python proves Mercury is the closest planet to Earth

Jun 12, 2019 00:21:10


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Brian #1: Three scientists publish a paper proving that Mercury, not Venus, is the closest planet to Earth. using Python

contributed by, and explained by, listener Andrew Diederich.

“This is from the March 19th, 2019 Strange Maps article. Which planet is, on average, closest to the Earth? Answer: Mercury. Actually, Mercury is, on average, the closest to all other planets, because it’s closest to the sun.”

article, including video, uses PyEphem, which apparently is now deprecated and largely replaced with skyfield.

Michael #2: Github semantics

Parsing, analyzing, and comparing source code across many languages Written in a Haskell, it’s a library and command line tool for parsing, analyzing, and comparing source code. It’s still early days yet, but semantic can do a lot of cool things, and is powering public-facing GitHub features. I’m tremendously excited as to see how it’ll evolve now that it’s a community-facing project. Understands: Python, TypeScript, JavaScript, Ruby, Go, … here are some cool things inside it: A flow-sensitive, caching, generalized interpreter for imperative languages An abstract interpreter that generates scope graphs for a given program text A strategic rewriting system based on recursion schemes for open syntax terms

Brian #3: flake8-black

Contributed by Nathan Clayton “The point of this plugin is to be able to run black --check ... from within the flake8 plugin ecosystem.” I like to run flake8 during development both to keep things neat, and to train myself to just write code in a more standard way. This is a way to run black with no surprises.

Michael #4: Python Preview for VS Code

You write Python code (script style mostly), it creates an object-visualization Think of a picture your first year C++ CS prof might draw. This extension does that automatically as you write Python code Looks to be based (conceptually) on Philip Guo’s Python Tutor site.

Brian #5: Create and Publish a Python Package with Poetry

John Franey Walks through creating a package, customizing the pyproject.toml, and talks about the different settings in the toml and what it means. Then using the testpypi, and finally publish.

Michael #6: Pointers in Python: What's the Point?

by Logan Jones Quick question: Does Python have pointers (outside of C-extensions, etc of course)? Yet Python is more pointer heavy than most languages (more so than C# more so than even C++)! In Python, everything is an object, even numbers and booleans. Each object contains at least three pieces of data: Reference count Type Value Check that you have the same object is instead of == Python variables are pointers, just safe ones. Interesting little tidbit from the article: Interning strings is useful to gain a little performance on dictionary lookup—if the keys in a dictionary are interned, and the lookup key is interned, the key comparisons (after hashing) can be done by a pointer compare instead of a string compare. (Source) But like we have inline-assembly in C++ and unsafe mode in C#, we can use pointers in Cython or more fine-grained with ctypes.



PSF needs your help. Spread the word about the fundraiser and please, ask your company to contribute: Building the PSF: the Q2 2019 Fundraiser (Donations are tax-deductible for individuals and organizations that pay taxes in the United States) “Contributions help fund workshops, conferences, pay meetup fees, support fiscal sponsorships, PyCon financial aid, and development sprints. ”


via Jay Miller

What did the developer name his newborn boy? JSON

#133 Github sponsors - The model open source has been waiting for?

Jun 5, 2019 00:27:29


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Brian #1: Python built-ins worth learning

Trey Hunner “I estimate most Python developers will only ever need about 30 built-in functions, but which 30 depends on what you’re actually doing with Python.” “I recommend triaging your knowledge: Things I should memorize such that I know them well Things I should know about so I can look them up more effectively later Things I shouldn’t bother with at all until/unless I need them one day” all 69 built-in functions, split into commonly known overlooked by beginners learn it later maybe learn it eventually you likely don’t need these Highlighting some: overlooked by beginners sum, enumerate, zip, bool, reversed, sorted, min, max, any, all know it’s there, but learn it later: open, input, repr, super, property, issubclass, isinstance, hasattr, getattr, setattr, delattr, classmethod, staticmethod, next my notes I think getattr should be learned early on, because it’s default behavior is so useful. But can’t use it for dicts. Use mydict.get(key, default) for dictionaries.

Michael #2: Github sponsors and match

Like Patreon but for GitHub projects 2x your sponsorship: Github matches! To boost community funding, we'll match contributions up to $5,000 during a developer’s first year in GitHub Sponsors with the GitHub Sponsors Matching Fund. 100% to developers, Zero fees: GitHub will not charge fees for GitHub Sponsors. Anyone who contributes to open source—whether through code, documentation, leadership, mentorship, design, or beyond—is eligible for sponsorship.

Brian #3: Build a REST API in 30 minutes with Django REST Framework

Bennett Garner Very fast intro including: Set up Django Create a model in the database that the Django ORM will manage Set up the Django REST Framework Serialize the model from step 2 Create the URI endpoints to view the serialized data Example is a simple hero db with hero name and alias.

Michael #4: Dependabot has been acquired by GitHub

Automated dependency updates: Dependabot creates pull requests to keep your dependencies secure and up-to-date. I personally use and recommend PyUP: https://pyup.io/ How it works: Dependabot checks for updates: Dependabot pulls down your dependency files and looks for any outdated or insecure requirements. Dependabot opens pull requests: If any of your dependencies are out-of-date, Dependabot opens individual pull requests to update each one. You review and merge: You check that your tests pass, scan the included changelog and release notes, then hit merge with confidence. Here's what you need to know: We're integrating Dependabot directly into GitHub, starting with security fix PRs 👮‍♂️ You can still install Dependabot from the GitHub Marketplace whilst we integrate it into GitHub, but it's now free of charge 🎁 We've doubled the size of Dependabot's team; expect lots of great improvements over the coming months 👩‍💻👨‍💻👩‍💻👨‍💻👩‍💻👨‍💻 Paid accounts are now free, automatically.

Brian #5: spoof “New features planned for Python 4.0

Charles Leifer - also known for Peewee ORM This is funny, but painful. Is it too soon to joke about the pain of 2 to 3? A few of my favorites PEP8 will be updated. Line lengths will be increased to 89.5 characters. (compromise between 79 and 100) All new libraries and standard lib modules must include the phrase "for humans" somewhere in their title. Type-hinting has been extended to provide even fewer tangible benefits and will be called type whispering. You can make stuff go faster by adding async before every other keyword. Notable items left out of 4.0 Still no switch statement. No improvements to packaging.

Michael #6: BlackSheep web framework

Fast HTTP Server/Client microframework for Python asyncio, using Cython, uvloop, and httptools. Very Flask-like API. Interesting to consider the “popularity” of Flask vs Django in this context. Objectives Clean architecture and source code, following SOLID principles Intelligible and easy to learn API, similar to those of many Python web frameworks Keep the core package minimal and focused, as much as possible, on features defined in HTTP and HTML standards Targeting stateless applications to be deployed in the cloud High performance, see results from TechEmpower benchmarks (links in Wiki page) Also has an async client much like aiohttp.



Free courses in the Training mobile apps Upcoming webcast: 10 Tools and Techniques Python Web Developers Should Explore 2019 PSF Board Elections Get PyCharm, Support Python Until June 1st, get PyCharm at 30% OFF All the money raised will go toward the Python Software Foundation


How do you generate a random string? Put a first year Computer Science student in Vim and ask them to save and exit. Waiter: He's choking! Is anyone a doctor? Programmer: I'm a Vim user.

#132 Algorithms as objects

May 30, 2019 0:30:19


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Brian #1: History of CircuitPython

PSF blog, A. Jesse Jiryu Davis Adafruit hired Scott Shawcroft to port MicroPython to their SAMD21 chip they use on many of their boards. CircuitPython is a friendly fork of MicroPython. Same licensing, and they share improvements back and forth. “MicroPython customizes its hardware APIs for each chip family to provide speed and flexibility for hardware experts. Adafruit’s audience, however, is first-time coders. Shawcroft said, “Our goal is to focus on the first five minutes someone has ever coded.” “ “Shawcroft aims to remove all roadblocks for beginners to be productive with CircuitPython. As he demonstrated, CircuitPython auto-reloads and runs code when the user saves it; there are two more user experience improvements in the latest release. First, serial output is shown on a connected display, so a program like print("hello world") will have visible output even before the coder learns how to control LEDs or other observable effects.” Related: CircuitPython 4.0.0 released

Michael #2: R Risks Python Swallowing It Whole: TIOBE

Is the R programming language in serious trouble? According to the latest update of the TIOBE Index, the answer seems to be “yes.” R has finally tumbled out of the top 20 languages “It seems that there is a consolidation going on in the statistical programming market. Python has become the big winner.” Briefly speculates why is Python (which ranked fourth on this month’s list) winning big in data science? My thought: Python is a full spectrum language with solid numerical support.

Brian#3: The Missing Introduction To Containerization

Aymen El Amri Understanding containerization through history chroot jail, 1979, allowed isolation of a root process and it’s children from the rest of the OS, but with no security restrictions. FreeBSD Jail, 2000, more secure, also isolating the file system. Linux VServer, 2001, added “security contextes” and used new OS system-level virtualization. Allows you to run multiple Linux distros on a single VPS. Oracle Solaris Containers, 2004, system resource controls and boundary separation provided by “zone”. OpenVZ, 2005, OS-level virtualization. Used by many hosting companies to isolate and sell VPSs. Google’s CGroups, 2007, a mechanizm to limit and isolate resource usage. Was mainlained into Linux kernel the same year. LXC, Linux Containers, 2008, Similar to OpenVX, but uses CGroups. CloudFoundry’s Warden, 2013, an API to manage environments. Docker, 2013, os-level virtualization Google’s LMCTFY (Let me contain that for you), 2014, an OSS version of Google’s container stack, providing Linux application containers. Most of this tech is being incorporated into libcontainer. “Everything at Google runs on containers. There are more than 2 billion containers running on Google infrastructure every week.” CoreOS’s rkt, 2014, an alternative to Docker. Lots of terms defined VPS, Virtual Machine, System VM, Process VM, … OS Containers vs App Containers

Docker is both a Container and a Platform

This is halfway through the article, and where I got lost in an example on creating a container sort of from scratch. I think I’ll skip to a Docker tutorial now, but really appreciate the back story and mental model of containers.

Michael #4: Algorithms as objects

We usually think of an algorithm as a single function with inputs and outputs. Our algorithms textbooks reinforce this notion. They present very concise descriptions that neatly fit in half of a page. Little details add up until you’re left with a gigantic, monolithic function monolithic function lacks readability the function also lacks maintainability Nobody wants to touch this code because it’s such a pain to get any context Complex code requires abstractions How to tell if your algorithm is an object Code smell #1. It’s too long or too deeply nested Code smell #2. Banner comments Code smell #3. Helper functions as nested closures, but it’s still too long Code smell #4. There are actual helper functions, but they shouldn’t be called by anyone else Code smell #5. You’re passing state between your helper functions Write your algorithm as an object Refactoring a monolithic algorithm into a class improves readability, which is is our #1 goal. Lots of concrete examples in the article

Brian #5: pico-pytest

Oliver Bestwalter Super tiny implementation of pytest core. 25 lines My original hand crafted test framework was way more code than that, and not as readable. This is good to look at to understand the heart of what test frameworks do find test code run it mark any exceptions as failures Of course, the bells and whistles added in the full implementation are super important, but this is the heart of what is happening.

Michael #6: An Introduction to Cython, the Secret Python Extension with Superpowers

Cython is one of the best kept secrets of Python. It extends Python in a direction that addresses many of the shortcomings of the language and the platform, such as execution speed, GIL-free concurrency, absence of type checking and not creating an executable. Number of widely used packages that are written in it, such as spaCy, uvloop, and significant parts of scikit-learn, Numpy and Pandas. Cython makes use of the architectural organization of Python by translating (or 'transpiling', as it is now called) a Python file into the C equivalent of what the Python runtime would be doing, and compiling this into machine code. Can sometimes avoid Python types altogether (e.g. sqrt function) C arrays versus lists: Python collection types (list, dict, tuple and set) can be used as a type in cdef functions. The problem with the list structure, however, is that it leads to Python runtime interaction, and is accordingly slow Nice article for getting started and motivation. But I didn’t see Python type annotations in play (they are now supported)



The Price of the Hallway Track - Hynek It’s lame to speak to an empty room, so go to some talks, and lean toward less known speakers. Definitely on my todo list for next year. Who put Python in the Windows 10 May 2019 Update? - Steve Dower more back story


Little development board to production via Crowd Supply: The TinyPICO is an ESP32-based board that's, well, tiny ;) but packs a pretty significant punch...and it's been designed from day 1 to have first-class MicroPython support! via matt_trentini PyCon 2019 Reflections by Automation Panda Python Bytes (yeah, us!) has a Patreon page. Upcoming webcast: 10 Tools and Techniques Python Web Developers Should Explore


What do you call eight hobbits? A hobbyte. Two bytes meet. The first byte asks, 'Are you ill?' The second byte replies, 'No, just feeling a bit off.’ OR: What is Benoit B. Mandelbrot's middle name? Benoit B. Mandelbrot.

#131 Python 3 has issues (over on GitHub)

May 21, 2019 00:27:15


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Brian #1: PEP 581 (Using GitHub issues for CPython) is accepted

PEP 581 The email announcing the acceptance. “The migration will be a large effort, with much planning, development, and testing, and we welcome volunteers who wish to help make it a reality. I look forward to your contributions on PEP 588 and the actual work of migrating issues to GitHub.” — Barry Warsaw

Michael #2: Replace Nested Conditional with Guard Clauses

Deeply nested code is problematic (does it have deodorant — err comments?) But what can you do? Guard clauses! See Martin Fowler’s article and this one. # BAD! def checkout(user): shipping, express = [], [] if user is not None: for item in user.cart: if item.is_available: shipping.append(item) if item.express_selected: express.append(item) return shipping, express # BETTER! def checkout(user): shipping, express = [], [] if user is None: return shipping, express for item in user.cart: if not item.is_available: continue shipping.append(item) if item.express_selected: express.append(item) return shipping, express

Brian #3: Things you’re probably not using in Python 3 – but should

Vinko Kodžoman Some of course items: f-strings Pathlib (side note. pytest tmp_path fixture creates temporary directories and files with PathLib) data classes Some I’m warming to: type hinting And those I’m really glad for the reminder of: enumerations from enum import Enum, auto class Monster(Enum): ZOMBIE = auto() WARRIOR = auto() BEAR = auto() print(Monster.ZOMBIE) # Monster.ZOMBIE built in lru_cache: easy memoization with the functools.lru_cache decorator. @lru_cache(maxsize=512) def fib_memoization(number: int) -> int: ... extended iterable unpacking >>> head, *body, tail = range(5) >>> print(head, body, tail) 0 [1, 2, 3] 4 >>> py, filename, *cmds = "python3.7 script.py -n 5 -l 15".split() >>> cmds ['-n', '5', '-l', '15'] >>> first, _, third, *_ = range(10) >>> first, third (0, 2)

Michael #4: The Python Arcade Library

Arcade is an easy-to-learn Python library for creating 2D video games. It is ideal for people learning to program, or developers that want to code a 2D game without learning a complex framework. Minesweeper games, hangman, platformer games in general. Check out Sample Games Made With The Arcade Library too Includes physics and other goodies Based on OpenGL

Brian #5: Teaching a kid to code with Pygame Zero

Matt Layman Scratch too far removed from coding. Using Mu to simplify coding interface. comes with a built in Python. Pygame Zero preinstalled “[Pygame Zero] is intended for use in education, so that teachers can teach basic programming without needing to explain the Pygame API or write an event loop.” Initial 29 line game taught: naming things and variables mutability and fiddling with “constants” to see the effect functions and side effects state and time interactions and mouse events Article also includes some tips on how to behave as the adult when working with kids and coding.

Michael #6: Follow up on GIL / PEP 554

Has the Python GIL been slain? by Anthony Shaw multithreading in CPython is easy, but it’s not truly concurrent, and multiprocessing is concurrent but has a significant overhead. Because Interpreter state contains the memory allocation arena, a collection of all pointers to Python objects (local and global), sub-interpreters in PEP 554 cannot access the global variables of other interpreters. the way to share objects between interpreters would be to serialize them and use a form of IPC (network, disk or shared memory). All options are fairly inefficient But: PEP 574 proposes a new pickle protocol (v5) which has support for allowing memory buffers to be handled separately from the rest of the pickle stream. When? Pickle v5 and shared memory for multiprocessing will likely be Python 3.8 (October 2019) and sub-interpreters will be between 3.8 and 3.9.



PyCon 2019 videos are available So grateful for this. Already watched a couple, including Ant’s awesome talk about complexity and wily. pytest and hypothesis show up in the new Pragmatic Programmer book.


100 Days of Web course is out! Effective PyCharm book New release of our Android and iOS apps.


MK → Waiter: Would you like coffee or tea? Programmer: Yes.

#130 Python.exe now shipping with Windows 10

May 14, 2019 00:24:07


Sponsored by Datadog: pythonbytes.fm/datadog

Folks this one is light on notes since we did it live. Enjoy the show!

Special guests

Emily Morehouse Steve Dower


Brian #1: pgcli Michael #2: Papermill Emily #3: Python Language Summit Steve #4: Python in Windows 10

#129 Maintaining a Python Project when it’s not your job

May 6, 2019 00:16:40


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Brian #1: Maintaining a Python Project when it’s not your job

Paul #2: Python in 1994


Barry #3 Python leadership in 2019

Michael #4: Textblob


#128 Will the GIL be obsolete with PEP 554?

May 2, 2019 00:23:01


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Brian #1: Solving Algorithmic Problems in Python with pytest

Adam Johnson How to utilize pytest to set up quick test cases for coding challenges, like Project Euler or Advent of Code. Moving the specification and examples in the challenge description into test cases. Running the tests with a stub implementation and understanding the failure output. Gradually building up a working solution. Nice demo of how little code it takes to write quick test cases. Also a cool idea to use challenge sites and platforms as TDD/test first practice, as well as practice converting specifications into test cases.

Michael #2: DepHell -- project management for Python

via @dreigelb Why it is better than all other tools: Format agnostic. You can use DepHell with your favorite format: setup.py, requirements.txt, Pipfile, poetry. DepHell supports them all and much more. Use your favorite tool on any project. Want to install a poetry based project, but don't like poetry? Just say DepHell to convert project meta information into setup.py and install it with pip. Or directly work with the project from DepHell, because DepHell can do everything what you usually want to do with packages. DepHell doesn't try to replace your favorite tools. If you use poetry, you have to use poetry's file formats and commands. However, DepHell can be combined with any other tool or even combine all these tools together through formats converting. You can use DepHell, poetry and pip at the same time. Easily extendable. Pipfile should be just another one supported format for pip. However, pip is really old and big project with many bad decisions, so, PyPA team can't just add new features in pip without fear to broke everything. This is how pipenv has been created, but pipenv has inherited almost all problems of pip and isn't extendable too. DepHell has strong modularity and can be easily extended by new formats and commands. Developers friendly. We aren't going to place all our modules into [_internal](https://github.com/pypa/pip/tree/master/src/pip/_internal). Also, DepHell has big ecosystem with separated libraries to help you use some DepHell's parts without pain and big dependencies for your project. All-in-one-solution. DepHell can manage dependencies, virtual environments, tests, CLI tools, packages, generate configs, show licenses for dependencies, make security audit, get downloads statistic from pypi, search packages and much more. None of your tools can do it all. Smart dependency resolution. Sometimes pip and pipenv can't lock your dependencies. Try to execute pipenv install oslo.utils==1.4.0. Pipenv can't handle it, but DepHell can: dephell deps add --from=Pipfile oslo.utils==1.4.0 to add new dependency and dephell deps convert --from=Pipfile --to=Pipfile.lock to lock it. Asyncio based. DepHell doesn't support Python 2.7, and that allows us to use modern features to make network and filesystem requests as fast as possible. Multiple environments. You can have as many environments for project as you want. Separate sphinx dependencies from your main and dev environment. Other tools like pipenv and poetry don't support it.

Brian #3 Python rant: from foo import is bad

Mike Croucher I’m glad to see this post because I’m still seeing this practice a lot, even in tutorial blog posts! This is meaningless: result = sqrt(-1) Is it: math.sqrt(-1)? or numpy.sqrt(-1) or cmath.sqrt(-1)? or scipy? or sympy? Recommendation: Never do from x import * Use import math or import numpy as np or even from scipy import sqrt

Michael #4: Dask

Dask natively scales Python Have numpy, pandas, and scikit-learn code that needs to go faster? Run these on smart clusters of servers Or just on your laptop Process more data than will fit into RAM Supported by… interesting to see proper support there. Matthew Rocklin was on Talk Python 207 to discuss

Brian #5: Animations with Matplotlib

Parul Pandey The raindrop simulation is mesmerizing. Tutorial on using FuncAnimation to animate a sine wave although, I’m not sure what the x axis means during an animation Also: live updates based on changing data animate turning a 3D plot using celluloid package to animate simple example animating subplots changing legend during animation

Michael #6: PEP 554 -- Multiple Interpreters in the Stdlib

This proposal introduces the stdlib interpreters module. The module will be provisional. It exposes the basic functionality of subinterpreters already provided by the C-API, along with new (basic) functionality for sharing data between interpreters. Sharing data centers around "channels", which are similar to queues and pipes. Examples and use-cases: Running isolated code In process, true parallelism Versioning of modules (?) Plugin systems



iOS Talk Python Training app is out: training.talkpython.fm/apps Find us at PyCon! Blessings terminal API (from Erik Rose, via Prayson Daniel)


via Topher Chung

Knock knock. Race condition. Who's there?

#127 That Python code is on fire!

Apr 25, 2019 00:24:55


Sponsored by Datadog: pythonbytes.fm/datadog

Special guest: Kenneth Reitz

Brian #1: inline_python (for rust)

“I just made a Frankenstein's monster: Python code embedded directly in rustlang code. Should I kill it before it escapes the lab?” - Mara Bos Writing some rust, and need a little Python? Maybe want to pop open a matplotlib window? This may be just the thing you need. see also: https://pypi.org/project/bash/

Kenneth #2: Requests3: Under Way!

Requests 2.x that you know and love is going into CVE-only mode (which it has been for a long time). Requests III is a new project which will bring async/await keywords to Requests. installable as requests3. Type-Annotations Python 3.6+

Michael #3: 🔥 Pyflame: A Ptracing Profiler For Python

Pyflame is a high performance profiling tool that generates flame graphs for Python. Pyflame is implemented in C++, and uses the Linux ptrace(2) system call to collect profiling information. It can take snapshots of the Python call stack without explicit instrumentation Capable of profiling embedded Python interpreters like uWSGI. Fully supports profiling multi-threaded Python programs. Why use it? Pyflame usually introduces significantly less overhead than the builtin profile (or cProfile) modules, and emits richer profiling data. The profiling overhead is low enough that you can use it to profile live processes in production.

Brian #4: flit + src

Currently a WIP PR. flit is easy. Given a module or a source package. flit init creates pyproject.toml and LICENSE files. commit those to git flit build creates a wheel flit publish (builds and) publishes to whatever you have in your [.pypirc](https://docs.python.org/3/distutils/packageindex.html#the-pypirc-file) Changes in this PR The flit project already has 2 types of projects. just a module, like foo.py a package (directory with __init__.py), like foo/__init__.py This would add a 3rd and 4th. just a module, but in src, like src/foo.py a package in src, like src/foo/__init__.py May be cracking open a can of worms, but I’m ok with that.

Kenneth #5: $ pipx install pipenv

Michael #6: cheat.sh

via Jon Bultmeyer Nothing to install, but works on the CLI $ http cht.sh/python/sort+list $ http cht.sh/python/connect+to+database Has a CLI client too with a proper shell Get started with http cht.sh/python/:learn Has a funky stealth mode too Editor integration VS Code & Vim cheat.sh uses selected community driven cheat sheet repositories and information sources, maintained by thousands of users, developers and authors all over the world



vi is good for beginners - fun read, for all you haters out there. But use vim, not vi. Better yet, IdeaVim for PyCharm or VSCodeVim for VS Code. nbstripout - command line tool to strip output from Jupyter Notebook files. We covered pyodide on episode 93, but here’s a cool article on it Pyodide: Bringing the scientific Python stack to the browser


PyCon AU CFP LIGO Blackhole collision follow up: https://www.youtube.com/watch?v=BXID4teFfDc via Dave Kirby and Matthew Feickert https://github.com/kylebebak/questionnaire like Bullet but for windows too via Sander Teunissen

Kenneth (optional):

PyColorado CFP PyOhio CFP PyRemote!


Don’t know if I’ll do all of these, but I like them. 🙂 Brian and Kenneth, feel free to add yours if you have some!

MK: Ubuntu users are apt to get these jokes. MK: How many programmers does it take to kill a cockroach? Two: one holds, the other installs Windows on it. MK: A programmer had a problem. He thought to himself, 'I know, I'll solve it with threads!'. has Now problems. two he

(mildly offensive) KR: What’s the difference between a musician and a pizza? A pizza can feed a family of four.

(In collaboration with Jonatan Skogsfors) Python used to be directed by the BDFL, Guido. Now it’s directed by a steering council, GUIDs[0:4].

#126 WebAssembly comes to Python

Apr 19, 2019 00:30:10


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Special guest: Cecil Philip

Brian #1: Python Used to Take Photo of Black Hole

Lots of people talking about this. The link I’m including is a quick write up by Mike Driscoll. From now on these conversations can happen: “So, what can you do with Python?” “Well, it was used to help produce the worlds first image of a black hole. Your particular problem probably isn’t as complicated as that, so Python should work fine.” Projects listed in the paper: “First M87 Event Horizon Telescope Results. III. Data Processing and Calibration”: Numpy (van der Walt et al. 2011) Scipy (Jones et al. 2001) Pandas (McKinney 2010) Jupyter (Kluyver et al. 2016) Matplotlib (Hunter 2007). Astropy (The Astropy Collaboration et al. 2013, 2018)

Cecil #2: Wasmer - Python Library for executing WebAssembly binaries

WebAssembly (Wasm) enables high level languages to target a portable format that runs in the web Tons of languages compile down to Wasm but Wasmer enables the consumption of Wasm in python This enables an interesting use case for using Wasm as a way to leverage code between languages

Michael #3: Cooked Input

cooked_input is a Python package for getting, cleaning, converting, and validating command line input. Name comes from input / raw_input (unvalidated) and cooked input (validated) Beginner’s can use the provided convenience classes to get simple inputs from the user. More complicated command line application (CLI) input can take advantage of cooked_input’s ability to create commands, menus and data tables. All sorts of cool validates and cleaners Examples cap_cleaner = ci.CapitalizationCleaner(style=ci.ALL_WORDS_CAP_STYLE) ci.get_string(prompt="What is your name?", cleaners=[cap_cleaner]) >>> ci.get_int(prompt="How old are you?", minimum=1) How old are you?: abc "abc" cannot be converted to an integer number How old are you?: 0 "0" too low (min_val=1) How old are you?: 67 67

Brian #4: JetBrains and PyCharm officially collaborating with Anaconda

PyCharm 2019.1.1 has some improvements for using Conda environments. Fixed various bugs related to creating Conda envs and installing packages into them. Special distribution of PyCharm: PyCharm for Anaconda with enhanced Anaconda support. I’m using PyCharm Pro with vim emulation this week to edit a notebook based presentation. I might run them in Jupyter, or just run it in PyCharm, but editing with all my normal keyboard shortcuts is awesome.

Cecil #5: Building a Serverless IoT Solution with Python Azure Functions and SignalR

Interesting blog post on using serverless, IoT, real-time messaging to create a live dashboard Shows how to create a serverless function in Python to process IoT data There’s tons of DIY applications for using this technique at home The Dashboard is a static website using D3 for charting.

Michael #6: multiprocessing.shared_memory — Provides shared memory for direct access across processes

New in Python 3.8 This module provides a class, SharedMemory, for the allocation and management of shared memory to be accessed by one or more processes on a multicore or symmetric multiprocessor (SMP) machine. The ShareableList looks nice to use.



Getting ready for PyCon with STICKERS. Yeah, baby. Come see us at PyCon. I’ll also be bringing some copies of Python Testing with pytest, if anyone doesn’t already have a copy. Lots of interviews going on for Test & Code, and some will happen at PyCon.


Attendee Detector Workshop Talk Python training app on Android


Guido van Rossum interviewed on MIT’s AI podcast via Tony Cappellini Visual Studio IntelliCode for VS & VS Code Showing a Craigslist scammer who's boss using Python via Dan Koster


Brian: To understand recursion you must first understand recursion.

Michael: A programmer was found dead in the shower. Next to their body was a bottle of shampoo with the instructions 'Lather, Rinse and Repeat'.

#125 Will you conquer the deadlock empire?

Apr 13, 2019 00:31:46


Sponsored by Datadog: pythonbytes.fm/datadog

Brian #1: My How and Why: pyproject.toml & the 'src' Project Structure

Brian Skinn pyproject.toml but with setuptools, instead of flit or poetry with a src dir and tox and black all the bits and pieces to make all of this work

Michael #2: The Deadlock Empire: Slay dragons, master concurrency!

A game to test your thread safety and skill! Deadlocks occur in code when two threads end up trying to enter two or more locks (RLocks please!) Consider lock_a and lock_b Thread one enters lock_a and will soon enter lock_b Thread two enters lock_b and will soon enter lock_a Imagine transferring money between two accounts, each with a lock, and each thread does this in opposite order.

Brian #3: Cog 3.0

Ned Batchelder’s cog gets an update (last one was a few years ago). “Cog … finds snippets of Python in text files, executes them, and inserts the result back into the text. It’s good for adding a little bit of computational support into an otherwise static file.” Development moved from Bitbucket to GitHub. Travis and Appveyor CI. The biggest functional change is that errors during execution now get reasonable tracebacks that don’t require you to reverse-engineer how cog ran your code. mutmut mutation testing added. Cool. What I want to know more about is this statement: “…now I use it for making all my presentations”. Very cool idea.

Michael #4: StackOverflow 2019 Developer Survey Results

More good news for Python Lots of focus on gender in this one Contributing to Open Source About 65% of professional developers on Stack Overflow contribute to open source projects once a year or more. Involvement in open source varies with language. Developers who work with Rust, WebAssembly, and Elixir contribute to open source at the highest rates, while developers who work with VBA, C#, and SQL do so at about half those rates. Competence and Experience We see evidence here among the most junior developers for impostor syndrome, pervasive patterns of self-doubt, insecurity, and fear of being exposed as a fraud. Among our respondents, men grew more confident much more quickly than gender minorities. Programming, Scripting, and Markup Languages Python edges out Java, second only to JavaScript (and two non-programming languages) Databases MySQL, Postgres, Microsoft SQL Server, SQLite, MongoDB Most Loved, Dreaded, and Wanted Languages Loved: Rust, Python Wanted: Python, JavaScript Dreaded: VBA, ObjectiveC Most Loved, Dreaded, and Wanted Databases Loved: Postgres Wanted: MongoDB Most Popular Development Environments VS Code is crushing it How Technologies Are Connected is just interesting

Brian #5: Cuv’ner “A commanding view of your test-coverage"

Coverage visualizations on the console.

Michael #6: Mobile apps launched

The tech (sadly only 50% Python) Xamarin, Mono, and C# on the device-side Python, Pyramid, and MongoDB on the server-side 90% code sharing or higher Native applications Build the prototype myself on Windows Hired Giorgi via TopTal Get your own developer or get some freelancing work and support my app progress with my referral code: toptal.com/#we-annexed-perfect-engineers Dear mobile app developers: You have my sympathy! Try the app at training.talkpython.fm/apps Comes with 2 free courses for anyone who logs in. Android only at the moment but not for long



Python Bytes Patreon page is up: patreon.com/pythonbytes


PyCon Booth XKCD Plots in Matplotlib with examples via Tim Harrison Fira Code Retina and Font Ligatures The EuroSciPy 2019 Conference will take place from September 2 to September 6 in Bilbao, Spain


“When your hammer is C++, everything begins to look like a thumb.” “Why don't jokes work in octal? Because 7 10 11” Over explained: Why is 6 afraid of 7. Cuz 7 8 9. Follow on: Why did 7 eat 9? He was trying to eat 3^2 meals. I've been using Vim for a long time now, mainly because I can't figure out how to exit.

#124 This is not the None you're looking for

Apr 5, 2019 00:27:41


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Brian #1: pytest 4.4.0

Lots of amazing new features here (at least for testing nerds) testpaths displayed in output, if used. pytest.ini setting that allows you to specify a list of directories or tests (relative to test rootdir) to test. (can speed up test collection). Lots of goodies for plugin writers. Internal changes to allow subtests to work with a new plugin, pytest-subtests. Just started playing with it, but I’m excited already. Planning on a full Test & Code episode after I play with it a bit more. # unittest example: class T(unittest.TestCase): def test_foo(self): for i in range(5): with self.subTest("custom message", i=i): self.assertEqual(i % 2, 0) # pytest example: def test(subtests): for i in range(5): with subtests.test(msg="custom message", i=i): assert i % 2 == 0

Michael #2: requests-async

async-await support for requests Just finished talking with Kenneth Reitz, native async coming to requests, but awhile off Nice interm solution Requires modern Python (3.6) Interesting Flask, Quart, Starlette, etc. framework wrapper for testing

Brian #3: Reasons why PyPI should not be a service

Dustin Ingram’s article: PyPI as a Service “Layoffs at JavaScript package registry raise questions about fate of community resource” - The Register article Apparently PyPI gets requests for a private form of their service regularly, but there are problems with that. Currently a non-profit project under the PSF. That may be hard to maintain if they have a for-profit part. Donated services and infrastructure of more than $1M/year would be hard to replace. There are already other package repository options. Although there is probably room for others to compete. Currently run by volunteers for the most part. (<1 employee). Don’t think they would stick around to volunteer for a for-profit enterprise. conclusion: not impossible, but probably not worth it.

Michael #4: Jupyter in the cloud

Six easy ways to run your Jupyter Notebook in the cloud by Kevin Markham six services you can use to easily run your Jupyter notebook in the cloud. All of them have the following characteristics: They don't require you to install anything on your local machine. They are completely free (or they have a free plan). They give you access to the Jupyter Notebook environment (or a Jupyter-like environment). They allow you to import and export notebooks using the standard .ipynb file format. They support the Python language (and most support other languages as well). Binder is a service provided by the Binder Project, which is a member of the Project Jupyter open source ecosystem. It allows you to input the URL of any public Git repository, and it will open that repository within the native Jupyter Notebook interface. Kaggle is best known as a platform for data science competitions. However, they also provide a free service called Kernels that can be used independently of their competitions. Google Colaboratory, usually referred to as "Google Colab," is available to anyone with a Google account. As long as you are signed into Google, you can quickly get started by creating an empty notebook, uploading an existing notebook, or importing a notebook from any public GitHub repository. To get started with Azure Notebooks, you first sign in with a Microsoft or Outlook account (or create one). The next step is to create a "project", which is structured identically to a GitHub repository: it can contain one or more notebooks, Markdown files, datasets, and any other file you want to create or upload, and all of these can be organized into folders. CoCalc, short for "collaborative calculation", is an online workspace for computation in Python, R, Julia, and many other languages. It allows you to create and edit Jupyter Notebooks, Sage worksheets, and LaTeX documents. Datalore was created by JetBrains, the same company who makes PyCharm (a popular Python IDE). Getting started is as easy as creating an account, or logging in with a Google or JetBrains account. You can either create a new Datalore "workbook" or upload an existing Jupyter Notebook.

Brian #5: Jupyter Notebook tutorials

These are from Dataquest Jupyter Notebook for Beginners: A Tutorial Incredibly gentle, concise, useful tutorial to get started quickly. Installation, creating, and running with server and browser. Discussion of .ipynb files Overview of interface, cells, shortcuts, markdown. Kernels Starting with data. Importing appropriate libraries, loading data. Save and checkpoint looking at data, graphing/plotting data Sharing notebooks: exporting, using github and gists, nbviewer, Tutorial: Advanced Jupyter Notebooks shell commands basic magics autosaving matplotlib inline debugging in Jupyter (Brian: Gak! Maybe switch to PyCharm for debugging) using timeit rendering theml, latex, other languages in cells. logging, extensions charts with seaborn macros loading, importing and running external code and snippets. scripted execution, even on the command line parametrization with env variables styling, hiding cells, working with databases

Michael #6: Unique sentinel values, identity checks, and when to use object() instead of None

By Trey Hunner In Python (and in programming in general), you’ll need an object which can be uniquely identified. Sometimes this unique object represents a stop value or a skip value and sometimes it’s an initial value. Often this is None, but there are plenty of gotchas packed in there. Nice example of re-implementing min. Make sure to leverage is rather than == initial = object() # ... if minimum is not initial: return minimum # ...





Responder course AceJump for IntelliJ platforms (including PyCharm)


#123 Time to right the py-wrongs

Mar 29, 2019 00:25:31


Sponsored by Datadog: pythonbytes.fm/datadog

Brian #1: Deconstructing xkcd.com/1987/

Brett Cannon Breakdown of the infamous xkcd comic poking fun at the authors Python Environment on his computer. The interpreters listed Homebrew description python.org binaries A discussion of pip, easy_install The paths and the $PATH and $PYTHONPATH Actually quite an educational history lesson, and the abuse some people put their computers through. “So the next time someone decides to link to this comic as proof that Python has a problem, you can say that it's actually Randall's problem.” Michael #2: Python package as a CLI option

Wanted to make this little app available via a CLI as a dedicated command. Really tired of python3 script.py or ./script.py Turns out, pip and Python already solve this problem, if you structure your package correctly Thanks to everyone on Twitter! The trick turns out to be to have entrypoints in your package entry_points = { "console_scripts": ['bootstrap = bootstrap.bootstrap:main'] } ...

This should even register it with pipx install package ;)

Brian #3: pyright

a Microsoft static type checker for the Python language. “Pyright was created to address gaps in existing Python type checkers like mypy.” 5x faster than mypy meant for large code bases written in TypeScript and runs within node. Michael #4: Refactoring Python Applications for Simplicity

If you can write and maintain clean, simple Python code, then it’ll save you lots of time in the long term. You can spend less time testing, finding bugs, and making changes when your code is well laid out and simple to follow. Is your code complex? Metrics for Measuring Complexity Lines of Code Cyclomatic complexity is the measure of how many independent code paths there are through your application. Maintainability Index Refactoring: The technique of changing an application (either the code or the architecture) so that it behaves the same way on the outside, but internally has improved. Nice overview of tooling (PyCharm, VS Code plugins, etc) Anti-patterns and ways out of them (best part of the article IMO) Brian #5: FastAPI

Thanks Colin Sullivan for suggesting the topic “FastAPI framework, high performance, easy to learn, fast to code, ready for production” “Sales pitch / key features: Fast: Very high performance, on par with NodeJS and Go (thanks to Starlette and Pydantic). One of the fastest Python frameworks available. Fast to code: Increase the speed to develop features by about 200% to 300%. (estimated) Fewer bugs: Reduce about 40% of human (developer) induced errors. (estimated) Intuitive: Great editor support. Completion everywhere. Less time debugging. Easy: Designed to be easy to use and learn. Less time reading docs. Short: Minimize code duplication. Multiple features from each parameter declaration. Fewer bugs. Robust: Get production-ready code. With automatic interactive documentation. Standards-based: Based on (and fully compatible with) the open standards for APIs: OpenAPI(previously known as Swagger) and JSON Schema.” uses: Starlette for the web parts. Pydantic for the data parts. document REST apis with both Swagger ReDoc looks like quite a fun contender in the “put together a REST API quickly” set of solutions out there. Just the front page demo is quite informative. There’s also a tutorial that seems like it might be a crash course in API best practices. Michael #6: Bleach: stepping down as maintainer

by Will Kahn-Greene Bleach is a Python library for sanitizing and linkifying text from untrusted sources for safe usage in HTML. A retrospective on OSS project maintenance Picked up maintenance of the project because I was familiar with it current maintainer really wanted to step down Mozilla was using it on a bunch of sites I felt an obligation to make sure it didn't drop on the floor and I knew I could do it. Never really liked working on Bleach He did a bunch of work on a project I don't really use, but felt obligated to make sure it didn't fall on the floor, that has a pain-in-the-ass problem domain. Did that for 3+ years. Is [he] getting paid to work on it? Not really. Does [he] like working on it? No. Seems like [he] shouldn't be working on it anymore. Extras




Passbolt Python 3.7.3 is now available stackroboflow via Alexander Allori Joke

#122 Give Me Back My Monolith

Mar 22, 2019 00:29:06


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Brian #1: Combining and separating dictionaries

PEP 584 -- Add + and - operators to the built-in dict class. Steven D'Aprano Draft status, just created 1-March-2019 d1 + d2 would merge d2 into d1 like {**d1, **d2} or on two lines d = d1.copy() d.update(d2) of note, (d1 + d2) != (d2 + d1) Currently no subtraction equivalent Guido’s preference of + over | Related, Why operators are useful - also by Guido

Michael #2: Why I Avoid Slack

by Matthew Rocklin I avoid interacting on Slack, especially for technical conversations around open source software. Instead, I encourage colleagues to have technical and design conversations on GitHub, or some other system that is public, permanent, searchable, and cross-referenceable. Slack is fun but, internal real-time chat systems are, I think, bad for productivity generally, especially for public open source software maintenance. Prefer GitHub because I want to Engage collaborators that aren’t on our Slack Record the conversation in case participants change in the future. Serve the silent majority of users who search the web for answers to their questions or bugs. Encourage thoughtful discourse. Because GitHub is a permanent record it forces people to think more before they write. Cross reference issues. Slack is siloed. It doesn’t allow people to cross reference people or conversations across Slacks

Brian #3: Hunting for Memory Leaks in Python applications

Wai Chee Yau Conquering memory leaks and spikes in Python ML products at Zendesk. A quick tutorial of some useful memory tools The memory_profiler package and matplotlib to visualize memory spikes. Using muppy to heap dump at certain places in the code. objgraph to help memory profiling with object lineage. Some tips when memory leak/spike hunting: strive for quick feedback run memory intensive tasks in separate processes debugger can add references to objects watch out for packages that can be leaky pandas? really?

Michael #4: Give Me Back My Monolith

by Craig Kerstiens Feels like we’re starting to pass the peak of the hype cycle of microservices We’ve actually seen some migrations from micro-services back to a monolith. Here is a rundown of all the things that were simple that you now get to re-visit Setup went from intro chem to quantum mechanics Onboarding a new engineering, at least for an initial environment would be done in the first day. As we ventured into micro-services onboarding time skyrocketed So long for understanding our systems Back when we had monolithic apps if you had an error you had a clear stacktrace to see where it originated from and could jump right in and debug. Now we have a service that talks to another service, that queues something on a message bus, that another service processes, and then we have an error. If we can’t debug them, maybe we can test them All the trade-offs are for a good reason. Right?

Brian #5: Famous Laws Of Software Development

Tim Sommer 13 “laws” of software development, including Hofstadter’s Law: “It always takes longer than you expect, even when you take into account Hofstadter's Law.” Conway’s Law: “Any piece of software reflects the organizational structure that produced it.” The Peter Principle: “In a hierarchy, every employee tends to rise to his level of incompetence.” Ninety-ninety rule: “The first 90% of the code takes 10% of the time. The remaining 10% takes the other 90% of the time”

Michael #6: Beer Garden Plugins

A powerful plugin framework for converting your functions into composable, discoverable, production-ready services with minimal overhead. Beer Garden makes it easy to turn your functions into REST interfaces that are ready for production use, in a way that’s accessible to anyone that can write a function. Based on MongoDB, Rabbit MQ, & modern Python Nice docker-compose option too



Firefox Send Ethical ads on Python Bytes (and Talk Python)


T&C 69: The Pragmatic Programmer — Andy Hunt not up yet, but will be before this episode is released


From Derrick Chambers

“What do you call it when a python programmer refuses to implement custom objects? self deprivation! Sorry, that joke was really classless.”

via pyjokes: I had a problem so I thought I'd use Java. Now I have a ProblemFactory.

#121 python2 becomes self-aware, enters fifth stage of grief

Mar 16, 2019 00:23:34


Sponsored by Datadog: pythonbytes.fm/datadog

Brian #1: Futurize and Auto-Futurize

Staged automatic conversion from Python2 to Python3 with futurize from python-future.org pip install future Stages: 1: safe fixes: exception syntax, print function, object base class, iterator syntax, key checking in dictionaries, and more 2: Python 3 style code with wrappers for Python 2 more risky items to change separating text from bytes, quite a few more very modular and you can be more aggressive and more conservative with flags. Do that, but between each step, run tests, and only continue if they pass, with auto-futurize from Timothy Hopper. a shell script that uses git to save staged changes and tox to test the code.

Michael #2: Tech blog writing live stream

via Anthony Shaw Live stream on "technical blog writing" Talking about how I put articles together, research, timing and other things about layouts and narratives. Covers “Modifying the Python language in 6 minutes”, deep article Listicals, “5 Easy Coding Projects to Do with Kids” A little insight into what is popular. Question article: Why is Python Slow? Tourists guide to the CPython source code

Brian #3: Try out walrus operator in Python 3.8

Alexander Hultnér The walrus operator is the assignment expression that is coming in thanks to PEP 572. # From: https://www.python.org/dev/peps/pep-0572/#syntax-and-semantics # Handle a matched regex if (match := pattern.search(data)) is not None: # Do something with match # A loop that can't be trivially rewritten using 2-arg iter() while chunk := file.read(8192): process(chunk) # Reuse a value that's expensive to compute [y := f(x), y**2, y**3] # Share a subexpression between a comprehension filter clause and its output filtered_data = [y for x in data if (y := f(x)) is not None] This article walks through trying this out with the 3.8 alpha’s now available. Using pyenv and brew to install 3.8, but you can also just download it and try it out. 3.8.0a1: https://www.python.org/downloads/release/python-380a1/ 3.8.0a2: https://www.python.org/downloads/release/python-380a2/ Ends with a demonstration of the walrus operator working in a (I think) very likely use case, grabbing a value from a dict if the key exists for entry in sample_data: if title := entry.get("title"): print(f'Found title: "{title}"') That code won’t fail if the title key doesn’t exist.

Michael #4: bullet : Beautiful Python Prompts Made Simple

Have you ever wanted a dropdown select box for your CLI? Bullet! Lots of design options Also Password “boxes” Yes/No Numbers Looking for contributors, especially Windows support.

Brian #5: Hosting private pip packages using Azure Artifacts

Interesting idea to utilize artifacts as a private place to store built packages to pip install elsewhere. Walkthrough is assuming you are working with a data pipeline. You can package some of the work in earlier stages for use in later stages by packaging them and making them available as artifacts. Includes a basic tutorial on setuptools packaging and building an sdist and a wheel. Need to use CI in the Azure DevOps tool and use that to build the package and save the artifact Now in a later stage where you want to install the package, there are some configs needed to get the pip credentials right, included in the article. Very fun article/hack to beat Azure into a use model that maybe it wasn’t designed for.

Could be useful for non data pipeline usage, I’m sure.

Speaking of Azure, we brought up Anthony Shaw’s pytest-azurepipelines pytest plugin last week. Well, it is now part of the recommended Python template from Azure. Very cool.

Michael #6: Async/await for wxPython

via Andy Bulka Remember asyncio and PyQt from last week? Similar project called wxasync which does the same thing for wxPython! He’s written a medium article about it https://medium.com/@abulka/async-await-for-wxpython-c78c667e0872 with links to that project, and share some real life usage scenarios and fun demo apps. wxPython is important because it's free, even for commercial purposes (unlike PyQt). His article even contains a slightly controversial section entitled "Is async/await an anti-pattern?" which refers to the phenomenon of the async keyword potentially spreading through one's codebase, and some thoughts on how to mitigate that.


Michael: Mongo license followup

Will S. told me I was wrong! And I was. :) The main clarification I wanted to make above was that the AGPL has been around for a while, and it is the new SSPL from MongoDB that targets cloud providers. Also, one other point I didn't mention -- the reason the SSPL isn't considered open source is that it places additional conditions on providing the software as a service and the OSI's open source definition requires no discrimination based on field of endeavor.

Michael: python2 becomes self-aware, enters fifth stage of grief

Funny thread I started

python2 -m pip list DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.

Michael: PyDist — Simple Python Packaging

Your private and public dependencies, all in one place. Looks to be paid, but with free beta? It mirrors the public PyPI index, and keeps packages and releases that have been deleted from PyPI. It allows organizations to upload their own private dependencies, and seamlessly create private forks of public packages. And it integrates with standard Python tools almost as well as PyPI does.


A metajoke: pip install --user pyjokes or even better pipx install pyjokes. Then:

$ pyjoke

[hilarity ensues! …]

#120 AWS, MongoDB, and the Economic Realities of Open Source and more

Mar 5, 2019 00:25:25


Sponsored by pythonbytes.fm/digitalocean

Brian #1: The Ultimate Guide To Memorable Tech Talks

Nina Zakharenko 7 part series that covers choosing a topic, writing a talk proposal, tools, planning, writing, practicing, and delivering the talk I’ve just read the tools section, and am looking forward to the rest of the series. From the tools section: “I noticed I’d procrastinate on making the slides look good instead of focusing my time on making quality content.”

Michael #2: *Running Flask on Kubernetes*

via TestDriven.io & Michael Herman What is Kubernetes? A step-by-step tutorial that details how to deploy a Flask-based microservice (along with Postgres and Vue.js) to a Kubernetes cluster. Goals of tutorial Explain what container orchestration is and why you may need to use an orchestration tool Discuss the pros and cons of using Kubernetes over other orchestration tools like Docker Swarm and Elastic Container Service (ECS) Explain the following Kubernetes primitives - Node, Pod, Service, Label, Deployment, Ingress, and Volume Spin up a Python-based microservice locally with Docker Compose Configure a Kubernetes cluster to run locally with Minikube Set up a volume to hold Postgres data within a Kubernetes cluster Use Kubernetes Secrets to manage sensitive information Run Flask, Gunicorn, Postgres, and Vue on Kubernetes Expose Flask and Vue to external users via an Ingress

Brian #3: Changes in the CI landscape

Travis CI joins the Idera family - TravisCI blog #travisAlums on Twitter “TravisCI is laying off a bunch of senior engineers and other technical staff. Look at the #travisAlums hashtag and hire them!” - alicegoldfuss options: GitHub lists 17 options for CI, including GitLab & Azure Pipelines Some relevant articles, resources: The CI/CD market consolidation - GitLab article Azure Pipelines with Python — by example - Anthony Shaw pytest-azurepipelines - Anthony Shaw Azure Pipelines Templates - Anthony Sottile

Michael #4: Python server setup for macOS 🍎

what: hello world for Python server setup on macOS why: most guides show setup on a Linux server (which makes sense) but macoS is useful for learning and for local dev STEP 1: NGINX ➡️ STATIC ASSETS STEP 2: GUNICORN ➡️ FLASK STEP 3: NGINX ➡️ GUNICORN

Brian #5: Learn Enough Python to be Useful: argparse

How to Get Command Line Arguments Into Your Scripts - Jeff Hale “argparse is the “recommended command-line parsing module in the Python standard library.” It’s what you use to get command line arguments into your program. “I couldn’t find a good intro guide for argparse when I needed one, so I wrote this article.”

Michael #6: AWS, MongoDB, and the Economic Realities of Open Source

Related podcast: https://soundcloud.com/exponentfm/episode-159-inverted-pyramids

Last week, from the AWS blog:

Today we are launching Amazon DocumentDB (with MongoDB compatibility), a fast, scalable, and highly available document database that is designed to be compatible with your existing MongoDB applications and tools. Amazon DocumentDB uses a purpose-built SSD-based storage layer, with 6x replication across 3 separate Availability Zones. The storage layer is distributed, fault-tolerant, and self-healing, giving you the the performance, scalability, and availability needed to run production-scale MongoDB workloads.

Like an increasing number of such projects, MongoDB is open source…or it was anyways. MongoDB Inc., a venture-backed company that IPO’d in October, 2017, made its core database server product available under the GNU Affero General Public License (AGPL).

AGPL extended the GPL to apply to software accessed over a network; since the software is only being used, not copied MongoDB’s Business Model We believe we have a highly differentiated business model that combines the developer mindshare and adoption benefits of open source with the economic benefits of a proprietary software subscription business model. MongoDB enterprise and MongoDB atlas Basically, MongoDB sells three things on top of its open source database server: Additional tools for enterprise companies to implement MongoDB A hosted service for smaller companies to use MongoDB Legal certainty What AWS Sells the value of software is typically realized in three ways: First is hardware. Second is licenses. This was Microsoft’s core business for decades: licenses sold to OEMs (for the consumer market) or to companies directly (for the enterprise market). Third is software-as-a-service. AWS announced last week: > The storage layer is distributed, fault-tolerant, and self-healing, giving you the the performance, scalability, and availability needed to run production-scale MongoDB workloads. AWS is not selling MongoDB: what they are selling is “performance, scalability, and availability.” DocumentDB is just one particular area of many where those benefits are manifested on AWS. Thus we have arrived at a conundrum for open source companies: MongoDB leveraged open source to gain mindshare. MongoDB Inc. built a successful company selling additional tools for enterprises to run MongoDB. More and more enterprises don’t want to run their own software: they want to hire AWS (or Microsoft or Google) to run it for them, because they value performance, scalability, and availability. This leaves MongoDB Inc. not unlike the record companies after the advent of downloads: what they sold was not software but rather the tools that made that software usable, but those tools are increasingly obsolete as computing moves to the cloud. And now AWS is selling what enterprises really want. This tradeoff is inescapable, and it is fair to wonder if the golden age of VC-funded open source companies will start to fade (although not open source generally). The monetization model depends on the friction of on-premise software; once cloud computing is dominant, the economic model is much more challenging.


PyTexas 2019 at #Austin on Apr 13th and 14th. Registrations now open. More info at pytexas.org/2019/

Michael: Sorry Ant!

Michael: RustPython follow up: https://rustpython.github.io/demo/


Q: Why was the developer unhappy at their job?

A: They wanted arrays.

Q: Where did the parallel function wash its hands?

A: Async

#119 Assorted files as Django ORM backends with Alkali

Feb 26, 2019 00:22:13


Sponsored by pythonbytes.fm/datadog

Special guests

Eric Chou Dan Bader Trey Hunner Michael #1: Incrementally migrating over one million lines of code from Python 2 to Python 3

Weighing in at over 1 million lines of Python logic, we had a massive surface area for potential issues in our migration from Python 2 to Python 3 First Py3 commit, hack week 2015 Unfortunately, it was clear that many features were completely broken by the upgrade Official start H1 2017 Armed with Mypy, a static type-checking tool that we had adopted in the interim year, they made substantial strides towards enabling the Python 3 migration: Ported our custom fork of Python to version 3.5 Upgraded some Python dependencies to Python 3-compatible versions, and forked some others (e.g. babel) Modified some Dropbox client code to be Python 3 compatible Set up automated jobs in our continuous integration (CI) to run the existing unit tests with the Python 3 interpreter, and Mypy type-checking in Python 3 mode Crucially, the automated tests meant that we could be certain that the limited Python 3 compatibility that existed would not have regressed when the project was picked up again. Prerequisites Before we could begin working on migrating any of our application logic, we had to ensure that we could load the Python 3 interpreter and run until the entry point of the application. In the past, we had used “freezer” scripts to do this for us. However, none of these had support for Python 3 around this time, so in late 2016, we built a custom, more native solution which we internally referred to as “Anti-freeze” (more on that in the initial Python 3 migration blog post). Incrementally enabling unit tests and type-checking ‘Straddling’ Python 2 and Python 3 Letting it bake Learnings (tl;dr) Unit tests and typing are invaluable. String encoding in Python is hard. Incrementally migrate to Python 3 for great profit. Eric #2: Network Automation Development with Python (for fun and for profit)

Terms: NetDevOps (Cisco), NRE (Network Reliability Engineer) Libraires: Netmiko, NAPALM, Nornir Free Lab Resources: NRE Labs, dCloud, DevNet Conferences: AnsibleFest (network automation track), Cisco DevnetCreate Trey #3: Alkali file as DB

If you have structured data you want to query (like RSS feed, CSV, JSON, or any custom format of your own creation) you can use a Django ORM-like syntax to query it Save it to the same format or a different format because you control both the reading and the writing Kurt is at PyCascades so I got to chat with him about this Dan #4: Carnegie Mellon Launches Undergraduate Degree in Artificial Intelligence **

Carnegie Mellon University's School of Computer Science will offer a new undergraduate degree in artificial intelligence beginning this fall The first offered by a U.S. university "Specialists in artificial intelligence have never been more important, in shorter supply or in greater demand by employers," said Andrew Moore, dean of the School of Computer Science. The bachelor's degree in AI will focus more on how complex inputs — such as vision, language and huge databases — are used to make decisions or enhance human capabilities Michael #5: asyncio + PyQt5/PySide2

via Florian Dahlitz asyncqt is an implementation of the PEP 3156 event-loop with Qt. This package is a fork of quamash focusing on modern Python versions, with some extra utilities, examples and simplified CI. Allows wiring events to Qt’s event loop that run on asyncio and leverage it internally. Example: https://github.com/gmarull/asyncqt/blob/master/examples/aiohttp_fetch.py Dan #6: 4 things I want to see in Python 4.0

JIT as a first class feature A stable .0 release Static type hinting A GPU story for multiprocessing More community contributions Extras:

Michael: My Python Async webcast recording is now available. Michael: PyCon Israel in the first week of June (https://il.pycon.org/2019/), and the CFP opened today: https://cfp.pycon.org.il/conference/cfp Dan: Python Basics Book


Q: Why did the developer ground their kid? A: They weren't telling the truthy

#118 Better Python executable management with pipx

Feb 22, 2019 00:25:54


Sponsored by pythonbytes.fm/digitalocean

Brian #1: Frozen-Flask

“Frozen-Flask freezes a Flask application into a set of static files. The result can be hosted without any server-side software other than a traditional web server.” 2012 tutorial, Dead easy yet powerful static website generator with Flask Some of it is out of date, but it does point to the power of Frozen-Flask, as well as highlight a cool plugin, Flask-FlatPages, which allows pages from markdown.

#117 Is this the end of Python virtual environments?

Feb 14, 2019 00:28:20


Sponsored by pythonbytes.fm/datadog

Brian #1: Goodbye Virtual Environments?

by Chad Smith venv’s are great but they introduce some problems as well: Learning curve: explaining “virtual environments” to people who just want to jump in and code is not always easy Terminal isolation: Virtual Environments are activated and deactivated on a per-terminal basis Cognitive overhead: Setting up, remembering installation location, activating/deactivating PEP 582 — Python local packages directory This PEP proposes to add to Python a mechanism to automatically recognize a __pypackages__directory and prefer importing packages installed in this location over user or global site-packages. This will avoid the steps to create, activate or deactivate “virtual environments”. Python will use the __pypackages__ from the base directory of the script when present. Try it now with pythonloc pythonloc is a drop in replacement for python and pip that automatically recognizes a __pypackages__ directory and prefers importing packages installed in this location over user or global site-packages. If you are familiar with node, __pypackages__ works similarly to node_modules. Instead of running python you run pythonloc and the __pypackages__ path will automatically be searched first for packages. And instead of running pip you run piploc and it will install/uninstall from __pypackages__.

Michael #2: webassets

Bundles and minifies CSS & JS files Been doing a lot of work to rank higher on the sites That lead me to Google’s Lighthouse Despite 25ms response time to the network, Google thought my site was “kinda slow”, yikes! webassets has integration for the big three: Django, Flask, & Pyramid. But I prefer to just generate them and serve them off disk def build_asset(env: webassets.Environment, files: List[str], filters: str, output: str): bundle = webassets.Bundle( *files, filters=filters, output=output, env=env ) bundle.build(force=True)

Brian #3: Bernat on Python Packaging

3 part series by Bernat Gabor Maintainer of tox and virtualenv Python packages. The State of Python Packaging Python packaging - Past, Present, Future Python packaging - Growing Pains

Michael #4: What the mock? — A cheatsheet for mocking in Python

Nice introduction Some examples @mock.patch('work.os') def test_using_decorator(self, mocked_os): work_on() mocked_os.getcwd.assert_called_once()


def test_using_context_manager(self): with mock.patch('work.os') as mocked_os: work_on() mocked_os.getcwd.assert_called_once()

Brian #5: Transitions: The easiest way to improve your tech talk

By Saron Yitbarek Jeff Atwood of CodingHorror noted “The people who can write and communicate effectively are, all too often, the only people who get heard. They get to set the terms of the debate.” Effectively presenting is part of effective communication. I love the focus of this article. Focused on one little aspect of improving the performance of a tech talk.

Michael #6: Steering council announced

Our new leaders are Barry Warsaw Brett Cannon Carol Willing Guido van Rossum Nick Coghlan Via Joe Carey We both think it’s great Guido is on the council.


Brian: Got interviewed on IT Energizer Podcast: The one with Brian: https://itcareerenergizer.com/e123/ The one with Michael: https://itcareerenergizer.com/e83/ PyCon LATAM August 29, Puerto Vallarta, Mexico We should go. Anyone want to sponsor our travel/hotel to this event? CFP open till May 31, 2019, https://www.pylatam.org/en/speaking/


From the list from Ant, my votes.

Q: What's the second movie about a database engineer called? A: The SQL.

!false It's funny 'cause it's true.

A programmer's spouse tells them, "Run to the store and pick up a loaf of bread. If they have eggs, get a dozen." The programmer comes home with 12 loaves of bread.

#116 So you want Python in a 3D graphics engine?

Feb 6, 2019 00:17:56


Sponsored by pythonbytes.fm/digitalocean

Brian #1: Inside python dict — an explorable explanation

Interactive tutorial on dictionaries Searching efficiently in a list Why are hash tables called has tables? Putting it all together to make an “almost”-Python-dict How Python dict really works internally Yes this is a super deep dive, but wow it’s cool. Tons of the code is runnable right there in the web page, including moving visual representations, highlighted code with current line of code highlighted. Some examples allow you to edit values and play with stuff.

Michael #2: Embed Python in Unreal Engine 4

You may notice a theme throughout my set of picks on this episode Games built on Unreal Engine 4 include Fortnite: Save the World Gears of War 4 Marvel vs. Capcom: Infinite Moto Racer 4 System Shock (remake) Plugin embedding a whole Python VM in Unreal Engine 4 (both the editor and runtime). This means you can use the plugin to write other plugins, to automate tasks, to write unit tests and to implement gameplay elements. Here is an example usage. It’s a really nice overview and tutorial for the editor. For game elements, check out this section.

Brian #3: Redirecting stdout with contextlib

When I want to test the stdout output of some code, that’s easy, I grab the capsys fixture from pytest. But what if you want to grab the stdout of a method NOT while testing? Enter [contextlib.redirect_stdout(new_target)](https://docs.python.org/3/library/contextlib.html#contextlib.redirect_stdout) so cool. And very easy to read. ex: f = io.StringIO() with redirect_stdout(f): help(pow) s = f.getvalue() also a version for stderr

Michael #4: Panda3D

via Kolja Lubitz Panda3D is an open-source, completely free-to-use engine for realtime 3D games, visualizations, simulations, experiments Not just games, could be science as well! The full power of the graphics card is exposed through an easy-to-use API. Panda3D combines the speed of C++ with the ease of use of Python to give you a fast rate of development without sacrificing on performance. Features: Platform Portability Flexible Asset Handling: Panda3D includes command-line tools for processing and optimizing source assets, allowing you to automate and script your content production pipeline to fit your exact needs. Library Bindings: Panda3D comes with out-of-the-box support for many popular third-party libraries, such as the Bullet physics engine, Assimp model loader, OpenAL Performance Profiling: Panda3D includes pstats — an over-the-network profiling system designed to help you understand where every single millisecond of your frame time goes.

Brian #5: Why PyPI Doesn't Know Your Projects Dependencies

Some questions you may have asked: > How can I produce a dependency graph for Python packages? > Why doesn’t PyPI show a project’s dependencies on it’s project page? > How can I get a project’s dependencies without downloading the package? > Can I search PyPI and filter out projects that have a certain dependency? If everything is in requirements.txt, you just might be able to, but… setup.py is dynamic. You gotta run it to see what’s needed. Dependencies might be environment specific. Windows vs Linux vs Mac, as an example. Nothing stopping someone from putting random.choice() for dependencies in a setup.py file. But that would be kinda evil. But could be done. (Listener homework?) The wheel format is way more predictable because it limits some of this freedom. wheels don’t get run when they install, they really just get unpacked. More info on wheels: Kind of a tangent, but what why not: From: https://pythonwheels.com “Advantages of wheels Faster installation for pure Python and native C extension packages. Avoids arbitrary code execution for installation. (Avoids setup.py) Installation of a C extension does not require a compiler on Linux, Windows or macOS. Allows better caching for testing and continuous integration. Creates .pyc files as part of installation to ensure they match the Python interpreter used. More consistent installs across platforms and machines.”

Michael #6: PyGame series

via Matthew Ward Learn how to program in Python by building a simple dice game Build a game framework with Python using the PyGame module How to add a player to your Python game Using PyGame to move your game character around What's a hero without a villain? How to add one to your Python game Put platforms in a Python game with PyGame Also: Shout out to Mission Python book: Code a Space Adventure Game!


Joke (maybe, Brain feel free to pick another one):

via @realpython Why do Pythons live on land? They are above C-level!

#115 Dataclass CSV reader and Nina drops by

Feb 2, 2019 00:28:58


Sponsored by pythonbytes.fm/datadog

Special guest: Nina Zakharenko

Brian #1: Great Expectations

A set of tools intended for batch time testing of data pipeline data. Introduction to the problem doc: Down with Pipeline debt / Introducing Great Expectations expect_[something]() methods that return json formatted descriptions of whether or not the passed in data matches your expectations. Can be used programmatically or interactively in a notebook. (video demo). For programmatic use, I’m assuming you have to put code in place to stop a pipeline stage if expectations aren’t met, and write failing json result to a log or something. Examples, just a few, full list is big: Table shape: expect_column_to_exist, expect_table_row_count_to_equal Missing values, unique values, and types: - expect_column_values_to_be_unique, expect_column_values_to_not_be_null Sets and ranges expect_column_values_to_be_in_set String matching expect_column_values_to_match_regex Datetime and JSON parsing Aggregate functions expect_column_stdev_to_be_between Column pairs Distributional functions expect_column_chisquare_test_p_value_to_be_greater_than

Nina #2: Using CircuitPython and MicroPython to write Python for wearable electronics and embedded platforms

I’ve been playing with electronics projects as a hobby for the past two years, and a few months ago turned my attention to Python on microcontrollers MicroPython is a lean and efficient implementation of Python3 that can run on microcontrollers with just 256k of code space, and 16k of RAM. CircuitPython is a port of MicroPython, optimized for Adafruit devices. Some of the devices that run Python are as small as a quarter. My favorite Python hardware platform for beginners is Adafruit’s Circuit PlayGround Express. It has everything you need to get started with programming hardware without soldering. All you’ll need is alligator clips for the conductive pads. The board features NeoPixel LEDs, buttons, switches, temperature, motion, and sound sensors, a tiny speaker, and lots more. You can even use it to control servos, tiny motor arms. Best of all, it only costs $25. If you want to program the Circuit PlayGround Express with a drag-n-drop style scratch-like interface, you can use Microsoft’s MakeCode. It’s perfect for kids and you’ll find lots of examples on their site. Best of all, there are tons of guides for Python projects to build on their website, from making your own synthesizers, to jewelry, to silly little robots. Check out the repo for my Python-powered earrings, see a photo, or a demo. Sign up for the Adafruit Python for Microcontrollers mailing list here, or see the archives here.

Michael #3: Data class CSV reader

Map CSV to Data Classes You probably know about reading CSV files Maybe as tuples Better with csv.DictReader This library is similar but maps Python 3.7’s data classes to rows of CSV files Includes type conversions (say string to int) Automatic type conversion. DataclassReader supports str, int, float, complex and datetime DataclassReader use the type annotation to perform validation of the data of the CSV file. Helps you troubleshoot issues with the data in the CSV file. DataclassReader will show exactly in which line of the CSV file contain errors. Extract only the data you need. It will only parse the properties defined in the dataclass It uses dataclass features that let you define metadata properties so the data can be parsed exactly the way you want. Make the code cleaner. No more extra loops to convert data to the correct type, perform validation, set default values, the DataclassReader will do all this for you Default fallback values, more.

Brian #4: How to Rock Python Packaging with Poetry and Briefcase

Starts with a discussion of the packaging (for those readers that don’t listen to Python Bytes, I guess.) However, it also puts flit, pipenv, and poetry in context with each other, which is nice. Runs through a tutorial of how to build a pyproject.toml based project using poetry and briefcase. We’ve talked about Poetry before, on episode 100. pyproject.toml is discussed extensively on Test & Code 52. briefcase is new, though, it’s a project for creating standalone native applications for Mac, Windows, Linux, iOS, Android, and more. The tutorial also discusses using poetry directly to publish to the test-pypi server. This is a nice touch. Use the test-pypi before pushing to the real pypi. Very cool.

Nina #5: awesome-python-security *🕶🐍🔐, a collection of tools, techniques, and resources to make your Python more secure*

All of your production and client-facing code should be written with security in mind This list features a few resources I’ve heard of such as Anthony Shaw’s excellent 10 common security gotchas article which highlights problems like input injection and depending on assert statements in production, and a few that are new to me: OWASP (Open Web Application Security Project) Python Resources at pythonsecurity.org bandit a tool to find common security issues in Python bandit features a lot of useful plugins, that test for issues like: hardcoded password strings leaving flask debug on in production using exec() in your code & more detect-secrets, a tool to detect secrets left accidentally in a Python codebase & lots more like resources for learning about security concepts like cryptography See the full list for more

Michael #6: pydbg

Python implementation of the Rust dbg macro Best seen with an example. Rather than printing things you want to inspect, you: a = 2 b = 3 dbg(a+b) def square(x: int) -> int: return x * x dbg(square(a))


[testfile.py:4] a+b = 5 [testfile.py:9] square(a) = 4



pathlib + pytest tmpdir → tmp_path & tmp_path_factory https://docs.pytest.org/en/latest/tmpdir.html These two new fixtures (as of pytest 3.9) act like the good old tmpdir and tmpdir_factory, but return pathlib Path objects. Awesome.


The Art of Python is a miniature arts festival at PyCon North America 2019, focusing on narrative, performance, and visual art. We intend to encourage and showcase novel art that helps us share our emotionally charged experiences of programming (particularly in Python). We hope that by attending, our audience will discover new aspects of empathy and rapport, and find a different kind of delight and perspective than might otherwise be expected at a large conference. StackOverflow Survey is Open! https://stackoverflow.az1.qualtrics.com/jfe/form/SV_1RGiufc1FCJcL6B NumPy Is Awaiting Fix for Critical Remote Code Execution Bug via Doug Sheehan The issue was raised on January 16 and affects NumPy versions 1.10 (released in 2015) through 1.16, which is the latest release at the moment, released on January 14 The problem is with the 'pickle' module, which is used for transforming Python object structures into a format that can be stored on disk or in databases, or that allows delivery across a network. The issue was reported by security researcher Sherwel Nan, who says that if a Python application loads malicious data via the numpy.load function an attacker can obtain remote code execution on the machine. Get your google data All google docs in MS Office format via https://takeout.google.com/settings/takeout All Gmail in MBOX format from there as well Hint: Start with nothing selected ;)


I’m teaching a two day Intro and Intermediate Python course on March 19th and 20th. The class will live-stream for free here on each day of or join in-person from downtown Minneapolis. All of the course materials will be released for free as well. I recently recorded a series of videos with Carlton Gibson (Django maintainer) on developing Django Web Apps with VS Code, deploying them to Azure with a few clicks, setting up a Continuous Integration / Continuous Delivery pipeline, and creating serverless apps. Watch the series here: https://aka.ms/python-videos I’ll be a mentor at a brand new hatchery event at PyCon US 2019, mentored sprints for diverse beginners organized by Tania Allard. The goal is to help underrepresented folks at PyCon contribute to open source in a supportive environment. The details will be located here (currently a placeholder) when they’re finalized. Catch my talk about electronics projects in Python with LEDs at PyCascades in Seattle on February 24th. Currently tickets are still for sale. If you haven’t tried the Python extension for VS Code, now is a great time. The December release included some killer features, such as remote Jupyter support, and exporting Python files as Jupyter notebooks. Keep up with future releases at the Python at Microsoft blog.


Q: What do you call a snake that only eats desert? A: A pie-thon. (might not make sense read out loud) Q: How do you measure a python? A: In inches. They don't have any feet! Q: What is a python’s favorite subject? Hiss-tory!

#114 What should be in the Python standard library?

Jan 26, 2019 00:28:33


Sponsored by pythonbytes.fm/digitalocean

Brian #1: What should be in the Python standard library?

on lwn.net by Jake Edge There was a discussion recently about what should be in the standard library, triggered by a request to add LZ4 compression. Kinda hard to summarize but we’ll try: Jonathan Underwood proposed adding LZ4 compression to stdlib. Can of worms opened zlib and bz2 already in stdlib Brett proposed making something similar to hashlib for compression algorithms. Against adding it: lz4 not needed for stdlib, and actually, bz2 isn’t either, but it’s kinda late to remove. PyPI is easy enough. put stuff there. Led to a discussion of the role of stdlib. If it’s batteries included, shouldn’t we add new batteries Some people don’t have access to PyPI easily Do we never remove elements? really? Maybe we should have a lean stdlib and a thicker standard distribution of selected packages who would decide? same problem exists then of depending on it. How to remove stuff? Steve Dower would rather see a smaller standard library with some kind of "standard distribution" of PyPI modules that is curated by the core developers. A leaner stdlib could speed up Python version schedules and reduce burden on core devs to maintain seldom used packages. See? can of worms. In any case, all this would require a PEP, so we have to wait until we have a PEP process decided on.

Michael #2: Data Science portal for Home Assistant launched

via Paul Cutler Home Assistant is launching a data science portal to teach you how you can learn from your own smart home data. In 15 minutes you setup a local data science environment running reports. A core principle of Home Assistant is that a user has complete ownership of their personal data. A users data lives locally, typically on the SD card in their Raspberry Pi The Home Assistant Data Science website is your one-stop-shop for advice on getting started doing data science with your Home Assistant data. To accompany the website, we have created a brand new Hass.io Add-on JupyterLab lite, which allows you to run a data science IDE called JupyterLab directly on your Raspberry Pi hosting Home Assistant. You do your data analysis locally, your data never leaves your local machine. When you build something cool, you can share the notebook without the results, so people can run it at their homes too. We have also created a Python library called the HASS-Data-Detective which makes it super easy to get started investigating your Home Assistant data using modern data science tools such as Pandas. Check out the Getting Started notebook IoT aside: I finally found my first IoT project: Recording in progress button.

Brian #3: What's the future of the pandas library?

Kevin Markham over at dataschool.io pandas is gearing up to move towards a 1.0 release. Currently rc-ing 0.24 Plans are to get there “early 2019”. Some highlights method chaining - encouraged by core team to encourage further, more methods will support chaining Apache arrow likely to be part of pandas backend sometime after 1.0 Extension arrays - allow you to create custom data types deprications inplace parameter. It doesn’t work with chaining, doesn’t actually prevent copies, and causes codebase complexity ix accessor, use loc and iloc instead Panel data structure. Use MultiIndex instead SparseDataFrame. Just use a normal DataFrame legacy python support

Michael #4: PyOxidizer

PyOxidizer is a collection of Rust crates that facilitate building libraries and binaries containing Python interpreters. PyOxidizer is capable of producing a single file executable - with all dependencies statically linked and all resources (like .pyc files) embedded in the executable The Oxidizer part of the name comes from Rust: executables produced by PyOxidizer are compiled from Rust and Rust code is responsible for managing the embedded Python interpreter and all its operations. PyOxidizer is similar in nature to PyInstaller, Shiv, and other tools in this space. What generally sets PyOxidizer apart is Produced executables contain an embedded, statically-linked Python interpreter have no additional run-time dependency on the target system runs everything from memory (as opposed to e.g. extracting Python modules to a temporary directory and loading them from there).

Brian #5: Working With Files in Python

by Vuyisile Ndlovu on RealPython Very comprehensive write up on working with files and directories Includes legacy and modern methods. Pay attention to pathlib parts if you are using 3.4 plus Also great for “if you used to do x, here’s how to do it with pathlib”. Included: Directory listings getting file attributes creating directories file name pattern matching traversing directories doing stuff with the files in there creating temp directories and files deleting, copying, moving, renaming archiving with zip and tar including reading those looping over files

Michael #6: $ python == $ python3?

via David Furphy Homebrew tried this recently & got "persuaded" to reverse. Also in recent discussion of edits to PEP394, GvR said absolutely not now, probably not ever. Guido van Rossum RE: python doesn’t exist on macOS as a command: Did you mean python2 there? In my experience macOS comes with python installed (and invoking Python 2) but no python2 link (hard or soft). In any case I'm not sure how this strengthens your argument. I'm also still unhappy with any kind of endorsement of python pointing to python3. When a user gets bitten by this they should receive an apology from whoever changed that link, not a haughty "the PEP endorses this". Regardless of what macOS does I think I would be happier in a future where python doesn't exist and one always has to specify python2 or python3. Quite possibly there will be an age where Python 2, 3 and 4 all overlap, and EIBTI.


Michael: A letter to the Python community in Africa

via Anthony Shaw Believe the broader international Python and Software community can learn a lot from what so many amazing people are doing across Africa. e.g. The attendance of PyCon NA was 50% male and 50% female.

Joke: via Luke Russell: A: “Knock Knock” B: “Who’s There" A: ……………………………………………………………………………………….“Java”

Also: Java 4EVER video is amazing: youtube.com/watch?v=kLO1djacsfg

#113 Python Lands on the Windows 10 App Store

Jan 18, 2019 00:23:22


Sponsored by https://pythonbytes.fm/digitalocean

Brian #1: Advent of Code 2018 Solutions

Michael Fogleman Even if you didn’t have time or energy to do the 2018 AoC, you can learn from other peoples solutions. Here’s one set written up in a nice blog post.

Michael #2: Python Lands on the Windows 10 App Store

Python Software Foundation recently released Python 3.7 as an app on the official Windows 10 app store. Python 3.7 is now available to install from the Microsoft Store, meaning you no longer need to manually download and install the app from the official Python website. there is one limitation. “Because of restrictions on Microsoft Store apps, Python scripts may not have full write access to shared locations such as TEMP and the registry. Discussed with Steve Dower over on Talk Python 191

Brian #3: How I Built A Python Web Framework And Became An Open Source Maintainer

Florimond Manca Bocadillo - “A modern Python web framework filled with asynchronous salsa” ”maintaining an open source project is a marathon, not a sprint.” Tips at the end of the article include tips for the following topics, including recommendations and tool choices: Project definition Marketing & Communication Community Project management Code quality Documentation Versioning and releasing

Michael #4: Python maintainability score via Wily

via Anthony Shaw A Python application for tracking, reporting on timing and complexity in tests Easiest way to calculate it is with wily https://github.com/tonybaloney/wily … the metrics are ‘maintainability.mi’ and ‘maintainability.rank’ for a numeric and the A-F scale. Build an index: wily build src Inspect report: wily report file Graph: wily graph file metric

Brian #5: A couple fun awesome lists

Awesome Python Security resources Tools web framework hardening, ex: secure.py multi tools static code analysis, ex: bandit vulnerabilities and security advisories cryptography app templates Education lots of resources for learning Companies Awesome Flake8 Extensions clean code testing, including flake8-pytest - Enforces to use pytest-style assertions flake8-mock - Provides checking mock non-existent methods security documentation enhancements copyrights

Michael #6: fastlogging

via Robert Young A faster replacement of the standard logging module with a mostly compatible API. For a single log file it is ~5x faster and for rotating log file ~13x faster. It comes with the following features: (colored, if colorama is installed) logging to console logging to file (maximum file size with rotating/history feature can be configured) old log files can be compressed (the compression algorithm can be configured) count same successive messages within a 30s time frame and log only once the message with the counted value. log domains log to different files writing to log files is done in (per file) background threads, if configured configure callback function for custom detection of same successive log messages configure callback function for custom message formatter configure callback function for custom log writer


Michael: My webcast on async, Jan 24, 11am PT Michael: Watch your YAML!

Joke: >>> import antigravity

#112 Don't use the greater than sign in programming

Jan 11, 2019 00:28:47


Sponsored by https://pythonbytes.fm/datadog

Brian #1: nbgrader

nbgrader: A Tool for Creating and Grading Assignments in the Jupyter Notebook The Journal of Open Source Education, paper accepted 6-Jan-2019 nbgrader documentation, including a intro video From the JOSE article: “nbgrader is a flexible tool for creating and grading assignments in the Jupyter Notebook (Kluyver et al., 2016). nbgrader allows instructors to create a single, master copy of an assignment, including tests and canonical solutions. From the master copy, a student version is generated without the solutions, thus obviating the need to maintain two separate versions. nbgrader also automatically grades submitted assignments by executing the notebooks and storing the results of the tests in a database. After auto-grading, instructors can manually grade free responses and provide partial credit using the formgrader Jupyter Notebook extension. Finally, instructors can use nbgrader to leave personalized feedback for each student’s submission, including comments as well as detailed error information.” CS teaching methods have come a long ways since I was turning in floppies and code printouts. Michael #2: profanity-check

A fast, robust Python library to check for offensive language in strings. profanity-check uses a linear SVM model trained on 200k human-labeled samples of clean and profane text strings. Making profanity-check both robust and extremely performant Other libraries like profanity-filter use more sophisticated methods that are much more accurate but at the cost of performance. profanity-filter runs in 13,000ms vs 24ms for profanity-check in a benchmark Two ways to use: predict(text) → 0 or 1 (1 = bad) predict_prob(text) → [0, 1] confidence interval (1 = bad) Brian #3: An Introduction to Python Packages for Absolute Beginners

Ever tried to explain the difference between module and package? Between package-in-the-directory-with-init sense and package-you-can-distribute-and-install-with-pip sense? Here’s the article to read beforehand. Modules, packages, using packages, installing, importing, and more. And that’s not even getting into flit and poetry, etc. But it’s a good place to start for people new to Python. Michael #4: Python Dependencies and IoC

via Joscha Götzer Open-closed principle is at work with these and is super valuable to testing (one of the SOLID principles): Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification. There is a huge debate around why Python doesn’t need DI or Inversion of Control (IoC), and a quick stackoverflow search yields multiple results along the lines of “python is a scripting language and dynamic enough so that DI/IoC makes no sense”. However, especially in large projects it might reduce the cognitive load and decoupling of individual components Dependency Injector: I couldn’t get this one to work on windows, as it needs to compile some C libraries and some Visual Studio tooling was missing that I couldn’t really install properly. The library looks quite promising though, but sort of static with heavy usage of containers and not necessarily pythonic. Injector: The library that above mentioned article talks about, a little Java-esque pinject: Has been unmaintained for about 5 years, and only recently got new attention from some open source people who try to port it to python3. A product under Google copyright, and looks quite nice despite the lack of python3 bindings. Probably the most feature-rich of the listed libraries. python-inject: I discovered that one while writing this email, not really sure if it’s any good. Nice use of type annotations and testing features di-py: Only works up to python 3.4, so I’ve also never tried it (I’m one of those legacy python haters, I’m sure you can relate 😄). Serum: This one is a little too explicit to my mind. It makes heavy use of context managers (literally with Context(...): everywhere 😉) and I’m not immediately sure how to work with it. In this way, it is quite powerful though. Interesting use of class decorators. And now on to my favorite and a repeated recommendation of mine around the internet→ Haps: This lesser-known, lightweight library is sort of the new kid on the block, and really simple to use. As some of the other libraries, it uses type annotations to determine the kind of object it is supposed to instantiate, and automatically discovers the required files in your project folder. Haps is very pythonic and fits into apps of any size, helping to ensure modularization as the only dependency of your modules will be one of the types provided by the library. Pretty good example here. Brian #5: A Gentle Introduction to Pandas

Really a gentle introduction to the Pandas data structures Series and DataFrame. Very gentle, with console examples. Create series objects: from an array from an array, and change the indexing from a dictionaries from a scalar, cool. didn’t know you could do that Accessing elements in a series DataFrames sorting, slicing selecting by label, position statistics on columns importing and exporting data Michael #6: Don't use the greater than sign in programming

One simple thing that comes up time and time again is the use of the greater than sign as part of a conditional while programming. Removing it cleans up code. Let's say that I want to check that something is between 5 and 10. There are many ways I can do this x > 5 and 10 > x 5 < x and 10 > x x > 5 and x < 10 10 < x and x < 5 x < 10 and x > 5 x < 10 and 5 < x Sorry, one of those is incorrect. Go ahead and find out which one If you remove the use of the greater than sign then only 2 options remain x < 10 and 5 < x 5 < x and x < 10 The last is nice because x is literally between 5 and 10 There is also a nice way of expressing that "x is outside the limits of 5 and 10” x < 5 or 10 < x Again, this expresses it nicely because x is literally outside of 5 to 10. Interesting comment: What is cleaner or easier to read comes down to personal taste. But how to express "all numbers greater than 1" without '>'? ans: 1 < allNumbers Extras


Teaching Python podcast by Kelly Paredes & Sean Tibor Github private repos (now free) EuroPython 2019 announced South African AWS Data Center coming (via William H.) Pandas is dropping legacy Python support any day now

Joke: Harry Potter Parser Tongue via Nick Spirit

#111 loguru: Python logging made simple

Jan 5, 2019 00:34:16


Sponsored by https://pythonbytes.fm/datadog

Brian #1: loguru: Python logging made (stupidly) simple

Finally, a logging interface that is just slightly more syntax than print to do mostly the right thing, and all that fancy stuff like log rotation is easy to figure out. i.e. a logging API that fits in my brain. bonus: README is a nice tour of features with examples. Features: Ready to use out of the box without boilerplate No Handler, no Formatter, no Filter: one function to rule them all Easier file logging with rotation / retention / compression Modern string formatting using braces style Exceptions catching within threads or main Pretty logging with colors Asynchronous, Thread-safe, Multiprocess-safe Fully descriptive exceptions Structured logging as needed Lazy evaluation of expensive functions Customizable levels Better datetime handling Suitable for scripts and libraries Entirely compatible with standard logging Personalizable defaults through environment variables Convenient parser Exhaustive notifier

Michael #2: Python gets a new governance model

by Brett Canon July 2018, Guido steps down Python progress has basically been on hold since then ended up with 7 governance proposals Voting was open to all core developers as we couldn't come up with a reasonable criteria that we all agreed to as to what defined an "active" core dev And the winner is ... In the end PEP 8016, the steering council proposal, won. it was a decisive win against second place PEP 8016 is heavily modeled on the Django project's organization (to the point that the PEP had stuff copy-and-pasted from the original Django governance proposal). What it establishes is a steering council of five people who are to determine how to run the Python project. Short of not being able to influence how the council itself is elected (which includes how the electorate is selected), the council has absolute power. result of the vote prevents us from ever having the Python project be leaderless again, it doesn't directly solve how to guide the language's design. What's next? The next step is we elect the council. It's looking like nominations will be from Monday, January 07 to Sunday, January 20 and voting from Monday, January 21 to Sunday, February 03 A key point I hope people understand is that while we solved the issue of project management that stemmed from Guido's retirement, the council will need to be given some time to solve the other issue of how to manage the design of Python itself.

Brian #3: Why you should be using pathlib

Tour of pathlib from Trey Hunner pathlib combines most of the commonly used file and directory operations from os, os.path, and glob. uses objects instead of strings as of Python 3.6, many parts of stdlib support pathlib since pathlib.Path methods return Path objects, chaining is possible convert back to strings if you really need to for pre-3.6 code Examples: make a directory: Path('src/__pypackages__').mkdir(parents=True, exist_ok=True) rename a file: Path('.editorconfig').rename('src/.editorconfig') find some files: top_level_csv_files = Path.cwd().glob('*.csv') recursively: all_csv_files = Path.cwd().rglob('*.csv') read a file: Path('some/file').read_text() write to a file: Path('.editorconfig').write_text('# config goes here') with open(path, mode) as x works with Path objects as of 3.6

Michael #4: Altair and Altair Recipes

via Antonio Piccolboni (he wrote altair_recipes) Altair: Declarative statistical visualization library for Python Altair is developed by Jake Vanderplas and Brian Granger By statistical visualization they mean: The data source is a DataFrame that consists of columns of different data types (quantitative, ordinal, nominal and date/time). The DataFrame is in a tidy format where the rows correspond to samples and the columns correspond to the observed variables. The data is mapped to the visual properties (position, color, size, shape, faceting, etc.) using the group-by data transformation. Nice example that I can get behind # cars = some Pandas data frame alt.Chart(cars).mark_point().encode( x='Horsepower', y='Miles_per_Gallon', color='Origin', ) altair_recipes Altair allows generating a wide variety of statistical graphics in a concise language, but lacks, by design, pre-cooked and ready to eat statistical graphics, like the boxplot or the histogram. Examples: https://altair-recipes.readthedocs.io/en/latest/examples.html They take a few lines only in altair, but I think they deserve to be one-liners. altair_recipes provides that level on top of altair. The idea is not to provide a multitude of creative plots with fantasy names (the way seaborn does) but a solid collection of classics that everyone understands and cover most major use cases: the scatter plot, the boxplot, the histogram etc. Fully documented, highly consistent API (see next package), 90%+ test coverage, maintainability grade A, this is professional stuff if I may say so myself.

Brian #5: A couple fun pytest plugins

pytest-picked Using git status, this plugin allows you to: Run only tests from modified test files Run tests from modified test files first, followed by all unmodified tests Kinda hard to overstate the usefulness of this plugin to anyone developing or debugging a test. Very, very cool. pytest-clarity Colorized left/right comparisons Early in development, but already helpful. I recommend running it with -qq if you don’t normally run with -v/--verbose since it overrides the verbosity currently.

Michael #6: Secure 🔒 headers and cookies for Python web frameworks

Python package called Secure, which sets security headers and cookies (as a start) for Python web frameworks. I was listening to the Talk Python To Me episode “Flask goes 1.0” with Flask maintainer David Lord. At the end of the interview he was asked about notable PyPI packages and spoke about Flask-Talisman, a third-party package to set security headers in Flask. As a security professional, it was surprising and encouraging to hear the maintainer of the most popular Python web framework speak passionately about a security package. Had been recently experimenting with emerging Python web frameworks and realized there was a gap in security packages. That inspired Caleb to (humbly) see if it were possible to make a package to correct that and I started with Responder and then expanded to support more frameworks. The outcome was Secure with functions to support aiohttp, Bottle, CherryPy, Falcon, hug, Pyramid, Quart, Responder, Sanic, Starlette and Tornado (most of these, if not all have been featured on Talk Python) and can also be utilized by frameworks not officially supported. The goal is to be minimalistic, lightweight and be implemented in a way that does not disrupt an individual framework’s design. I have had some great feedback and suggestions from the developer and OWASP community, including some awesome discussions with the OWASP Secure Project and the Sanic core team. Added support for Flask and Django too. Secure Cookies is nice in the mix


Michael: SQLite bug impacts thousands of apps, including all Chromium-based browsers

See https://twitter.com/mborus/status/1080874700924964864 Since this bug is triggered by an SQL command, general CPython usage should not be affected, and long as you don’t run arbitrary SQL-commands provided by the outside. Seems to NOT be a problem in CPython: https://twitter.com/mborus/status/1080883549308362753

Michael: Follow up to our AI and healthcare conversation

via Bradley Hintze I found your discussion of deep learning in healthcare interesting, no doubt because that is my area. I am the data scientist for the National Oncology Program at the Veterans Health Administration. I work directly with clinicians and it is my strong opinion that AI cannot take the job from the MD. It will however make caring for patients much more efficient as AI takes care of the low hanging fruit, it you will. Healthcare, believe it or not, is a science and an art. This is why AI is never going to make doctors obsolete. It will, however, make doctors more efficient and demanded a more sophisticated doctor -- one that understands AI enough to not only trust it but, crucially, comprehend its limits.

Michael: Upgrade to Python 3.7.2

If you install via home brew, it’s time for brew update && brew upgrade

Michael: New course!

Introduction to Ansible

#110 Python Year in Review 2018 Edition

Dec 26, 2018 00:56:54


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

This episode originally aired on Talk Python at talkpython.fm/192.

It's been a fantastic year for Python. Literally, every year is better than the last with so much growth and excitement in the Python space. That's why I've asked two of my knowledgeable Python friends, Dan Bader and Brian Okken, to help pick the top 10 stories from the Python community for 2018.


Brian Okken @brianokken Dan Bader @dbader_org

10: Python 3.7:

Cool New Features in Python 3.7

9: Changes in versioning patterns

ZeroVer: 0-based Versioning Calendar Versioning Semantic Versioning 2.0.0

8: Python is becoming the world’s most popular coding language

Economist article

7: 2018 was the year data science Pythonistas == web dev Pythonistas

Python Developers Survey Results Covered in depth on Talk Python 176

6: Black

Project Soundgarden : “Black Hole Sun”

5: New PyPI launched!

Python Package Index

4: Rise of Python in the embedded world

Covered at Python Bytes

3: Legacy Python's days are fading?

Python 2.7 -- bugfix or security before EOL? Python 2 death clockhttps://pythonclock.org/

2: It's the end of innocence for PyPi

Twelve malicious Python libraries found and removed from PyPI

1: Guido stepped down as BDFL

python-committers: Transfer of power Proposals for new governance structure

#109 CPython byte code explorer

Dec 18, 2018 00:20:45


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Brian #1: Python Descriptors Are Magical Creatures

an excellent discussion of understanding @property and Python’s descriptor protocol. discussion includes getter, setter, and deleter methods you can override.

Michael #2: Data Science Survey 2018 JetBrains

JetBrains polled over 1,600 people involved in Data Science and based in the US, Europe, Japan, and China, in order to gain insight into how this industry sector is evolving Key Takeaways Most people assume that Python will remain the primary programming language in the field for the next 5 years. Python is currently the most popular language among data scientists. Data Science professionals tend to use Keras and Tableau, while amateur data scientists are more likely to prefer Microsoft Azure ML. Most common activities among pros and amateurs: Data processing Data visualization Main programming language for data analysis Python 57% R 15% Julia 0% IDEs and Editors Jupyter 43% PyCharm 38% RStudio 23% …

Brian #3: cache.py

cache.py is a one file python library that extends memoization across runs using a cache file. memoization is an incredibly useful technique that many self taught or on the job taught developers don’t know about, because it’s not obvious. example: import cache @cache.cache() def expensive_func(arg, kwarg=None): # Expensive stuff here return arg The @cache.cache() function can take multiple arguments. @cache.cache(timeout=20) - Only caches the function for 20 seconds. @cache.cache(fname="my_cache.pkl") - Saves cache to a custom filename (defaults to hidden file .cache.pkl) @cache.cache(key=cache.ARGS[KWARGS,NONE]) - Check against args, kwargs or neither of them when doing a cache lookup.

Michael #4: Setting up the data science tools

part of a larger video series set up. Tools to keras ultimately Tools anaconda tensorflow Jupyter Keras good for true beginners setup and activate a condo venv Start up a notebook and switch envs use conda, rather than pip

Brian #5: chartify

“Python library that makes it easy for data scientists to create charts.” from the docs: Consistent input data format: Spend less time transforming data to get your charts to work. All plotting functions use a consistent tidy input data format. Smart default styles: Create pretty charts with very little customization required. Simple API: We've attempted to make to the API as intuitive and easy to learn as possible. Flexibility: Chartify is built on top of Bokeh, so if you do need more control you can always fall back on Bokeh's API.

Michael #6: CPython byte code explorer

JupyterLab extension to inspect Python Bytecode via Anton Helm by Jeremy Tuloup You’ll see exactly what it’s about if you watch the GIF movie at the github repo. Can’t think of a better way to understand Python bytecode quickly than to play a little with this Comparing versions of CPython: If you have several versions of Python installed on your machine (let's say in different conda environments), you can use the extension to check how the bytecode might differ. Nice visualization of different performance aspects of while vs. for at the end



“How the Internet is made.”

#108 Spilled data? Call the PyJanitor

Dec 11, 2018 00:21:51


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Brian #1: pyjanitor - for cleaning data

originally a port of an R package called janitor, now much more. “pyjanitor’s etymology has a two-fold relationship to “cleanliness”. Firstly, it’s about extending Pandas with convenient data cleaning routines. Secondly, it’s about providing a cleaner, method-chaining, verb-based API for common pandas routines.” functionality: Cleaning columns name (multi-indexes are possible!) Removing empty rows and columns Identifying duplicate entries Encoding columns as categorical Splitting your data into features and targets (for machine learning) Adding, removing, and renaming columns Coalesce multiple columns into a single column Convert excel date (serial format) into a Python datetime format Expand a single column that has delimited, categorical values into dummy-encoded variables This pandas code: df = pd.DataFrame(...) # create a pandas DataFrame somehow. del df['column1'] # delete a column from the dataframe. df = df.dropna(subset=['column2', 'column3']) # drop rows that have empty values in column 2 and 3. df = df.rename({'column2': 'unicorns', 'column3': 'dragons'}) # rename column2 and column3 df['newcolumn'] = ['iterable', 'of', 'items'] # add a new column. - looks like this with pyjanitor: df = ( pd.DataFrame(...) .remove_columns(['column1']) .dropna(subset=['column2', 'column3']) .rename_column('column2', 'unicorns') .rename_column('column3', 'dragons') .add_column('newcolumn', ['iterable', 'of', 'items']) ) Michael #2: What Does It Take To Be An Expert At Python?

Presentation at PyData 2017 by James Powell Covers Python Data Model (dunder methods) Covers uses of Metaclasses All done very smoothly as a series of demos Pretty long and in depth, 1.5+ hours Brian #3: Awesome Python Applications

pypi is a great place to find great packages you can use as examples for the packages you write. Where do you go for application examples? Well, now you can go to Awesome Python Applications. categories of applications included: internet, audio, video, graphics, games, productivity, organization, communication, education, science, CMS, ERP (enterprise resource planning), static site generators, and a whole slew of developer related applications. Mahmoud is happy to have help filling this out, so if you know of a great open source application written in Python, go ahead and contribute to this, or open an issue on this project. Michael #4: Django Core no more

Write up by James Bennett If you’re not the sort of person who closely follows the internals of Django’s development, you might not know there’s a draft proposal to drastically change the project’s governance. What’s up: Django the open-source project is OK right now, but difficulty in recruiting and retaining enough active contributors. Some of the biggest open-source projects dodge this by having, effectively, corporate sponsorship of contributions. Django has become sort of a victim of its own success: the types of easy bugfixes and small features that often are the path to growing new committers have mostly been done already in Django. Not managed to bring in new committers at a sufficient rate to replace those who’ve become less active or even entirely inactive, and that’s not sustainable for much longer. Under-attracting women contributors too Governance: Some parallels to what the Python core devs are experiencing now. Project leads BDFLs stepped down. The proposal: what I’ve proposed is the dissolution of “Django core”, and the revocation of almost all commit bits Seems extreme but they were working much more as a team with PRs, etc anyway. Breaks down the barrier to needing to be on the core team to suggest, change anything. Two roles would be formalized — Mergers and Releasers — who would, respectively, merge pull requests into Django, and package/publish releases. But rather than being all-powerful decision-makers, these would be bureaucratic roles Brian #5: wemake django template

a cookie-cutter template for serious django projects with lots of fun goodies “This project is used to scaffold a django project structure. Just like django-admin.py startproject but better.” features: Always up-to-date with the help of [@dependabot](https://dependabot.com/) poetry for managing dependencies mypy for optional static typing pytest for unit testing flake8 and wemake-python-styleguide for linting pre-commit hooks for consistent development docker for development, testing, and production sphinx for documentation Gitlab CI with full build, test, and deploy pipeline configured by default Caddy with https and http/2 turned on by default Michael #6: Django Hunter

Tool designed to help identify incorrectly configured Django applications that are exposing sensitive information. Why? March 2018: 28,165 thousand django servers are exposed on the internet, many are showing secret API keys, database passwords, amazon AWS keys. Example: https://twitter.com/6IX7ine/status/978598496658960384 Some complained this inferred Django was insecure and said it wasn’t. Others thought “There is a reasonable argument to be made that DEBUG should default to False.” One beginner, Peter, chimes in: I probably have one of them, among my early projects that are on heroku and public GitHub repos. I did accidentally expose my aws password this way and all hell broke loose. The problem is that as a beginner, it wasn't obvious to me how to separate development and production settings and keep production stuff out of my public repository. Extras:

Michael: Thanks for having me on your show Brian: https://blog.michaelckennedy.net/2018/12/08/being-a-great-podcast-guest/

Brian: open source extra: For Christmas, I want a dragon…

pic.twitter.com/RmFAEgqpSr — Changelog (@changelog)

Michael: Why did the multithreaded chicken cross the road?

road the side get to the other of to to get the side to road the of other the side of to the to road other get to of the road to side other the get

#107 Restructuring and searching data, the Python way

Dec 7, 2018 00:22:50


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Brian #1: glom: restructuring data, the Python way

glom is a new approach to working with data in Python, featuring: Path-based access for nested structure data\['a'\]['b']['c'] → glom(data, 'a.b.c') Declarative data transformation using lightweight, Pythonic specifications glom(target, spec, **kwargs) with options such as a default value if value not found allowed exceptions Readable, meaningful error messages: PathAccessError: could not access 'c', part 2 of Path('a', 'b', 'c') is better than TypeError: 'NoneType' object is not subscriptable Built-in data exploration and debugging features glom.Inspect(``**a*``, ***kw*``) The [**Inspect**](https://glom.readthedocs.io/en/latest/api.html#glom.Inspect) specifier type provides a way to get visibility into glom’s evaluation of a specification, enabling debugging of those tricky problems that may arise with unexpected data.

Michael #2: Scientific GUI apps with TraitsUI

via Franklin Ventura They support: PyQt, wxPython, PySide, PyQt5 People should be aware of and when combined with Chaco (again from Enthought) the graphing and controlling capabilities really are amazing. Tutorial: Writing a graphical application for scientific programming using TraitsUI 6.0 Really simple UI / API for mapping object(s) to GUIs and back.

Brian #3: Pampy: The Pattern Matching for Python you always dreamed of

“Pampy is pretty small (150 lines), reasonably fast, and often makes your code more readable and hence easier to reason about.” uses _ as the missing info in a pattern

simple match signature of match(input, pattern, action)


nested lists and tuples from pampy import match, _ x = [1, [2, 3], 4] match(x, [1, [_, 3], _], lambda a, b: [1, [a, 3], b]) # => [1, [2, 3], 4] - dicts: pet = { 'type': 'dog', 'details': { 'age': 3 } } match(pet, { 'details': { 'age': _ } }, lambda age: age) # => 3 match(pet, { _ : { 'age': _ } }, lambda a, b: (a, b)) # => ('details', 3)

Michael #4: Google AI better than doctors at detecting breast cancer

Google’s deep learning AI called LYNA able to correctly identify tumorous regions in lymph nodes 99 per cent of the time. We think of the impact of AI as killing 'low end' jobs [see poster], but these are "doctor" level positions. The presence or absence of these ‘nodal metastases’ influence a patient’s prognosis and treatment plan, so accurate and fast detection is important. In a second trial, six pathologists completed a diagnostic test with and without LYNA’s assistance. With LYNA’s help, the doctors found it ‘easier’ to detect small metastases, and on average the task took half as long.

Brian #5: 2018 Advent of Code

Another winter break activity people might enjoy is practicing with code challenges. AoC is a fun tradition.

a calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved in any programming language you like. don't need a computer science background to participate don’t need a fancy computer; every problem has a solution that completes in at most 15 seconds on ten-year-old hardware. There’s a leaderboard, so you can compete if you want. Or just have fun. Past years available, back to 2015. Some extra tools and info: awesome-advent-of-code

Michael #6: Red Hat Linux 8.0 Beta released, now (finally) updated to use Python 3.6 as default instead of 2.7

First of all, my favorite comment was a correction to the title: legacy python * “Python 3.6 is the default Python implementation in RHEL 8; limited support for Python 2.7 is provided. No version of Python is installed by default.“ Red Hat Enterprise Linux 8 is distributed with Python 3.6. The package is not installed by default. To install Python 3.6, use the yum install python3 command. Python 2.7 is available in the python2 package. However, Python 2 will have a shorter life cycle and its aim is to facilitate smoother transition to Python 3 for customers. Neither the default python package nor the unversioned /usr/bin/python executable is distributed with RHEL 8. Customers are advised to use python3 or python2 directly. Alternatively, administrators can configure the unversioned python command using the alternatives command. Python scripts must specify major version in hashbangs at RPM build time In RHEL 8, executable Python scripts are expected to use hashbangs (shebangs) specifying explicitly at least the major Python version.


Michael: We were featured on TechMeme Long Ride Home podcast. Check out their podcast here. Thank you to Brian McCullough, the host of the show. I just learned about their show through this exchange but can easily see myself listening from time to time. It’s like Python Bytes, but for the wider tech world and less developer focused but still solid tech foundations.

Brian: First story was about glom. I had heard of glom before, but got excited after interviewing Mahmoud for T&C 55, where we discussed the difficulty in testing if you use glom or DSLs in general. A twitter exchange and GH issue followed the episode, with Anthony Shaw. At one point, Ant shared this great joke from Brenan Kellar:

A QA engineer walks into a bar. Orders a beer. Orders 0 beers. Orders 99999999999 beers. Orders a lizard. Orders -1 beers. Orders a ueicbksjdhd.

First real customer walks in and asks where the bathroom is. The bar bursts into flames, killing everyone.

— Brenan Keller (@brenankeller) November 30, 2018

#106 Fluent query APIs on Python collections

Dec 1, 2018 00:26:21


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Brian #1: Dependency Management through a DevOps Lens

Python Application Dependency Management in 2018 - Hynek An opinionated comparison of one use case and pipenv, poetry, pip-tools “We have more ways to manage dependencies in Python applications than ever. But how do they fare in production? Unfortunately this topic turned out to be quite polarizing and was at the center of a lot of heated debates. This is my attempt at an opinionated review through a DevOps lens.” Best disclaimer in a blog article ever: “DISCLAIMER: The following technical opinions are mine alone and if you use them as a weapon to attack people who try to improve the packaging situation you’re objectively a bad person. Please be nice.” Requirements: Solution needs to meet the following features: Allow me specify my immediate dependencies (e.g. Django), resolve the dependency tree and lock all of them with their versions and ideally hashes (more on hashes), integrate somehow with tox so I can run my tests, and finally allow me to install a project with all its locked dependencies into a virtual environment of my choosing. Seem like reasonable wishes. So far, none of the solutions work perfectly. A good example of pointing out tooling issues with his use case while being respectful of the people involved in creating other tools. Michael #2: Plugins made simple with pluginlib

makes creating plugins for Python very simple it relies on metaclasses, but the average programmer can easily get lost dealing with metaclasses Main Features: Plugins are validated when they are loaded (instead of when they are used) Plugins can be loaded through different mechanisms (modules, filesystem paths, entry points) Multiple versions of the same plugin are supported (The newest one is used by default) Plugins can be blacklisted by type, name, or version Multiple plugin groups are supported so one program can use multiple sets of plugins that won't conflict Plugins support conditional loading (examples: os, version, installed software, etc) Once loaded, plugins can be accessed through dictionary or dot notation Brian #3: How to Test Your Django App with Selenium and pytest

Bob Belderbos “In this article I will show you how to test a Django app with pytest and Selenium. We will test our CodeChalleng.es platform comparing the logged out homepage vs the logged in dashboard. We will navigate the DOM matching elements and more.” Michael #4: Fluent collection APIs (flupy and asq)

flupy implements a fluent interface for chaining multiple method calls as a single python expression. All flupy methods return generators and are evaluated lazily in depth-first order. This allows flupy expressions to transform arbitrary size data in extremely limited memory. Example: pipeline = flu(count()).map(lambda x: x**2) \ .filter(lambda x: x % 517 == 0) \ .chunk(5) \ .take(3) for item in pipeline: print(item) The CLI in particular has been great for our data science team. Not everyone is super comfortable with linux-fu so having a cross-platform way to leverage python knowledge on the shell has been an easy win. Also if you are LINQ inclined: https://github.com/sixty-north/asq asq is simple implementation of a LINQ-inspired API for Python which operates over Python iterables, including a parallel version implemented in terms of the Python standard library multiprocessing module. # ASQ >>> from asq import query >>> words = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"] >>> query(words).order_by(len).then_by().take(5).select(str.upper).to_list() ['ONE', 'SIX', 'TEN', 'TWO', 'FIVE'] Brian #5: Guido blogging again

What to do with your computer science career Answering “A question about whether to choose a 9-5 job or be an entrepreneur” entrepreneurship isn’t for everyone working for someone else can be very rewarding shoot for “better than an entry-level web development job” And “A question about whether AI would make human software developers redundant (not about what I think of the field of AI as a career choice)” AI is about automating tasks that can be boring Software Engineering is never boring. Michael #6: Web apps in pure Python apps with Anvil

Design with our visual designer Build with nothing but Python Publish Instant hosting in the cloud or on-site Paid product but has a free version Covered on Talk Python 138 Extras:

Second Printing (P2) of “Python Testing with pytest

#105 Colorizing and Restoring Old Images with Deep Learning

Nov 23, 2018 00:24:15


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Brian #1: Colorizing and Restoring Old Images with Deep Learning

Text interview by Charlie Harrington of Jason Antic, developer of DeOldify A whole bunch of machine learning buzzwords that I don’t understand in the slightest combine to make a really cool to to make B&W photos look freaking amazing. “This is a deep learning based model. More specifically, what I've done is combined the following approaches: Self-Attention Generative Adversarial Network Training structure inspired by (but not the same as) Progressive Growing of GANs. Two Time-Scale Update Rule. Generator Loss is two parts: One is a basic Perceptual Loss (or Feature Loss) based on VGG16. The second is the loss score from the critic.”

Michael #2: PlatformIO IDE for VSCode

via Jason Pecor PlatformIO is an open source ecosystem for IoT development Cross-platform IDE and unified debugger. Remote unit testing and firmware updates Built on Visual Studio Code which has a nice extension for Python PlatformIO, combined with the features of VSCode provides some great improvements for project development over the standard Arduino IDE for Arduino-compatible microcontroller based solutions. Some of these features are paid, but it’s a reasonable price With Python becoming more popular for microcontroller design, as well, this might be a very nice option for designers. And for Jason’s, specifically, it provides a single environment that can eventually be configured to handle doing the embedded code design, associated Python supporting tools mods, and HDL development. The PlatformIO Core written in Python. Python 2.7 (hiss…) Jason’s test drive video from Tuesday: Test Driving PlatformIO IDE for VSCode

Brian #3: Python Data Visualization 2018: Why So Many Libraries?

Nice overview of visualization landscape, by Anaconda team Differentiating factors, API types, and emerging trends Related: Drawing Data with Flask and matplotlib Finally! A really simple example app in Flask that shows how to both generate and display matplotlib plots. I was looking for something like this about a year ago and didn’t find it.

Michael #4: coder.com - VS Code in the cloud

Full Visual Studio Code, but in your browser Code in the browser Access up to 96 cores VS Code + extensions, so all the languages and features Collaborate in real time, think google docs Access linux from any OS Note: They sponsored an episode of Talk Python To Me, but this is not an ad here...

Brian #5: *By Welcoming Women, Python’s Founder Overcomes Closed Minds In Open Source*

Forbes’s article about Guido and the Python community actively working to get more women involved in core development as well as speaking at conferences. Good lessons for other projects, and work teams, about how you cannot just passively “let people join”, you need to work to make it happen.

Michael #6: Machine Learning Basics

From Anna-Lena Popkes Plain python implementations of basic machine learning algorithms Repository contains implementations of basic machine learning algorithms in plain Python (modern Python, yay!) All algorithms are implemented from scratch without using additional machine learning libraries. Goal is to provide a basic understanding of the algorithms and their underlying structure, not to provide the most efficient implementations. Most of the algorithms Linear Regression Logistic Regression Perceptron k-nearest-neighbor k-Means clustering Simple neural network with one hidden layer Multinomial Logistic Regression Decision tree for classification Decision tree for regression Anna-Lena was on Talk Python on 186: http://talkpython.fm/186


Michael: PSF Fellow Nominations are open Michael: Shiboken has no meaning Brian: Python 3.7 runtime now available in AWS Lambda

#104 API Evolution the Right Way

Nov 17, 2018 00:30:07


Python Bytes 104

Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Michael #0.1: Chapters and play at

Chapters are now in the mp3 file Play at button on the website (doesn’t work on iOS unless you click the play to start it)

Michael #0.2: Become a friend of the show

https://pythonbytes.fm/friends-of-the-show Or just click “friends of the show” in the navbar Brian #1: wily: A Python application for tracking, reporting on timing and complexity in tests and applications.

Anthony Shaw (aka “Friend of the Show”, aka “Ant”) (if listing 2 “aliases, do you just put one “aka” or one per alias?) I should cover this on Test & Code for the content of the package. But it’s the actual packaging that I want to talk about today. Wily is a code base that can be used as an example of embracing pyproject.toml (pyproject.toml discussed on PB 100 and T&C 52) A real nice clean project using newer packaging tools that also has some frequently used bells and whistles NO setup.py file wily’s pyproject.toml includes flit packaging, metadata, scripts tox configuration black configuration project also has testing done on TravisCI rst based docs and readthedocs updates code coverage black pre-commit for wily pre-commit hook for your project to run wily CONTRIBUTING.md that includes code of conduct HISTORY.md with a nice format tests using pytest Michael #2: Latest VS Code has Juypter support

In this release, closed a total of 49 issues, including: Jupyter support: import notebooks and run code cells in a Python Interactive window Use new virtual environments without having to restart Visual Studio Code Code completions in the debug console window Improved completions in language server, including recognition of namedtuple, and generic types The extension now contains new editor-centric interactive programming capabilities built on top of Jupyter. have Jupyter installed in your environment (e.g. set your environment to Anaconda) and type #%% into a Python file to define a Cell. You will notice a “Run Cell” code lens will appear above the #%% line: Cells in the Jupyter Notebook will be converted to cells in a Python file by adding #%% lines. You can run the cells to view the notebook output in Visual Studio code, including plots Brian #3: API Evolution the Right Way

A. Jesse Jiryu Davis adding features removing features adding parameters changing behavior Michael #4: PySimpleGUI now on Qt

Project by Mike B Covered back on https://pythonbytes.fm/episodes/show/90/a-django-async-roadmap Simple declarative UI “builder” Looking to take your Python code from the world of command lines and into the convenience of a GUI? Have a Raspberry Pi with a touchscreen that's going to waste because you don't have the time to learn a GUI SDK? Look no further, you've found your GUI package. Now supports Qt Modern Python only More frameworks likely coming Brian #5: Comparison of the 7 governance PEPs

Started by Victor Stinner The different PEPs are compared by: hierarchy number of people involved requirements for candidates to be considered for certain positions elections: who votes, and how term limits no confidence vote teams/experts PEP process core dev promotion and ejection how governance will be updated code of conduct PEP 8000, Python Language Governance Proposal Overview: PEP 8010 - The Technical Leader Governance Model continue status quo (ish) PEP 8011 - Python Governance Model Lead by Trio of Pythonistas like status quo but with 3 co-leaders PEP 8012 - The Community Governance Model no central authority PEP 8013 - The External Governance Model non-core oversight PEP 8014 - The Commons Governance Model core oversight PEP 8015 - Organization of the Python community push most decision-making to teams PEP 8016 - The Steering Council Model bootstrap iterating on governance Michael #6: Shiboken (from Qt for Python project)

From PySide2 (AKA Qt for Python) project Generate Python bindings from arbitrary C/C++ code Has a Typesystem (based on XML) which allows modifying the obtained information to properly represent and manipulate the C++ classes into the Python World. Can remove and add methods to certain classes, and even modify the arguments of each function, which is really necessary when both C++ and Python collide and a decision needs to be made to properly handle the data structures or types. Qt for Python: under the hood Write your own Python bindings Other options include: CFFI (example dbader.org) Cython (example: via shamir.stav) Extras:

Michael: Mission Python: Code a Space Adventure Game! book Michael: PyCon tickets are on sale Michael: PyCascade tickets are on sale

#103 Getting to 10x (results for developers)

Nov 8, 2018 00:27:06


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Brian #1: FEniCS

“FEniCS is a popular open-source (LGPLv3) computing platform for solving partial differential equations (PDEs). FEniCS enables users to quickly translate scientific models into efficient finite element code. With the high-level Python and C++ interfaces to FEniCS, it is easy to get started, but FEniCS offers also powerful capabilities for more experienced programmers. FEniCS runs on a multitude of platforms ranging from laptops to high-performance clusters.” Solves partial differential equations efficiently with a combination of C++ and Python. Can be run on a desktop/laptop or deployed to a supercomputer with thousands of parallel processes. is a NumFOCUS fiscally supported project “makes the implementation of the mathematical formulation of a system of partial differential equations almost seamless.” - Sébastien Brisard “FEniCS is in fact a C++ project with a full-featured Python interface. The library itself generates C++ code on-the-fly, that can be called (on-the-fly) from python. It's almost magical... Under the hood, it used to use SWIG, and recently moved to pybind11. I guess the architecture that was set up to achieve this level of automation might be useful in other situations.” - Sébastien Brisard Michael #2: cursive_re

via Christopher Patti, created by Bogdan Popa Readable regular expressions for Python 3.6 and up. It’s a tiny Python library made up of combinators that help you write regular expressions you can read and modify six months down the line. Best understood via an example: >>> hash = text('#') >>> hexdigit = any_of(in_range('0', '9') + in_range('a', 'f') + in_range('A', 'F')) >>> hexcolor = ( ... beginning_of_line() + hash + ... group(repeated(hexdigit, exactly=6) | repeated(hexdigit, exactly=3)) + ... end_of_line() ... ) >>> str(hexcolor) '^\\#([a-f0-9]{6}|[a-f0-9]{3})$' Has automatic escaping for [ and \ etc: str(any_of(text("[]"))) → '[\\[\\]]' Easily testable / inspectable. Just call str on any expression. Brian #3: pyimagesearch

Adrian Rosebrock is focused on teaching OpenCV with Python Just a really cool resource of integrating computer vision and Python. Both free and paid resources. He had one of the most successful tech learning kickstarters (ever?) on this topic: https://www.kickstarter.com/projects/adrianrosebrock/deep-learning-for-computer-vision-with-python-eboo Michael #4: Visualization of Python development up till 2012

via Ophion Group (on twitter) mercurial (hg) source code repository commit history August 1990 - June 2012 (cpython 3.3.0 alpha) Watch the first minute, then click ahead minute at a time and watch for a few seconds to get the full feel Really interesting to see a visual representation of the growth of an open source ecosystem Built with Gource: https://gource.io/ Amazing video of the history gource and its visualization of various projects: https://vimeo.com/15943704 Who wants to build this for 2012-present? Would make an amazing lightning talk! Brian #5: Getting to 10x (Results): What Any Developer Can Learn from the Best

Forget the “10x” bit if that term is fighting words. - Brian’s advice How about just “ways to improve your effectiveness as a developer”? “… there is a clear path to excellence. People aren’t born great developers. They get there through focused, deliberate practice.” traits of great developers problem solver skilled mentor/teacher excellent learner passionate traits to avoid: incompetent arrogant uncooperative unmotivated stubborn Focus on your strengths more than your weaknesses Pick 1 thing to improve on this week and focus on it relentlessly Michael #6: Chaos Toolkit

Chaos Engineering is the discipline of experimenting on a distributed system in order to build confidence in the system's capability to withstand turbulent conditions in production. Netflix uses the chaos monkey (et. al.) on their systems. Covered on https://talkpython.fm/episodes/show/16/python-at-netflix The Chaos Toolkit aims to be the simplest and easiest way to explore building, and automating, your own Chaos Engineering Experiments. Integrates with Kubernetes, AWS, Google Cloud, Microsoft Azure, etc. To give you an idea, here are some things it can do to aws: lambda: delete_function_concurrency Removes concurrency limit applied to the specified Lambda stop_instance Stop a single EC2 instance. You may provide an instance id explicitly or, if you only specify the AZ, a random instance will be selected. Extras:

MK: Malicious Python Libraries Found & Removed From PyPI MK: Some really long type names Brian: Deep dive into pyproject.toml and the future of Python packaging with Brett Cannon follow up from episode 100 Python Bytes

#102 Structure of a Flask Project

Oct 31, 2018 00:26:52


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Brian #1: QuantEcon

“Open source code for economic modeling” “QuantEcon is a NumFOCUS fiscally sponsored project dedicated to development and documentation of modern open source computational tools for economics, econometrics, and decision making.” Educational resource that includes: Lectures, workshops, and seminars Cheatsheets for scientific programming in Python and Julia Notebooks QuantEcon.py : open source Python code library for economics

Michael #2: Structure of a Flask Project

Flask is very flexible, it has no certain pattern of a project folder structure. Here are some suggestions. I always keep this one certain rule when writing modules and packages: “Don't backward import from root __init__.py.” Candidate structure: project/ __init__.py models/ __init__.py users.py posts.py ... routes/ __init__.py home.py account.py dashboard.py ... templates/ base.html post.html ... services/ __init__.py google.py mail.py Love it! To this, I would rename routes to views or controllers and add a viewmodels folder and viewmodels themselves. Brian, see anything missing? ya. tests. :) Another famous folder structure is app based structure, which means things are grouped bp application I (Michael) STRONGLY recommend Flask blueprints

Brian #3: Overusing lambda expressions in Python

lambda expressions vs defined functions They can be immediately passed around (no variable needed) They can only have a single line of code within them They return automatically They can’t have a docstring and they don’t have a name They use a different and unfamiliar syntax misuses: naming them. Just write a function instead calling a single function with a single argument : just use that func instead overuse: if they get complex, even a little bit, they are hard to read has to be all on one line, which reduces readibility map and filter : use comprehensions instead using custom lambdas instead of using operators from the operator module.

Michael #4: Asyncio in Python 3.7

by Cris Medina The release of Python 3.7 introduced a number of changes into the async world. Some may even affect you even if you don’t use asyncio. New Reserved Keywords: The async and await keywords are now reserved. There’s already quite a few modules broken because of this. However, the fix is easy: rename any variables and parameters. Context Variables: Version 3.7 now allows the use of context variables within async tasks. If this is a new concept to you, it might be easier to picture it as global variables whose values are local to the currently running coroutines. Python has similar constructs for doing this very thing across threads. However, those were not sufficient in async-world New asyncio.run() function With a call to asyncio.run(), we can now automatically create a loop, run a task on it, and close it when complete. Simpler Task Management: Along the same lines, there’s a new asyncio.create_task() function that helps make tasks that inside the current loop, instead of having to get the loop first and calling create task on top of it. Simpler Event Loop Management: The addition of asyncio.get_running_loop() will help determine the active event loop, and catch a RuntimeError if there’s no loop running. Async Context Managers: Another quality-of-life improvement. We now have the asynccontextmanager() decorator for producing async context managers without the need for a class that implements __aenter__() or __aexit__(). Performance Improvements: Several functions are now optimized for speed, some were even reimplemented in C. Here’s the list: asyncio.get_event_loop() is now 15 times faster. asyncio.gather() is 15% faster. asyncio.sleep() is two times faster when the delay is zero or negative. asyncio.Future callback management is optimized. Reduced overhead for asyncio debug mode. Lots lots more

Brian #5: Giving thanks with **pip thank**

proposal: https://github.com/pypa/pip/issues/5970

Michael #6: Getting Started With Testing in Python

by Anthony Shaw, 33 minutes reading time according to Instapaper Automated vs. Manual Testing Unit Tests vs. Integration Tests: A unit test is a smaller test, one that checks that a single component operates in the right way. A unit test helps you to isolate what is broken in your application and fix it faster. Compares unittest, nose or nose2, pytest Covers things like: Writing Your First Test Where to Write the Test How to Structure a Simple Test How to Write Assertions Dangers of Side Effects Testing in PyCharm and VS Code Testing for Web Frameworks Like Django and Flask Advanced Testing Scenarios Even: Testing for Security Flaws in Your Application


MK: Hack ur name — aka Pivot me bro (done in Python: https://github.com/veekaybee/hustlr ) by Vicki Boykis MK: Python 3.7.1 and 3.6.7 Are Now Available MK: Click-Driven Development (CDD) - via @tombaker Use Python Click package to mock up suite of commands w/options/args. Decorated functions print description of intended results. Replace placeholders with code.

#101 Nobel Prize awarded to a Python convert

Oct 24, 2018 00:21:34


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Brian #1: Asterisks in Python: what they are and how to use them

I just ** love *s Using * and ** to pass arguments to a function * for list, ** for keyword arguments from a dictionary Using * and ** to capture arguments passed into a function Using * to accept keyword-only arguments Using * to capture items during tuple unpacking you can capture the rest if you only want to grab a few Using * to unpack iterables into a list/tuple Using ** to unpack dictionaries into other dictionaries

Michael #2: responder web framework

From Kenneth Reitz — A familiar HTTP Service Framework Already has 1,393 github stars Flask-like but with async support and A pleasant API, with a single import statement. Class-based views without inheritance. ASGI framework, the future of Python web services. WebSocket support! The ability to mount any ASGI / WSGI app at a subroute. f-string syntax route declaration. Mutable response object, passed into each view. No need to return anything. Background tasks, spawned off in a ThreadPoolExecutor. GraphQL (with GraphiQL) support! OpenAPI schema generation. Single-page webapp support Responder gives you the ability to mount another ASGI / WSGI app at a subroute uvicorn: powers responder and is built on top of uvloop asgi: https://www.encode.io/articles/hello-asgi/

Brian #3: Python Example resource: pythonprogramming.in

Lots of examples Python basics including date time, strings, dictionaries pandas, matplotlib, tensorflow basics data structures and algorithms Nice reference, especially for people getting into Python for data science or scientific work.

Michael #4: This year’s Nobel Prize in economics was awarded to a Python convert**

Nordhaus and Romer “have designed methods that address some of our time’s most fundamental and pressing issues: long-term sustainable growth in the global economy and the welfare of the world’s population,” Notably for a 62-year-old economist of his distinction, he is a user of the programming language Python. Romer believes in making research transparent. He argues that openness and clarity about methodology is important for scientific research to gain trust. He tried to use Mathematica to share one of his studies in a way that anyone could explore every detail of his data and methods. It didn’t work. He says that Mathematica’s owner, Wolfram Research, made it too difficult to share his work in a way that didn’t require other people to use the proprietary software, too. Romer believes that open-source notebooks are the way forward for sharing research. He believes they support integrity, while proprietary software encourage secrecy. “The more I learn about proprietary software, the more I worry that objective truth might perish from the earth,” he wrote. Michael covered a similar story for the Nobel Prize in Physics at CERN on Talk Python Jake Vanderplas Keynote at PyCon 2017: “The unexpected effectiveness of Python in Science”

Brian #5: More in depth TensorFlow

Michael #6: MAKERphone - an educational DIY mobile phone

MAKERphone is an educational DIY mobile phone designed to bring electronics and programming to the crowd in a fun and interesting way. A fully functional mobile phone that you can code yourself Games such as space invaders, pong, or snake Apps such as a custom media player that only plays cat videos Programs in Arduino Lines of code in Python Your first working piece of code in Scratch A custom case


MK: Around 62% of all Internet sites will run an unsupported PHP version in 10 weeks The highly popular PHP 5.x branch will stop receiving security updates at the end of the year.

#100 The big 100 with special guests

Oct 19, 2018 00:42:00


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Special guests:

Anthony Shaw Dan Bader Brett Cannon Nina Zakharenko

Brian #1: poetry

“poetry is a tool to handle dependency installation as well as building and packaging of Python packages. It only needs one file to do all of that: the new, standardized pyproject.toml. In other words, poetry uses pyproject.toml to replace setup.py, requirements.txt, setup.cfg, MANIFEST.in and the newly added Pipfile.” poetry can be used for both application and library development handles dependencies and lock files strongly encourages virtual environment use (need specifically turn it off) can be used within an existing venv or be used to create a new venv automates package build process automates deployment to PyPI or to another repository CLI and the use model is very different than pipenv. Even if they produced the same files (which they don’t), you’d still want to try both to see which workflow works best for you. For me, I think poetry matches my way of working a bit more than pipenv, but I’m still in the early stages of using either. From Python's New Package LandscapePEP 517 and PEP 518—accepted in September 2017 and May 2016, respectively—changed this status quo by enabling package authors to select different build systems. Said differently, for the first time in Python, developers may opt to use a distribution build tool other than **distutils** or **setuptools**. The ubiquitous **setup.py** file is no longer mandatory in Python libraries.” PEP 517 -- A build-system independent format for source trees PEP 518 -- Specifying Minimum Build System Requirements for Python Projects Another project that utilizes pyproject.toml is flit, which seems to overlap quite a bit with poetry, but I don’t think it does the venv, dependency management, dependency updating, etc. See also: Clarifying PEP 518 (a.k.a. pyproject.toml) - From Brett Question for @Brett C 517 and 518 still say “provisional” and not “final”. What’s that mean? We are still allowed to tweak it as necessary before it Biggest difference is poetry uses pyproject.toml (PEP518) instead of Pipfile. Replaces all others (setup.py, setup.cfg, requirements*.txt, manifest.IN) Even its lock file is in TOML Author “does not like” pipenv, or some of the decisions it has made. Note that Kenneth has recently made some calls to introduce more discussion and openness with a PEP-style process called PEEP (PipEnv Enhancement Proposals). E.g. uses a more extensive dependency resolver Pipenv does not support multiple environments (by design) making it useless for library development. Poetry makes this more open. See https://medium.com/@DJetelina/pipenv-review-after-using-in-production-a05e7176f3f0 Wait. Why am I doing your notes for you @Brian O ! (awesome. Thanks Ant.) Brett has had initial discussions on Twitter with both pipenv and poetry about possibly standardizing on a lockfile format so that’s the artifact these tools produce and everything else is tool preference

Anthony Shaw #2: pylama and radon

Have been investigating tools for measuring complexity and performance of code and how that relates to test If you can refactor your code so the tests still pass, the customers are still happy AND it’s simpler then that’s a good thing - right? Radon is a Python tool that leverages the AST to give statistics on Cyclomatic Complexity (number of decisions — nested if’s are bad), maintainability index (LoC & Halstead) and Halstead (number of operations an complexity of AST). Radon works by adding a ComplexityVisitor to the AST. Another option is Ned Batchelder’s McCabe tool which measures the number of possible branches (similar to cyclomatic) All of these tools are combined in pylama - a code linter for Python and Javascript. Embeds pycodestyle, mccabe, radon, gjslint and pyflakes. Final goal is to have a pytest plugin that fails tests if you make your code more complicated

Nina Zakharenko #3: Tools for teaching Python

Teaching Python can come with hurdles — virtual environments, installing python3, pip, working with the command line. Put out a call on twitter asking - “What software and tools do you use to teach Python?”. 50 Responses, 414 votes, learned about lots of new tools. Read the thread. 27% use python or ipython repl 13% use built-in IDLE 39% use an IDE or editor - Visual Studio Code, PyCharm, Atom. 21% use other (mix of local and hosted Jupyter notebooks and other responses) New tools I learned about: Mu editor - simple python editor, great for those completely new to programming. Large buttons with common actions above the editor. Support for educational platforms Integrates with hardware platforms -- adafruit Circuit Playground, micro:bit PyGame Awesome tutorials Neuron plugin for VS Code, Hydrogen plugin for Atom Interactive coding environment, brings a taste of Jupyter notebooks into your editor. Targeted towards data scientists. Show evaluated values, output pane to display charts and graphs Import to/from Jupyter notebooks repl.it - open source hosted cloud repl with reasonable free tier project goal - zero effort setup 3 vertical panes: files, editor, repl, and a button to run the current code. no login, no signup needed to get started visual package installation - no running pip, requirements.txt automatically generated includes a debugger bpython - Used it years ago, still an active project. Fancy curses interface to the Python interactive interpreter. Windows, type hints, expected parameters lists. Really cool feature — you can rewind your session! Pops the last line, and the entire session is reevaluated. Easily reload imported modules. Honorable mentions: Edublocks - Teaching tool for kids, visually drag and drop blocks of Python code. Open source, created by Joshua Lowe, a brilliant 14 year old maker and programmer. pythonanywhere, codeskulptor.org, codesters.

Dan Bader #4: My favorite tool of 2018: “Black” code formatter by Łukasz Langa

Black is the “uncompromising Python code formatter” An opinionated auto-formatter for your code (like YAPF/autopep for Python, or gofmt for golang who popularized the idea) Heard about it in episode #73 by Brian Started using it for some small tools, then rolled it out to the whole realpython.com code base including our public example code repo (https://github.com/realpython/materials) Benefits are: Auto formatting—Not only does it call you out on formatting violations, it auto-fixes them Code style discussions disappear—just use whatever Black does Super easy to make several code bases look consistent (no more mental gymnastics to format new code to match its surroundings) Automatically enforce consistent formatting on CI with “black --check” (I use a combo of flake8 + black because flake8 also catches syntax errors and some other “code smells”) pro-tip: set up a pre-commit hook/rule to automatically run black before committing to Git. Also add it to your editor workflow (reformat on save / reformat on paste) Tool support: Built into the Python extension for VS Code (which Łukasz uses 😉) Plug-in for PyCharm (for Michael and Brian 😁 ) Support in pre-commit For the most part I really like the formatting Black applies, if you’re not a fan you might hate this tool because it makes your code look “ugly” 🙂 Still in beta but found it very useful and helpful as of October 2018. Give it a try!

Brett Cannon #5: A Web without JavaScript: Russell Keith-Magee at PyCon AU

JavaScript has a monopoly in web browsers for client-side programming Mono-language situations are not good for anyone Can Python somehow break into the client-side web world? Example implementation of Luhn algorithm: JavaScript: 0.4KB Transcrypt: transpile to 32KB Brython: Python compiler for 0.5KB + 646KB bootstrap Batavia: Eval loop for 1.2KB + 5MB bootstrap Pyodide: CPython compiled to WASM for 0.5KB + 3MB bootstrap WASM as a Python target might make this feasible Example written in C compiled to 22KB (w/ a 65KB bootstrap for older browsers) Maybe easier to target Electron/Node instead of client-side web initially? Scott Hanselman’s blog post https://www.hanselman.com/blog/JavaScriptIsWebAssemblyLanguageAndThatsOK.aspx Hanselminutes interview https://hanselminutes.com/638/c-and-browser-monoculture-with-vivaldis-patricia-aas

Michael #6: Async WebDriver implementation for asyncio and asyncio-compatible frameworks

You’ve heard of Selenium but in an async world what do we use? Answer: arsenic # Example: Let's run a local Firefox instance. async def example(): # Runs geckodriver and starts a firefox session async with get_session(Geckodriver(), Firefox()) as session: # go to example.com await session.get('http://example.com') # wait up to 5 seconds to get the h1 element from the page h1 = await session.wait_for_element(5, 'h1') # print the text of the h1 element print(await h1.get_text()) Use cases include testing of web applications, load testing, automating websites, web scraping or anything else you need a web browser for. It uses real web browsers using the Webdriver specification. Warning: While this library is asynchronous, web drivers are not. You must call the APIs in sequence. The purpose of this library is to allow you to control multiple web drivers asynchronously or to use a web driver in the same thread as an asynchronous web server. Arsenic with pytest Supported browsers Headless Google Chrome Headless Firefox Everyone’s thoughts on async in Python these days? Selenium-Grid https://www.seleniumhq.org/docs/07_selenium_grid.jsp


Take the python survey: https://talkpython.fm/survey2018 3.7.1rc1 is out https://docs.python.org/3.7/whatsnew/changelog.html#python-3-7-1-release-candidate-1 A good review on Python packaging http://andrewsforge.com/article/python-new-package-landscape/ New September release of Python Extension for Visual Studio Code — lots of new features, like automatic environment activation in the terminal, debugging improvements, and more! Submit a talk to PyCascades happening February 2019 in Seattle. Call for proposals closes October 21st. Mentorship available.

#99 parse - the regex antidote in Python

Oct 16, 2018 00:21:18


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Forbes cyber article: Cyber Saturday—Doubts Swirl Around Bloomberg's China Chip Hack Report

Brian #1: parse

“parse() is the opposite of format()” regex not required for parsing strings. Provides these functionalities: export parse(), search(), findall(), and with_pattern() >>> parse("It's {}, I love it!", "It's spam, I love it!") [HTML_REMOVED] >>> search('Age: {:d}\n', 'Name: Rufus\nAge: 42\nColor: red\n') [HTML_REMOVED] >>> ''.join(r.fixed[0] for r in findall(">{}<", "[HTML_REMOVED]the [HTML_REMOVED]bold[HTML_REMOVED] text[HTML_REMOVED]")) 'the bold text' Can also compile for repeated use.

Michael #2: fman Build System

FBS lets you create GUI apps for Windows, Mac and Linux via Michael Herrmann Build Python GUIs, with Qt – in minutes Write a desktop application with PyQt or Qt for Python. Use fbs to package and deploy it on Windows, Mac and Linux. Avoid months of painful work with the proven solutions provided by fbs. Easy Packaging: Unlike other solutions, fbs makes packaging easy. Create installers for your app in seconds and distribute them to your users – on Windows, Mac and Linux! Open Source: fbs's source code is available on GitHub. You can use it for free in open source projects licensed under the GPL. Commercial licenses are also offered. Free under the GPL. If that's too restrictive, a commercial license is 250 Euros once. PyQt's licensing is similar (GPL/Commercial). A license for it is € 450 (source). Came from fman, a dual-pane file manager for Mac, Windows and Linux

Brian #3: fastjsonschema

Validate JSON against a schema, quickly.

Michael #4: IPython 7.0, Async REPL

via Nick Spirit Article by Matthias Bussonnier We are pleased to announce the release of IPython 7.0, the powerful Python interactive shell that goes above and beyond the default Python REPL with advanced tab completion, syntactic coloration, and more. Not having to support Python 2 allowed us to make full use of new Python 3 features and bring never before seen capability in a Python Console, see the Python 3 Statement. One of the core features we focused on for this release is the ability to (ab)use the async and await syntax available in Python 3.5+. TL;DR: You can now use async/await at the top level in the IPython terminal and in the notebook, it should — in most of the cases — “just work”. The only thing you need to remember is: If it is an async function you need to await it.

Brian #5: molten

Michael #6: A Python love letter

Dear Python, where have you been all my life? (reddit thread) I am NOT a developer. But, I've tinkered with programming (in BASIC, Visual Basic, Perl, now Python) when needed over the years I decided that I needed to script something, and hoped that learning how to do it in Python was going to take me significantly less time than doing it manually - with the benefit of future timesavings. No, I didn't go from 0 to production in a day. But if my coworkers will leave me alone, I might be in production by the end of the day tomorrow. What I'm working on today isn't super complex — But putting together what I've done so far has just been a complete joy. Overall it feels natural, intuitive, and relatively easy to understand and write the code for the basic things I'm doing - I haven't had this much fun doing stuff with code since the days fooling around with BASIC in my teens. Feedback / comments Welcome to the club. I came up on c++; my job highly trained me in C and assembly but every project I touch I think, wait, "we can do 95% this in python". And we do. I used to have a chip on my shoulder. I wanted to do things the hard way to truly understand them. I went with C++. … I learned that doing things the smart way was better than doing things the hard way and didn't interfere with learning. I felt the exact same way I finally decided to learn it. It's like a breath of fresh air. Sadly there are few things in my life that made me feel like this, Python and Bitcoin both give me the same levels of enjoyment. … I've used Java, Groovy, Scala, Objective-C, C, C++, C#, Perl and Javascript in a professional capacity over the years and nothing feels as natural to me as Python does. The developers truly deserve any donations they get for making it. … Hell my next two planned tattoos are bitcoin and python logos on my wrists. I taught myself Python a little over 3 years ago and I quickly went from not being programmer to being a programmer. … However the real popularity of Python comes from the depth and quality of 3rd party libraries and how easy they are to install.


Brian: Power Mode II

#98 Python-Electron as a Python GUI

Oct 8, 2018 00:26:58


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Brian #1: Making Etch-a-Sketch Art With Python

Really nice write up of methodically solving problems with simplifying the problem space, figuring out what parts need solved, grabbing off the shelf bits that can help, and putting it all together. Plus it would be a fun weekend (or several) project with kids helping. Controlling the Etch-a-Sketch Raspberry Pi, motors, cables, wood fixture Software to control the motors Picture simplification with edge detection with Canny edge detection. Lines to motor control with path finding with networkx library. Example results included in article. Pentium song: https://www.youtube.com/watch?v=qpMvS1Q1sos

Michael #2: Dropbox moves to Python 3

They just rolled out one of the largest Python 3 migrations ever Dropbox is one of the most popular desktop applications in the world Much of the application is written using Python. In fact, Drew’s very first lines of code for Dropbox were written in Python for Windows using venerable libraries such as pywin32. Though we’ve relied on Python 2 for many years (most recently, we used Python 2.7), we began moving to Python 3 back in 2015. If you’re using Dropbox today, the application is powered by a Dropbox-customized variant of Python 3.5. Why Python 3? Exciting new features: Type annotations and async & await Aging toolchains: As Python 2 has aged, the set of toolchains initially compatible for deploying it has largely become obsolete Embedding Python To solve build and deploy problem, we decided on a new architecture to embed the Python runtime in our native application. Deep integration with the OS (e.g. smart sync) means native apps are required In future posts, we’ll look at: How we report crashes on Windows and macOS and use them to debug both native and Python code. How we maintained a hybrid Python 2 and 3 syntax, and what tools helped. Our very best bugs and stories from the Python 3 migration.

Brian #3: Resources for PyCon that relate to really any talk venue

Speaking page Talk proposal tips and resources And the poster session. Way cooler than I originally understood. Mariatta recently published her set of proposals Nice clean examples that don’t look overwhelming There’s also some links to examples at the talk proposal page. Related, on attending PyCon (or other technical conferences): You don't need to be a Pro @ Python to crack the code of Pycon missing: hang out and talk with, ask questions, and possibly help out with communities as part of the Expo.

Michael #4: Electron as GUI of Python Applications

via Andy Bulka Electron Python is a template of code where you use Electron (nodejs + chromium) as a GUI talking to Python 3 as a backend via zerorpc. Similar to Eel but much more capable e.g. you get proper native operating system menus — and users don’t need to have Chrome already installed. Needs to run zerorpc server and then start electron separately — can be done via the node backend using Electron as a GUI toolkit gets you native menus, notifications installers, automatic updates to your app debugging and profiling that you are used to, using the Chrome debugger ES6 syntax (a cleaner Javascript with classes, module imports, no need for semicolons etc.). Squint, look sideways, and it kinda looks like Python… ;-) the full power of nodejs and its huge npm package repository the large community and ecosystem of Electron How to package this all? Building a deployable Python-Electron App post by Andy Bulka One of the great things about using Electron as a GUI for Python is that you get to use cutting edge web technologies and you don’t have to learn some old, barely maintained GUI toolkit How much momentum, money, time and how many developer minds are focused on advancing web technologies? Answer: it’s staggeringly huge. Compare this with the number of people maintaining old toolkits from the 90’s e.g. wxPython? Answer: perhaps one or two people in their spare time. Which would you rather use? Final quote: And someone please wrap Electron-Python into an IDE so that in the future all we have to do is click a ‘build’ button — like we could 20 years ago. :-)

Brian #5: pluggy: A minimalist production ready plugin system

docs plugin management and hook system used by pytest A separate package to allow other projects to include plugin capabilities without exposing unnecessary state or behavior of the host project.

Michael #6: How China Used a Tiny Chip to Infiltrate U.S. Companies

via Eduardo Orochena The attack by Chinese spies reached almost 30 U.S. companies, including Amazon and Apple, by compromising America’s technology supply chain, according to extensive interviews with government and corporate sources. In 2015, Amazon.com Inc. began quietly evaluating a startup called Elemental Technologies, a potential acquisition to help with a major expansion of its streaming video service, known today as Amazon Prime Video. (from Portland!) To help with due diligence, AWS, which was overseeing the prospective acquisition, hired a third-party company to scrutinize Elemental’s security servers were assembled for Elemental by Super Micro Computer Inc., a San Jose-based company (commonly known as Supermicro) that’s also one of the world’s biggest suppliers of server motherboards Nested on the servers’ motherboards, the testers found a tiny microchip, not much bigger than a grain of rice, that wasn’t part of the boards’ original design. Amazon reported the discovery to U.S. authorities, sending a shudder through the intelligence community. Elemental’s servers could be found in Department of Defense data centers, the CIA’s drone operations, and the onboard networks of Navy warships. And Elemental was just one of hundreds of Supermicro customers. During the ensuing top-secret probe, which remains open more than three years later, investigators determined that the chips allowed the attackers to create a stealth doorway into any network that included the altered machines. Multiple people familiar with the matter say investigators found that the chips had been inserted at factories run by manufacturing subcontractors in China. One government official says China’s goal was long-term access to high-value corporate secrets and sensitive government networks. No consumer data is known to have been stolen. American investigators eventually figured out who else had been hit. Since the implanted chips were designed to ping anonymous computers on the internet for further instructions, operatives could hack those computers to identify others who’d been affected.


Michael's Async course talkpython.fm/async

#97 Java goes paid

Sep 28, 2018 00:24:36


Sponsored by DataDog -- pythonbytes.fm/datadog

Brian #1: Making a PyPI-friendly README

twine now checks for rendering problems with README Install the latest version of twine; version 1.12.0 or higher is required: pip install --upgrade twine Build the sdist and wheel for your project as described under Packaging your project. Run twine check on the sdist and wheel: twine check dist/* This command will report any problems rendering your README. If your markup renders fine, the command will output Checking distribution FILENAME: Passed.

Michael #2: Java goes paid

Oracle's new Java SE subs: Code and support for $25/processor/month Prepare for audit after inevitable change, says Oracle licensing consultant There’s also a little bit of stick to go with the carrot, because come January 2019 Java SE 8 on the desktop won’t be updated any more … unless you buy a sub. The short version is that every commercial enterprise needs to look at their Java SE (Standard Edition) usage to see if they need to do something with licensing.

Brian #3: Absolute vs Relative Imports in Python

Review of how imports are used, along with subpackages and from ex: from package.sub import func Relative: what does this mean: from .some_module import some_class from ..some_package import some_function from . import some_class

Michael #4: pyxel - A retro game engine for Python

Thanks to its simple specifications inspired by retro gaming consoles, such as only 16 colors can be displayed and only 4 sounds can be played back at the same time, you can feel free to enjoy making pixel art style games. Run on Windows, Mac, and Linux Code writing with Python3 After installing Pyxel, the examples of Pyxel will be copied to the current directory with the following command: install_pyxel_examples

Brian #5: Click 7.0 Released

Changelog Drop support for Python 2.6 and 3.3. Add native ZSH autocompletion support. Usage errors now hint at the --help option Really long list of changes since the last release at the beginning of 2017

Michael #6: How we spent 30k USD in Firebase in less than 72 hours

the largest crowdfunding campaign in Colombia, collecting 3 times more than the previous record so far in only two days! Run on the Vaki platform -- subject of this article We had reached more than 2 million sessions, more than 20 million pages visited and received more than 15 thousand supports. This averages to a thousand users active on the site in average and collecting more than 20 supports per minute. Site was running slow, tried things like upgraded the frontend frameworks Logged into Firebase: had spent $30,356.56 USD in just 72 hours! Going at $600/hr All came down to a very bad implementation of this.loadPayments(). Comments are interesting It could happen to any of us, it happened to me this month.


Dropbox has upgraded from Python 2 → 3! Michael’s async course is live: Async Techniques and Examples in Python 2019 PyCon CFPs open PyCascades CFP is open until mid-Oct

#96 Python Language Summit 2018

Sep 22, 2018 00:26:33


Sponsored by DigitalOcean -- pythonbytes.fm/digitalocean

Brian #1: Plumbum: Shell Combinators and More

Toolbox of goodies to do shell-like things from Python. “The motto of the library is “Never write shell scripts again”, and thus it attempts to mimic the shell syntax (shell combinators) where it makes sense, while keeping it all Pythonic and cross-platform.”


>>> from plumbum.cmd import grep, wc, cat, head >>> chain = ls["-a"] | grep["-v", "\\.py"] | wc["-l"] >>> print chain /bin/ls -a | /bin/grep -v '\.py' | /usr/bin/wc -l >>> chain() u'13\n' >>> ((cat < "setup.py") | head["-n", 4])() u'#!/usr/bin/env python\nimport os\n\ntry:\n' >>> (ls["-a"] > "file.list")() u'' >>> (cat["file.list"] | wc["-l"])() u'17\n'

Michael #2: Windows 10 Linux subsystem for Python developers

via Marcus Sherman “One of the hardest days in teaching introduction to bioinformatics material is the first day: Setting up your machine.” While I have seen a very large bias towards Macs in academia, there are plenty of people that keep their Windows machines as a badge of pride... Marcus included. Even though Anaconda is cross platform and helpful, how does this work on Windows? python3 -m venv .env and source .env/bin/activate? Spoiler alert: Not well. Step by step getting Ubuntu on Windows Shows how to setup an x-server

Brian #3: Type hints cheat sheet (Python 3)

Do you remember how to type hint duck types? Something accessed like an array (list or tuple or …) and holds strings → Sequence[str] Something that works like a dictionary mapping integers to strings → Mapping[int, str] As I’m adding more and more typing to interface functions, I keep this cheat sheet bookmarked.

Michael #4: Python driving new languages

Here are five predictions for what programming will look like 10 years from now. Programming will be more abstract Trends like serverless technologies, containers, and low code platforms suggest that many developers may work at higher levels of abstraction in the future AI will become part of every developer's toolkit—but won't replace them A universal programming language will arise To reap the benefits of emerging technologies like AI, programming has to be easy to learn and easy to build upon "Python may be remembered as being the great-great-great grandmother of languages of the future, which underneath the hood may look like the English language, but are far easier to use," Every developer will need to work with data Programming will be a core tenet of the education system

Brian #5: asyncio documentation rewritten from scratch

twitter thread by Yury Selivanov “Big news! asyncio documentation has been rewritten from scratch! Read the new version here: https://docs.python.org/3/library/asyncio.html …. Huge thanks to @WillingCarol, @elprans, and @andrew_svetlov for support, ideas, and reviews!’ “BTW, this is just the beginning. We'll continue to refine and update the documentation. Next up is adding two tutorials: one teaching high-level concepts and APIs, and another teaching how to use protocols and transports. A section about asyncio architecture is also planned.” “And this is just the beginning not only for asyncio documentation, but for asyncio itself. Just for Python 3.8 we plan to add: new streaming API TaskGroups and cancel scopes Supervisors and tracing API new SSL implementation many usability improvements”

Michael #6: The 2018 Python Language Summit

Here are the sessions: Subinterpreter support for Python: a way to have a better story for multicore scalability using an existing feature of the language. Subinterpreters will allow multiple Python interpreters per process and there is the potential for zero-copy data sharing between them. But subinterpreters share the GIL, so that needs to be changed in order to make it multicore friendly. Modifying the Python object model: looking at changes to CPython data structures to increase the performance of the interpreter. - via Instagram and Carl Shapiro - By modifying the Python object model fairly substantially, they were able to roughly double the performance - A little controversial - Shapiro's overall point was that he felt Python sacrificed its performance for flexibility and generality, but the dynamic features are typically not used heavily in performance-sensitive production workloads. A Gilectomy update: a status report on the effort to remove the GIL from CPython. Larry Hastings updated attendees on the status of his Gilectomy project. Since his status report at last year's summit, little has happened, which is part of why the session was so short. He hasn't given up on the overall idea, but it needs a new approach. Using GitHub Issues for Python: a discussion on moving from bugs.python.org to GitHub Issues. Mariatta Wijaya described her reasoning for advocating moving Python away from its current bug tracker to GitHub Issues. it would complete Python's journey to GitHub that started a ways back. Shortening the Python release schedule: a discussion on possibly changing from an 18-month to a yearly cadence. The Python release cycle has an 18-month cadence; a new major release (e.g. Python 3.7) is made roughly on that schedule. But Łukasz Langa, who is the release manager for Python 3.8 and 3.9, would like to see things move more quickly—perhaps on a yearly cadence. Unplugging old batteries: should some older, unloved modules be removed from the standard library? Python is famous for being a "batteries included" language—its standard library provides a versatile set of modules with the language There may be times when some of those batteries have reached their end of life. Christian Heimes wanted to suggest a few batteries that may have outlived their usefulness and to discuss how the process of retiring standard library modules should work. Linux distributions and Python 2: the end of life for Python 2 is coming, what distributions are doing to prepare. Christian Heimes wanted to suggest a few batteries that may have outlived their usefulness and to discuss how the process of retiring standard library modules should work. To figure out how to help the Python downstreams so that Python 2 can be fully discontinued. Python static typing update: a look at where static typing is now and where it is headed for Python 3.7. Started things off by talking about stub files, which contain type information for libraries and other modules. Right now, static typing is only partially useful for large projects because they tend to use a lot of packages from the Python Package Index (PyPI), which has limited stub coverage. There are only 35 stubs for third-party modules in the typeshed library, which is Python's stub repository. He suggested that perhaps a centralized library for stubs is not the right development model. Some projects have stubs that live outside of typeshed, such as Django and SQLAlchemy. PEP 561 ("Distributing and Packaging Type Information") will provide a way to pip install stubs from packages that advertise that they have them. Python virtual environments: a short session on virtual environments and ideas for other ways to isolate local installations. Steve Dower brought up the shortcomings of Python virtual environments, which are meant to create isolated installations of the language and its modules. Thomas Wouters defended virtual environments in a response: The correct justification is that for the average person, not using a virtualenv all too soon creates confusion, pain, and very difficult to fix breakage. Starting with a virtualenv is the easiest way to avoid that, at very little cost. But Beazley and others (including Dower) think that starting Python tutorials or training classes with a 20-minute digression on setting up a virtual environment is wasted time. PEP 572 and decision-making in Python: a discussion of the controversy around PEP 572 and how to avoid the thread explosion that it caused in the future. The "PEP 572 mess" was the topic of a 2018 Python Language Summit session led by benevolent dictator for life (BDFL) Guido van Rossum. Getting along in the Python community: trying to find ways to keep the mailing list welcoming even in the face of rudeness. About tkinter… Mentoring and diversity for Python: a discussion on how to increase the diversity of the core development team. Victor Stinner outlined some work he has been doing to mentor new developers on their path toward joining the core development ranks Mariatta Wijaya gave a very personal talk that described the diversity problem while also providing some concrete action items that the project and individuals could take to help make Python more welcoming to minorities.


Listener feedback: CUDA is NVidia only, so no MacBook pro unless you have a custom external GPU.

#95 Unleash the py-spy!

Sep 15, 2018 00:23:33


Sponsored by DataDog -- pythonbytes.fm/datadog

Brian #1: dataset: databases for lazy people

dataset provides a simple abstraction layer removes most direct SQL statements without the necessity for a full ORM model - essentially, databases can be used like a JSON file or NoSQL store. A simple data loading script using dataset might look like this: import dataset db = dataset.connect('sqlite:///:memory:') table = db['sometable'] table.insert(dict(name='John Doe', age=37)) table.insert(dict(name='Jane Doe', age=34, gender='female')) john = table.find_one(name='John Doe')

Michael #2: CuPy GPU NumPy

A NumPy-compatible matrix library accelerated by CUDA How many cores does a modern GPU have? CuPy's interface is highly compatible with NumPy; in most cases it can be used as a drop-in replacement. You can easily make a custom CUDA kernel if you want to make your code run faster, requiring only a small code snippet of C++. CuPy automatically wraps and compiles it to make a CUDA binary PyCon 2018 presentation: Shohei Hido - CuPy: A NumPy-compatible Library for GPU Code example >>> # This will run on your GPU! >>> import cupy as np # This is the only non-NumPy line >>> x = np.arange(6).reshape(2, 3).astype('f') >>> x array([[ 0., 1., 2.], [ 3., 4., 5.]], dtype=float32) >>> x.sum(axis=1) array([ 3., 12.], dtype=float32)

Brian #3: Automate Python workflow using pre-commits

We covered pre-commit in episode 84, but I still had trouble getting my head around it. This article by LJ Miranda does a great job with the workflow introduction and configuration necessary to get pre-commit working for black and flake8. Includes a nice visual of the flow. Demo of it all in action with a short video.

Michael #4: py-spy

Sampling profiler for Python programs Written by Ben Frederickson Lets you visualize what your Python program is spending time on without restarting the program or modifying the code in any way. Written in Rust for speed Doesn't run in the same process as the profiled Python program Does NOT it interrupt the running program in any way. This means Py-Spy is safe to use against production Python code. The default visualization is a top-like live view of your python program How does py-spy work? Py-spy works by directly reading the memory of the python program using the process_vm_readv system call on Linux, the vm_read call on OSX or the ReadProcessMemory call on Windows.

Brian #5: SymPy is a Python library for symbolic mathematics

“Symbolic computation deals with the computation of mathematical objects symbolically. This means that the mathematical objects are represented exactly, not approximately, and mathematical expressions with unevaluated variables are left in symbolic form.” example: >>> integrate(sin(x**2), (x, -oo, oo)) √2⋅√π ───── 2 examples on site are interactive so you can play with it without installing anything.

Michael #6: Starlette ASGI web framework

The little ASGI framework that shines. It is ideal for building high performance asyncio services, and supports both HTTP and WebSockets. Very flask-esq Can use ultrajson (ujson package) aiofiles for file responses Run using uvicorn


Michael: PyCon 2019 dates out, put them on your calendar!

Tutorials: May 1-2 • Wednesday, Thursday Talks and Events: May 3–5 • Friday, Saturday, Sunday Sprints: May 6–9 • Monday through Thursday

Listener follow up on git pre-commit hooks util: pre-commit package

Matthew Layman, @mblayman Heard the discussion about Git commit hooks at the end. I wanted to bring up pre-commit as an interesting project (written in Python!) that's useful for Git commit hooks. tl;dr: $ pip install pre-commit $ ... create a .pre-commit-config.yaml $ pre-commit install # This is a one time operation. pre-commit's job is to manage a project's Git commit hooks. We use this on my team at work and the devs only need to run pre-commit install. This saves us from a bunch of failing CI builds where flake8 or other code style checks would fail. We use pre-commit to run flake8 and black before allowing a commit to proceed. Some projects have a pre-commit configuration to use right out of the box (e.g., black https://github.com/ambv/black#version-control-integration).

Listener: You don't need that (pattern)

John Tocher PyCon AU Talk Called "You don't need that” - by Christopher Neugebauer, it was an interesting take on why with a modern and powerful language like python, you may not need the conventionally described design patterns, ala the "Gang of four".

#94 Why don't you like notebooks?

Sep 6, 2018 00:23:49


Sponsored by DigialOcean -- pythonbytes.fm/digitalocean

Brian #1: Python Patterns

@brandon_rhodes vs GOF

Michael #2: Arctic: Millions of rows a sec (time data)

Arctic is a high-performance datastore for numeric data. It supports Pandas, numpy arrays and pickled objects out-of-the-box, with pluggable support for other data types and optional versioning. Arctic can query millions of rows per second per client, achieves ~10x compression on network bandwidth, ~10x compression on disk, and scales to hundreds of millions of rows per second per MongoDB instance. Arctic has been under active development at Man AHL since 2012. Super fast, some latency numbers: 1xDay Data 4ms for 10k rows, vs 2,210 ms from SQL Server) Tick Data 1s for 3.5 MB (Python) or 15 MB (Java) vs 15-40sec from “other tick” Versioned data Built on MongoDB Slides Based on pandas Tested with pytest

Brian #3: PyCon Australia videos

How To Publish A Package On PyPI Mark Smith @judy2k

Michael #4: GAE: Introducing App Engine Second Generation runtimes and Python 3.7

Today, Google Cloud is announcing the availability of Second Generation App Engine standard runtimes, a significant upgrade to the platform that allows you to easily run web apps using up-to-date versions of popular languages, frameworks and libraries. Python 3.7 is one of the new Second Generation runtimes that we announced at Cloud Next. Based on technology from the gVisor container sandbox, these Second Generation runtimes eliminate many previous App Engine restrictions, giving you the ability to write portable web apps and microservices that take advantage of App Engine's unique auto-scaling, built-in security and pay-per-use billing model. This new runtime allows you to take advantage of Python's vibrant ecosystem of open-source libraries and frameworks. While the Python 2 runtime only allowed the use of specific versions of whitelisted libraries, Python 3 supports arbitrary third-party libraries, including those that rely on C code and native extensions. Just add Django 2.0, NumPy, scikit-learn or your library of choice to a requirements.txt file. App Engine will install these libraries in the cloud when you deploy your app.

Brian #5: I don’t like notebooks


Michael #6: PEP 8000 -- Python Language Governance Proposal Overview

This PEP provides an overview of the selection process for a new model of Python language governance in the wake of Guido's retirement. Once the governance model is selected, it will be codified in PEP 13. PEPs in the lower 8000s describe the general process for selecting a governance model. PEP 8001 - Python Governance Voting Process PEP 8002 - Open Source Governance Survey PEPs in the 8010s describe the actual proposals for Python governance. PEP 8010 - The BDFL Governance Model PEP 8011 - The Council Governance Model PEP 8012 - The Community Governance Model


Free Brian Granger ACM webcast on Jupyter Friday TIOBE jump to #3: https://www.tiobe.com/tiobe-index/

#93 Looking like there will be a PyBlazor!

Aug 31, 2018 00:24:15


Sponsored by DataDog -- pythonbytes.fm/datadog

Brian #1: Replacing Bash Scripting with Python.

reading & writing files CLI’s and working with stdin, stdout, stderr Path and shutil replacing sed, grep, awk, with regex running processes dealing with datetime see also: regex search and replace example scripts

Michael #2: PyIodide

Scientific Python in the browser ALL of CPython (allowed in the browser) NumPy MatPlotLib ... Project by Mozilla We asked “Will there be a PyBlazor?” just two weeks ago. I think we are on a path…

Brian #3: The subset of reStructuredText worth committing to memory

A lot of Python packages document with reStructuredText, a lot of reStructuredText tutorials are overwhelming. This post is the answer. paragraphs are with two newlines headings use a weird underlined method of above and below and =, -, and ~ bulleted lists work with asterisks but spacing is important italics and bold are with one or two surrounding asterisks inline code uses two backticks links and code snippets are weird and I have to always look this up, as with images, and internal references. so I’ll bookmark this link

Michael #4: bandit

via Anthony Shaw Bandit is a tool designed to find common security issues in Python code. To do this Bandit processes each file, builds an AST from it, and runs appropriate plugins against the AST nodes. Once Bandit has finished scanning all the files it generates a report. Issues detected: B312 telnetlib B307 eval B110 try_except_pass B602 subprocess_popen_with_shell_equals_true

Brian #5: Learn Python 3 within Jupyter Notebooks

just fun Also shows how to run pytest in a cell.

Michael #6: detect-secrets

An enterprise friendly way of detecting and preventing secrets in code. From Yelp detect-secrets is an aptly named module for (surprise, surprise) detecting secrets within a code base. However, unlike other similar packages that solely focus on finding secrets, this package is designed with the enterprise client in mind: providing a backwards compatible, systematic means of: Preventing new secrets from entering the code base, Detecting if such preventions are explicitly bypassed, and Providing a checklist of secrets to roll, and migrate off to a more secure storage. Allows you to set a baseline set it up as a git commit hook

#92 Will your Python be compiled?

Aug 25, 2018 00:26:57


Sponsored by Digital Ocean -- pythonbytes.fm/digitalocean

Brian #1: IEEE Survey Ranks Programming Languages

via Martin Rowe, @measureentblue Python on top. Was last year also, but this year it’s on top even for embedded. Some people dispute the numbers but I believe it. Projects contributing to the rise of Python in embedded: MicroPython CircuitPython micro:bit Mu

Michael #2: MyPyC

Thread on Python-Dev: Use of Cython It'd be *really nice to at least be able to write some of the C API tests directly in Cython rather than having to fiddle about with splitting the test between the regrtest parts that actually define the test case and the extension module parts that expose the interfaces that we want to test.* Later in the thread, Yury Selivanov dropped a bomb shell. Speaking of which, Dropbox is working on a new compiler they call "mypyc". mypyc will compile type-annotated Python code to an optimized C. Essentially, mypyc will be similar to Cython, but mypyc is a subset of Python, not a superset. Interfacing with C libraries can be easily achieved with cffi. Being a strict subset of Python means that mypyc code will execute just fine in PyPy. They can even apply some optimizations to it eventually, as it has a strict and static type system.

Brian #3: Beyond Interactive: Notebook Innovation at Netflix

Netflix is doing some very cool things with Jupyter, and sharing much of it through open source projects. Netflix has growing their use of Jupyter notebooks for many data related roles: business, data, & quantitative analysts algorithm, analytics, & data engineers data, machine learning, & research scientists All of these roles have common needs that are solved by Jupyter and related projects: data exploration, preparation, validation, and productionalization (is that a word?) To help solve their use cases and make notebooks even easier to use for everyone at Netflix, they’ve started many open source projects that can be used by non-Netflix folks as well: “nteract is a next-gen React-based UI for Jupyter notebooks.” “Papermill is a library for parameterizing, executing, and analyzing Jupyter notebooks. “ “Commuter is a lightweight, vertically-scalable service for viewing and sharing notebooks.” “Titus is a container management platform that provides scalable and reliable container execution and cloud-native integration with Amazon AWS. “ There’s a follow-on post that discusses how Netflix is scheduling notebook execution: Scheduling Notebooks

Michael #4: How to create a Windows Service in Python

We have spoken about how to run Python script as systemd service Here’s the Windows edition Run Python code on boo When logged out or logged in as another user As a restricted or different account Based on pywin32 (very little documentation) Derive from a given base class then override the three main methods: def start(self) : if you need to do something at the service initialization. A good idea is to put here the initialization of the running condition def stop(self) : if you need to do something just before the service is stopped. A good idea is to put here the invalidation of the running condition def main(self) : your actual run loop. Just create a loop based on your running condition

Brian #5: An Overview of Packaging for Python

Started from an essay by Mahmoud Hashemi, @mhashemi Now part of PyPA documentation Different techniques and tools for different types of Python projects modules packages source distributions wheels binary distributions applications this is the hairy part where a bullet point summary just won’t be enough. :)

Michael #6: PEP 505 -- None-aware operators

Several modern programming languages have so-called "null-coalescing" or "null- aware" operators, including C# and Swift. These operators provide syntactic sugar for common patterns involving null references. Why not Python? Two cases: The "null-coalescing" operator: To replace inline conditionals such as this value if value is not None else "MISSING" can now be just value ?? "MISSING" The "null-aware member access" operator: Chain calls into a fluent interface without testing for None: return user?.orders.first()?.name would replace this if user is None: return None first_order = user.orders.first() if first_order is None: return None return first_order.name


PyCascades: https://2019.pycascades.com/ Test and Code episode with DHH: http://testandcode.com/45

#91 Will there be a PyBlazor?

Aug 15, 2018 00:20:28


Sponsored by Datadog pythonbytes.fm/datadog

Brian #1: What makes the Python Cool

Shankar Jha “some of the cool feature provided by Python” The Zen of Python: import this XKCD: import antigravity Swapping of two variable in one line: a, b = b, a Create a web server using one line: python -m http.server 8000 collections itertools Looping with index: enumerate reverse a list: list(reversed(a_list)) zip tricks list/set/dict comprehensions Modern dictionary pprint _ when in interactive REPL Lots of great external libraries

Michael #2: Django 2.1 released

The release notes cover the smorgasbord of new features in detail, the model “view” permission is a highlight that many will appreciate. Django 2.0 has reached the end of mainstream support. The final minor bug fix release (which is also a security release), 2.0.8, was issued today. Features model “view” feature: This allows giving users read-only access to models in the admin. The new [ModelAdmin.delete_queryset()](https://docs.djangoproject.com/en/2.1/ref/contrib/admin/#django.contrib.admin.ModelAdmin.delete_queryset) method allows customizing the deletion process of the “delete selected objects” action. You can now override the default admin site. Lots of ORM features Cache: The local-memory cache backend now uses a least-recently-used (LRU) culling strategy rather than a pseudo-random one. Migrations: To support frozen environments, migrations may be loaded from .pyc files. Lots more

Brian #3: Awesome Python Features Explained Using Harry Potter

Anna-Lena Popkes Initial blog post 100 Days of code, with a Harry Potter universe bent. Up to day 18 so far.

Michael #4: Executing Encrypted Python with no Performance Penalty

Deploying Python in production presents a large attack surface that allows a malicious user to modify or reverse engineer potentially sensitive business logic. This is worse in cases of distributed apps. Common techniques to protect code in production are binary signing, obfuscation, or encryption. But, these techniques typically assume that we are protecting either a single file (EXE), or a small set of files (EXE and DLLs). In Python signing is not an option and source code is wide open. requirements were threefold: Work with the reference implementation of Python, Provide strong protection of code against malicious and natural threats, Be performant both in execution time and in stored space This led to a pure Python solution using authenticated cryptography. Created a .pyce file that is encrypted and signed Customized import statement to load and decrypt them Implementation has no overhead in production. This is due to Python's in-memory bytecode cache.

Brian #5: icdiff and pytest-icdiff

icdiff: “Improved colored diff” Jeff Kaufman pytest-icdiff: “better error messages for assert equals in pytest” Harry Percival

Michael #6: Will there be a PyBlazor?

The .NET guys, and Steve Sanderson in particular, are undertaking an interesting project with WebAssembly. WebAssembly (abbreviated Wasm) is a binary instruction format for a stack-based virtual machine. Wasm is designed as a portable target for compilation of high-level languages like C/C++/Rust, enabling deployment on the web for client and server applications. Works in Firefox, Edge, Safari, and Chrome Their project, Blazor, has nearly the entire .NET runtime (AKA the CLR) running natively in the browser via WebAssembly. This is notable because the CLR is basically pure C code. What else is C code? Well, CPython! Includes Interpreted and AOT mode: Ahead-of-time (AOT) compiled mode: In AOT mode, your application’s .NET assemblies are transformed to pure WebAssembly binaries at build time. Being able to run .NET in the browser is a good start, but it’s not enough. To be a productive app builder, you’ll need a coherent set of standard solutions to standard problems such as UI composition/reuse, state management, routing, unit testing, build optimization, and much more. Mozilla called for this to exist for Python, but sadly didn’t contribute or kick anything off at PyCon 2018: https://www.youtube.com/watch?v=ITksU31c1WY Gary Bernhardt’s Birth and Death of JavaScript video is required pre-reqs as well (asm.js).

Extras and personal info:


Building data-driven web apps course is being well received Guido van Rossum: Python 3 retrospective — Guido’s final presentation as BDFL

#90 A Django Async Roadmap

Aug 7, 2018 00:25:18


Sponsored by Digital Ocean: pythonbytes.fm/digitalocean

Brian #1: Reproducible Data Analysis in Jupyter

Amazing series of videos by Jake Vanderplas Exploring a data set through visualization in a Jupyter notebook There’s a lot of dense material there, from saving datasets to files, plotting in the notebook as opposed to outside in a separate window, using resampling, …

Michael #2: PySimpleGUI - For simple Python GUIs

Via Mike Barnett Looking to take your Python code from the world of command lines and into the convenience of a GUI? Have a Raspberry Pi with a touchscreen that's going to waste because you don't have the time to learn a GUI SDK? Look no further, you've found your GUI package. Based on tkinter No dependencies (outside of Python itself): pip install PySimpleGUI Python3 is required to run PySimpleGUI. It takes advantage of some Python3 features that do not translate well into Python2. Looking to help? → Port to other graphic engines. Hook up the front-end interface to a backend other than tkinter. Qt, WxPython, etc.

Brian #3: Useful tricks you might not know about Git stash

git stash save - Stash the changes in a dirty working directory away git stash apply - re-applies your changes after you do whatever you need to to your directory, like perhaps pull. Lots of neat things to do with stash you can add a message so the stashed content has a nice label -u will include untracked files when saving. git stash branch [HTML_REMOVED] stash@{1} will create a new branch with the latest stash, and then deletes the latest stash Lots of other nice tricks in the article See also: git-stash in git-scm book

Michael #4: A Django Async Roadmap

via Andrew Godwin, from Django Channels Thinks that the time has come to start talking seriously about bringing async functionality into Django itself Open for public feedback The goal is to make Django a world-class example of what async can enable for HTTP requests, such as: Doing ORM queries in parallel Allowing views to query external APIs without blocking threads Running slow-response/long-poll endpoints alongside each other efficiently Bringing easy performance improvements to any project that spends a majority of time blocking on databases or sockets (which is most projects!) Imperative that we keep Django backwards-compatible with existing code Why now? Django 2.1 will be the first release that only supports Python 3.5 and up, and so this provides us the perfect place to start working on async-native code

Brian #5: pydub

“Manipulate audio with a simple and easy high level interface” Really clean use of operators. from pydub import AudioSegment # also handles lots of other formats song = AudioSegment.from_mp3("never_gonna_give_you_up.mp3") # pydub does things in milliseconds ten_seconds = 10 * 1000 first_10_seconds = song[:ten_seconds] last_5_seconds = song[-5000:] # boost volume by 6dB beginning = first_10_seconds + 6 # reduce volume by 3dB end = last_5_seconds - 3 # Concatenate audio (add one file to the end of another) without_the_middle = beginning + end also: crossfade repeat fade switch formats add metadata tags save with a specific bitrate

Michael #6: Molten: Modern API framework

molten is a minimal, extensible, fast and productive framework for building HTTP APIs with Python. Heavy use of type annotations Officially supports Python 3.6 and later Request Validation: molten can automatically validate requests according to predefined schemas, ensuring that your handlers only ever run if given valid input Dependency Injection: Write clean, decoupled code by leveraging DI. Still experimental at this stage.

#89 A tenacious episode that won't give up

Aug 4, 2018 00:28:50


Python Bytes 89

Sponsored by Datadog -- pythonbytes.fm/datadog

Brian #1: tenacity

“Tenacity is a general-purpose retrying library to simplify the task of adding retry behavior to just about anything.” Example (Also, nice Trollhunters reference): import random from tenacity import retry @retry def do_something_unreliable(): if random.randint(0, 10) > 1: raise IOError("Broken sauce, everything is hosed!!!") else: return "Awesome sauce!" # Toby says this frequently print(do_something_unreliable()) Features: Generic Decorator API Specify stop condition (i.e. limit by number of attempts) Specify wait condition (i.e. exponential backoff sleeping between attempts) Customize retrying on Exceptions Customize retrying on expected returned result Retry on coroutines

Michael #2: Why is Python so slow?

Answer this question: When Python completes a comparable application 2–10x slower than another language, why is it slow and can’t we make it faster? Here are the top theories: “It’s the GIL (Global Interpreter Lock)” “It’s because its interpreted and not compiled” “It’s because its a dynamically typed language” “It’s the GIL” Modern computers come with CPU’s that have multiple cores For web apps, it might not matter (e.g. https://training.talkpython.fm/ has 16 worker processes, https://talkpython.fm/ has 8 workers) “It’s because its an interpreted language” I hear this a lot and I find it a gross-simplification of the way CPython actually works. JIT vs. NonJIT is interesting (startup time too) “It’s because its a dynamically typed language” In a “Statically-Typed” language, you have to specify the type of a variable when it is declared. Those would include C, C++, Java, C#, Go. In a dynamically-typed language, there are still the concept of types, but the type of a variable is dynamic. Not having to declare the type isn’t what makes Python slow It’s this design that makes it incredibly hard to optimize Python. Conclusion Python is primarily slow because of its dynamic nature and versatility. It can be used as a tool for all sorts of problems, where more optimized and faster alternatives are probably available.

Brian #3: Keynoting with Mu

David Beazley gave his EuroPython talk/demo “Die Threads” using Mu. Article also notes that simple tools are great not just for learning, but for teaching, as the extra clutter of a full power editor doesn’t distract too much.

Michael #4: A multi-core Python HTTP server (much) faster than Go (spoiler: Cython)

Exploring the question, “So, I’ve heard Python is slow… is it?” A multi-core Python HTTP server that is about 40% to 110% faster than Go can be built by relying on the Cython language and LWAN C library. Just a proof of concept validates the possibility of high performance system programming in the Cython language. Primarily interesting as a highlight of Cython Cython is both an optimizing static compiler and a hybrid language. It mainly gives the ability to: write Python code that can call back and forth from and to C/C++; add static typing using C declarations to Python code in order to boost performance; release the GIL in some code sections. Cython generates very efficient C code, which is then compiled into a module that Python can import. So it is an ideal language for wrapping external C libraries, and for developing C modules that speed up the execution of Python code. However, all experiments we are aware that rely on Cython for system programming fail short in at least two ways: as soon as some Python code is invoked (as opposed to pure Cython cdef code), performance degrades by one or two orders of magnitude; benchmarks are most of the time provided for single core execution only, which is somehow unfair considering Golang's ability to scale up on multiple cores.

Brian #5: PyCharm 2018.2 beefs up pytest support

Honestly, I’m super excited about this release to help my team navigate to all of the fixtures I create on a regular basis. This is the release I’ve been waiting for. I can now fully utilize the power of pytest from PyCharm Here’s the few things that were missing that now work great: Autocomplete fixtures from various sources Quick documentation and navigation to fixtures Renaming a fixture from either the definition or a usage Support for pytest’s parametrize See also: PyCharm 2018.2 and pytest Fixtures But if you really want to understand fixtures quickly, read chapters 3 and 4 of the pytest book.

Michael #6: XAR for Facebook

XAR lets you package many files into a single self-contained executable file. This makes it easy to distribute and install. A .xar file is a read-only file system image which, when mounted, looks like a regular directory to user-space programs. This requires a one-time installation of a driver for this file system (SquashFS). There are two primary use cases for XAR files. Simply collecting a number of files for automatic, atomic mounting somewhere on the filesystem. By making the XAR file executable and using the xarexec helper, a XAR becomes a self-contained package of executable code and its data. A popular example is Python application archives that include all Python source code files, as well as native shared libraries, configuration files, other data. Advantages of XAR for Python usage SquashFS looks like regular files on disk to Python. This lets it use regular imports which are better supported by CPython. SquashFS looks like regular files to your application, too. You don't need to use pkg_resources or other tricks to access data files in your package. SquashFS with Zstandard compression saves disk space, also compared to a ZIP file. SquashFS doesn't require unpacking of .so files to a temporary location like ZIP files do. SquashFS is faster to start up than unpacking a ZIP file. You only need to mount the file system once. Subsequent calls to your application will reuse the existing mount. SquashFS only decompresses the pages that are used by the application, and decompressed pages are cached in the page cache. SquashFS is read-only so the integrity of your application is guaranteed compared to using virtualenvs or unpacking to a temporary directory. Performance is interesting too



numpy 1.15.0 just released recently. Switched testing to pytest.


SciPy 2018 videos are out PyOhio 2018 videos are out Call for papers at PyCon Canada in Toronto PyBay 2018 conference in a few weeks My latest course, Building data-driven web apps with Pyramid and SQLAlchemy, is out!

#88 Python has brought computer programming to a vast new audience

Jul 27, 2018 00:23:08


Sponsored by Datadog: pythonbytes.fm/datadog

Brian #1: Documenting Python Code: A Complete Guide

Article describes the why you should document, comments vs docstrings vs separate documentation. Let’s zoom in on comments, because I don’t think many people get how to use comments effectively. Commenting comments are for you and other developers to help maintain the code. They can also help users understand your mental model and design. the source is often used as documentation if the other docs are lacking or confusing or incomplete. Comments start with # and are not accessible at runtime. Comment uses: planning and reviewing explaining intent explaining complicated algorithms tagging TODO, BUG, or FIXME sections. Article includes some good tips: keep comments as close to code it’s describing as possible. don’t try to format it with ascii alignment or whatever minimal, most of your code shouldn’t need comments. remove planning comments when they aren’t needed any more Docstrings: available at runtime via help(), thing.__doc__, and through many code completion tools in IDEs Can be used at function, class, module, and package level. Should help the user as if they don’t have the source available to look at. Also covered: Commenting with type hints How to use docstrings. Docstring standard practices and formatting. Necessary elements of documenting projects Using tools like Sphinx, MkDocs, etc.

Michael #2: Security vulnerability alerts for Python at Github

Last year, GitHub released security alerts that track security vulnerabilities in Ruby and JavaScript packages. They have identified millions of vulnerabilities and have prompted many patches. As of this week, Python users can now access the dependency graph and receive security alerts whenever their repositories depend on packages with known security vulnerabilities. See it under insights > dependency graph Using it: Ensure that you have checked in a requirements.txt or Pipfile.lock file inside of repositories that have Python code. Give access to private repos

Brian #3: How virtual environment libraries work in Python

“Have you ever wondered what happens when you activate a virtual environment and how it works internally? Here is a quick overview of internals behind popular virtual environments, e.g., virtualenv, virtualenvwrapper, conda, pipenv.” “When Python starts its interpreter, it searches for the site-specific directory where all packages are stored. The search starts at the parent directory of a Python executable location and continues by backtracking the path (i.e., looking at the parent directories) until it reaches the root directory. To determine if it's a site-specific directory, Python looks for the os.py module, which is a mandatory requirement by Python in order to work.” virtualenv creates a directory with some bin files, and the lib that mostly points to the parent Python site versions using symbolic links. Python 3.3, with PEP 405, added a pyvenv.cfg file that allows the interpreter itself to be a symbolic link, as well as an option to use system site packages, saving on lots of symbolic links at the start.

Michael 4:** Qt for Python available at PyPi

Announcement: Finally the technical preview of Qt for Python is available at the Python Package Index (PyPI). pip install PySide2 Try it at one of the demo apps http://blog.qt.io/blog/2018/05/04/hello-qt-for-python/

Brian #5: Learning (not) to Handle Exceptions

Understanding exceptions is important even if you never throw your own, since much of Python and 3rd party packages utilize them quite a bit. Try to catch specific exceptions. Don’t have except: catch everything. If you really need to intercept any exception, consider re-raising it with raise Some tips with handling multiple exceptions. finally can be used for stuff that needs to run regardless of an exception or not else runs if no exception occurs. You can use both finally and else Also: tracebacks custom exceptions best practices adding arguments to exceptions

Michael #6: Python has brought computer programming to a vast new audience

Features quotes from Guido van Rossum Interesting history Seeing with “outside eyes” is pretty novel and something we don’t often get to do. More about the meteoric growth of Python Warnings about AI in the hands of half educated novices

#87 Guido van Rossum steps down

Jul 17, 2018 00:33:20


Sponsored by Datadog: pythonbytes.fm/datadog

Special guests:

Brett Cannon: @brettsky Carol Willing: @WillingCarol

The topic: Guido steps down.

The announcement: Transfer of Power

Now that PEP 572 is done, I don't ever want to have to fight so hard for a PEP and find that so many people despise my decisions.

I would like to remove myself entirely from the decision process. I'll still be there for a while as an ordinary core dev, and I'll still be available to mentor people -- possibly more available. But I'm basically giving myself a permanent vacation from being BDFL, and you all will be on your own.

After all that's eventually going to happen regardless -- there's still that bus lurking around the corner, and I'm not getting younger... (I'll spare you the list of medical issues.)

I am not going to appoint a successor.

So what are you all going to do? Create a democracy? Anarchy? A dictatorship? A federation?

I'm not worried about the day to day decisions in the issue tracker or on GitHub. Very rarely I get asked for an opinion, and usually it's not actually important. So this can just be dealt with as it has always been.

The decisions that most matter are probably - How are PEPs decided - How are new core devs inducted

We may be able to write up processes for these things as PEPs (maybe those PEPs will form a kind of constitution). But here's the catch. I'm going to try and let you all (the current committers) figure it out for yourselves.

Note that there's still the CoC -- if you don't like that document your only option might be to leave this group voluntarily. Perhaps there are issues to decide like when should someone be kicked out (this could be banning people from python-dev or python-ideas too, since those are also covered by the CoC).

Finally. A reminder that the archives of this list are public ( https://mail.python.org/pipermail/python-committers/ ) although membership is closed (limited to core devs).

I'll still be here, but I'm trying to let you all figure something out for yourselves. I'm tired, and need a very long break.

--Guido van Rossum (python.org/~guido)

Why it happened?

e.g. PEP 572 burn-out/treatment View the twitter thread on this announcement tweet

What this means?

“keep calm and keep coding”

Is there a danger of Python losing its momentum from this?

What comes next?

current state of the governance discussion

What needs to be done to reduce this kind of pressure?

Brett’s talk about setting open source expectations at PyCascades is very relevant.

#86 Make your NoSQL async and await-able with uMongo

Jul 13, 2018 00:26:04


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Special guest Bob Belderbos: @bbelderbos

Brian #1: responses

“A utility for mocking out the Python Requests library.” From Sentry


import responses import requests @responses.activate def test_simple(): responses.add(responses.GET, 'http://twitter.com/api/1/foobar', json={'error': 'not found'}, status=404) resp = requests.get('http://twitter.com/api/1/foobar') assert resp.json() == {"error": "not found"} assert len(responses.calls) == 1 assert responses.calls[0].request.url == 'http://twitter.com/api/1/foobar' assert responses.calls[0].response.text == '{"error": "not found"}'

Bob #2: 29 common beginner Python errors on one page

Decision trees / graphics are nice to digest and concise, it wraps a lot of experience on one slide Knowing about common errors can safe you a lot of time (the guide I wish I had when I started coding in Python) Reminded me of struggles I had when I started in Python, for example TypeErrors when converting suspected ints to strings, regexes before discovering raw strings It made me think of related issues newer Pythonistas face, for example “I am reading a file but getting no input” can be translated to “I am looping over a generator for the second time and don’t get any output” Made me realize that some things are subtle, like comparing 3 == “3” or require good knowledge of stdlib (sorted returning new sequence vs inplace sort() for example) Made me reflect on how much hand holding you would give your students when teaching. Part of the learning is in the struggle. About the source, I like seeing Python being taught in all different kind of domains, in this case biology.

Michael #3: μMongo

μMongo is a Python MongoDB ODM. It inception comes from two needs: the lack of async ODM the difficulty to do document (un)serialization with existing ODMs. a few design choices: Stay close to the standards MongoDB driver to keep the same API when possible: use find({"field": "value"}) like usual but retrieve your data nicely OO wrapped ! Work with multiple drivers (PyMongo, TxMongo, motor_asyncio and mongomock for the moment) Tight integration with Marshmallow serialization library to easily dump and load your data with the outside world i18n integration to localize validation error messages Free software: MIT license Test with 90%+ coverage ;-) async / await support through Motor

Brian #4: Basic Statistics in Python: Descriptive Statistics

Cool use of Python to teach basic statistics topics. Includes code snippets to explain different concepts like min, max, mean, median, mode, … However, after you understand the math, DON’T write your own functions. use built in Python functions and the statistics library built in to Python (or numpy if you are on older Python versions).

Example from article:

sum_score = sum(scores) num_score = len(scores) avg_score = sum_score/num_score avg_score >>> 87.8884184721394

Using built in:

>>> x = (2, 2, 3, 100) >>> min(x), max(x) (2, 100) >>> import statistics as s >>> s.mean(x), s.median(x), s.mode(x) (26.75, 2.5, 2) >>> s.pstdev(x), s.pvariance(x) (42.29287765097097, 1788.6875) >>> s.stdev(x), s.variance(x) (48.835608593184, 2384.9166666666665)

Bob #5: Strings and Character Data in Python

Everything you need to know to work with strings and more … Similar to that great itertools article you shared some weeks ago: exhaustive overview Nice re-usable code snippets and explanation of basic concepts, ideal for beginners but you likely will get something out of it, few useful bites: Instead of try int(…) except, you can use isdigit() on a string You can use isspace() to see if all characters of a nonempty string are whitespace characters ( ' ', tab '\t', and newline '\n') It’s easy to make a header in your Python scripts: >>>> 'bar'.center(10, '-') '---bar----' - Replace up till n occurrences: >>>> 'foo bar foo baz foo qux'.replace('foo', 'grault', 2) 'grault bar grault baz foo qux' - Strip multiple characters from both ends of a string: >>>> 'www.realpython.com'.strip('w.moc') 'realpython' - Add leading padding to a string with `zfill`: >>>> '42'.zfill(5) '00042' This also reminded me of Python’s polymorphism, for example str.find and str.index work on both strings as well as lists >>> 'foo bar foo baz foo qux'.index('baz') 12 >>> 'foo bar foo baz foo qux'.split().index('baz') 3 >>> 'foo bar foo baz foo qux'.count('foo') 3 >>> 'foo bar foo baz foo qux'.split().count('foo') 3

Michael #6: PEP 572: Assignment expressions accepted

Whoa, check out that twitter conversation Splits 2 statements into an expressions (so they can be part of list comprehensions, etc). Not sure I like it but here you go:


# Handle a matched regex if (match := pattern.search(data)) is not None: ...

Contrast old and new:

# old if self._is_special: ans = self._check_nans(context=context) if ans: return ans # new if self._is_special and (ans := self._check_nans(context=context)): return ans

Our news:

Michael: New course coming! Data-driven web apps in Pyramid Bob: Be sure to visit PyBites Code Challenges Brian: More Test and Code episodes coming!

#85 Visually debugging your Jupyter notebook

Jul 3, 2018 00:24:40


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Brian #1: the state of type hints in Python

“Therefore, type hints should be used whenever unit test are worth writing.” Type hints, especially for function arguments and return values, help make your code easier to read, and therefore, easier to maintain. This includes refactoring, allowing IDEs to help with code completion, and allow linters to find problems. For CPython No runtime type inference happens. No performance tuning allowed. Of course, third party packages are not forbidden to do so. Non-comment type annotations are available for functions in 3.0+ Variable annotations for 3.6+ In 3.7, you can postpone evaluation of annotations with: from __future__ import annotations Interface stub files .pyi files, are allowed now, but this is extra work and code to maintain. typeshed has types for standard library plus many popular libraries. How do deal with multiple types, duck typing, and more discussed. A discussion of type generation and checking tools available now, including mypy See also: Stanford Seminar - Optional Static Typing for Python - Talk by Guido van Rossum Interesting discussion that starts with a bit of history of where mypy came from.

Michael #2: Django MongoDB connector

Via Robin on Twitter Use MongoDB as the backend for your Django project, without changing the Django ORM. Use Django Admin to access MongoDB Use Django with MongoDB data fields: Use MongoDB embedded documents and embedded arrays in Django Models. Connect 3rd party apps with MongoDB: Apps like Django Rest Framework and Viewflow app that use Django Models integrate easily with MongoDB. Requirements: Python 3.6 or higher. MongoDB 3.4 or higher. Example inner_qs = Blog.objects.filter(name__contains='Ch').values('name') entries = Entry.objects.filter(blog__name__in=inner_qs)

Brian #*3: Python Idioms: Multiline Strings*

or “How I use dedent” Example: def create_snippet(): code_snippet = textwrap.dedent("""\ int main(int argc, char* argv[]) { return 0; } """) do_something(code_snippet)

Michael #4: Flaskerizer

A program that automatically creates Flask apps from Bootstrap templates Bootstrap templates from websites like https://Bootstrapmade.com/ and https://startBootstrap.com are a fast way to get very dynamic website up and running Bootstap templates typically don't work "out of the box" with the python web framework Flask and require some tedious directory building and broken link fixing before being functional with Flask. The Flaskerizer automates the necessary directory building and link creation needed to make Bootstrap templates work "out of the box" with Flask. Queue black turtleneck!

Brian #*5: Learn Python the Methodical Way

From the article: Make your way through a tutorial/chapter that teaches you some discrete, four-to-six-step skill. Write down those steps as succinctly and generically as possible. Put the tutorial/chapter and its solutions away. Build your project from scratch, peeking only when you’re stuck. Erase what you built. Do the project again. Drink some water. Erase what you built and do it again. A day or two later, delete your work and do it again – this time without peeking even once. Erase your work and do it again. The notion of treating code like you treat creative writing with rough drafts and sometimes complete do-overs is super liberating. You’ll be surprised how fast you can do something the second time, the third time, the fourth time. And it’s very gratifying.

Michael #6: PixieDebugger

The Visual Python Debugger for Jupyter Notebooks You’ve Always Wanted Jupyter already supports pdb for simple debugging, where you can manually and sequentially enter commands to do things like inspect variables, set breakpoints, etc. Check out the video to get a good idea of its usage: https://www.youtube.com/watch?v=Z-tPeEkVqjk

#84 Vibora web framework: It's fast, async, and means viper

Jun 28, 2018 00:26:29


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Special guest Nina Zakharenko (@nnja) is a Cloud Developer Advocate at Microsoft!

Brian #1: Correcting Documentation for a Deployed Python Package

"A clever way to release new documentation without releasing a new package that might confuse your user base.” Upload changes to pypi without bumping the version by using post release version numbers: 0.3.2 => 0.3.2.post1 Prevent documentation issues by using restview --long-description before uploading. (or use md and really any md converter)


Packaging Python Projects : revamped pypa tutorial that works pretty darned well. Using TestPyPI : more detailed instructions on testing with TestPyPI before pushing to final spot.

Nina #2: Flask Mega Tutorial

Amazing resource for developers who’d like to learn about building web applications with Flask in Python. Covers important topics like databases, internationalization, and dates and times. Three full sections on deploying your web app using Linux, Heroku, or containers. VS Code IDE has great Flask support. Try Azure with a $200 credit to deploy Flask apps.

Michael #3: 10 common security gotchas in Python and how to avoid them

Article by Anthony Shaw (congrats on being a 2018 PSF Fellow) The 10 topics Input injection (see little bobby tables) Use an ORM (db) or shlex module to escape input correctly (process) Parsing XML Assert statements Timing attacks A polluted site-packages or import path Temporary files Using yaml.load Pickles Using the system Python runtime and not patching it Not patching your dependencies

Brian #4: pre-commit “A framework for managing and maintaining multi-language pre-commit hooks.”

Describe pre-commit actions using yaml. Lots of projects already use it, like black. Does the work for you so you don’t have to read up on git commit hooks and such. Test out hooks ahead of time with pre-commit run [HTML_REMOVED]

Nina #5: Python 3.7 release and PSF board members

Python 3.7 has just been released today! 🎉 New Features Overview Blog Post Debugging improvements - new breakpoint() built-in function allows you to start an interactive session, like IPython. 4 New PSF Board members elected - Congratulations to them! Anna Ossowski Christopher Neugebauer Jeff Triplett Katie McLaughlin

Michael #6: Vibora web framework

A new speedy web framework Only 14 days old, but has 21 contributors and 2k stars Just like Flask: Vibora APIs were heavily inspired by the awesome Flask. Schemas validation, template engine, sessions and many more features were written from scratch to provide great performance along with an elegant async interface. Vibora also take advantage of multiple CPU cores by default thanks to the multi-processed architecture. Uvloop and other C speed-ups are used when available. Virtual Hosts: Maybe you have different domains and you want to host them all with a single Vibora application. Deployment has its own HTTP app server Docs need help

Our news and extras:

Qt for Python Webinar via Fredrik Averpil

#83 from __future__ import braces

Jun 22, 2018 00:29:22


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Special guest: Cristian Medina, @tryexceptpass

Brian #1: Code with Mu: a simple Python editor for beginner programmers.

Found out about this from Nicholas Tollervey (@ntoll) Built by an impressive list of people: https://codewith.mu/en/ thanks Beginning code editor that also works with Adafruit and micro:bit boards. From about: Less is More. Mu has only the most essential features, so users are not intimidated by a baffling interface. Tread the Path of Least Resistance. Whatever the task, there is always only one obvious way to do it with Mu. Keep it Simple. It's quick and easy to learn Mu ~ complexity impedes a novice programmer's first steps. Have fun! Learning should inspire fun ~ Mu helps learners quickly create and test working code.

Cris #2: Python parenthesis primer

Good for beginners. Covers the main uses of parenthesis, curly brackets and square brackets. Including code examples. Parenthesis Callables. Operation prioritization. Tuples. Generator expressions. Skirting the indentation rules. Square brackets Lists and their comprehensions. Indexing. Slices. Comments also mention type hints. Curly braces Dictionaries and comprehensions. Sets and comprehensions. F-strings. str.format. Try to import braces from __future__: >>> from __future__ import braces File "[HTML_REMOVED]", line 1 SyntaxError: not a chance

Michael #3: Python for Qt Released

The Qt Company happy to announce the first official release of Qt for Python (Pyside2). v5.11 We hope we can receive plenty of feedback on what works and what does not. We want to patch early and often. Eventually the aim is to release Qt for Python 5.12 without the Tech Preview flag. Started two years ago with this announcement from Lars. Get Qt for Python: The release supports Python 2.7, 3.5 & 3.6 on the three main desktop platforms. The packages can be obtained from download.qt.io or using pip with pip install --index-url=https://download.qt.io/official_releases/QtForPython/ pyside2

Brian #4: Itertools in Python 3, By Example

by David Amos (@somacdivad) Iterators and generators are awesome. Nice discussion of lazy evaluation and iterator algebra. Naive approach using list can blow up in memory and time if you use huge datasets. Examples: combinations, combinations_with_replacement, permutations count, repeat, cycle, accumulate product, tee, islice, chain filterfalse, takewhile, dropwhile

Cris #5: Python Sets and Set Theory

Nice primer on sets in python and a little set theory. How to build them: set() vs {``'``value1``'``, '``value2``'``} vs {name for name in name_list} Membership tests (which are O(1)) Set operations Union Intersection Difference Symmetric Difference Frozen sets

Michael #6: Python 3.7 is coming soon!

Schedule 3.7.0 candidate 1: 2018-06-12 3.7.0 final: 2018-06-27 What’s new / changed? New syntax features: PEP 563, postponed evaluation of type annotations. New modules: dataclasses: PEP 557 – Data Classes New built-in features: PEP 553, the new breakpoint() function. Standard lib changes: The asyncio module has received new features, significant usability and performance improvements. The time module gained support for functions with nanosecond resolution. Speed: Method calls are 20% faster 3.7 is THE fastest Python available, period. What’s new in Python 3.7 course by Anthony Shaw

Our news

ahem… https://www.mongodb.com/presentation/building-python-web-apps

#82 Let's make a clear Python 3 statement

Jun 15, 2018 00:25:55


DigitalOcean: pythonbytes.fm/digitalocean

* GitHub coverage coming at the end! *

Brian #1: Building and Documenting Python REST APIs With Flask and Connexion

Doug Farrell, @writeson, on the RealPython site. Tutorial with example. REST explanation of what REST is and is not Swagger, swagger.yml to define API Use Connexion to incorporate swagger.yml into Flask app. Nice succinct explanation of swagger and API configuration. Demo of Swagger UI for API documentation. JavaScript included for MVC implementation.

Michael #2: MyPy + PyCharm

Written by Ivan Levkivskyi via Guido van Rossum Ricky Teachey asks: “What advantages does using mypy bring to pycharm vs just using pycharm's native type checking- which is already pretty good?” Response: mypy is a bit more stricter/precise it is more configurable, lots of options regulating type system "rules" it typechecks the whole program, so that you immediately see errors your change causes in _other_ files people run mypy in CI and want to see the result before push

Brian #3: Automatic code/doc conversion

pyupgrade “A tool (and pre-commit hook) to automatically upgrade syntax for newer versions of the language.” Can even convert to f-strings with --py36-plus option. docs “Run black on python code blocks in documentation files.” blacken-docs provides a single executable (blacken-docs) which will modify .rst / .md files in place.

Michael #4: python3statement

via Bruno Alla Matthias Bussonnier (Talk Python, episode 44) “We now have 44 projects that pledged to drop #python2 in less than 30 months. Some already did ! To see which one, and how to migrate with as few disruption as possible for both Python 2 and 3 users head to http://python3statement.org/ ” Supporting legacy Python: **it is a small but constant friction in the development of a lot of code. We are keen to use Python 3 to its full potential, and we currently accept the cost of writing cross-compatible code to allow a smooth transition, but we don’t intend to maintain this compatibility indefinitely. Nice “Why switch to Python 3?” section and resources Nice list of participating projects Can we get some that are not data science? :)

Microsoft buys GitHub:

Everyone complaining about Microsoft buying GitHub needs to offer a better solution Microsoft to acquire GitHub for $7.5 billion Linux Foundation: Microsoft's GitHub buy is a win for open source Coverage on Exponent podcast: 154 — Legacy Leverage Nat Friedman, future CEO of GitHub, AMA Re gitlab: GitLab congratulates GitHub and Microsoft GitLab imports from GitHub going up

Our news and extras:

PyLadies Cleveland just launched: First meeting June 26 (FB Profile) https://www.facebook.com/cleveland.pyladies.3 (FB Community Page) https://www.facebook.com/clepyladies/ (Twitter) https://twitter.com/CLEPyladies (Meetup) https://www.meetup.com/CLE-PyLadies/ (YouTube) https://www.youtube.com/channel/UCrX6AAcxXO_-8gitJWdjkuw

#81 Making your C library callable from Python by wrapping it with Cython

Jun 5, 2018 00:17:00


Sponsored by digitalocean: pythonbytes.fm/digitalocean

Brian #1: Learning about Machine Learning

hello tensorflow one pager site with a demo of machine learning in action. “Machine Learning (ML) is the dope new thing that everyone's talking about, because it's really good at learning from data so that it can predict similar things in the future.” Includes a graphical demo of ML trying to learn the correct coefficients to a polynomial. Google Provides Free Machine Learning Course For All Machine Learning Crash Course (MLCC) is a free 15 hours course that is divided into 25 lessons. It provides exercises, interactive visualizations, and instructional videos. These can help in learning machine learning concepts. 40 exercises, 25 lessons, 15 hours, case studies, interactive visualizations

Michael #2: Making your C library callable from Python by wrapping it with Cython

Article by Stav Shamir Cython is known for its ability to increase the performance of Python code. Another useful feature of Cython is making existing C functions callable from within (seemingly) pure Python modules. Need to directly interact from Python with a small C library

Want to wrap this C function?

void hello(const char *name) { printf("hello %s\n", name); }

Just install Cython and write this:

cdef extern from "examples.h": void hello(const char *name) def py_hello(name: bytes) -> None: hello(name)

Then create a setup file (details in article), call python setup.py build_ext --inplace and you’re good to go.

Brian #3: Taming Irreversibility with Feature Flags (in Python)

“Feature Flags are a very simple technique to make features of your application quickly toggleable. The way it works is, everytime we change some behavior in our software, a logical branch is created and this new behavior is only accessible if some specific configuration variable is set or, in certain cases, if the application context respects some rules.” def my_function(): if is_feature_active('feature_one'): do_something() else: do_something_else() Benefits Improving team’s response time to bugs. If a new feature causes a bunch of customer problems, just turn it off. Making possible to sync code more frequently. Merge to master with the feature turned off. Having a more fluid feature launching flow. Turn feature on in test/staging server. Validate your features easily with A/B testing, user groups, etc. Article discusses: how to implement flags cleanly. measuring success with analytics implementing flags with third party packages and recommends a few.

Michael #4: pretend: a stubbing library

Heard about this at the end of the pypi episode of Talk Python and wanted to highlight it more. Pretend is a library to make stubbing with Python easier. Stubbing is a technique for writing tests. A stub is an object that returns pre-canned responses, rather than doing any computation. Stubbing is related to mocking, but traditionally with stubs, you don’t care about behavior, you are just concerned with how your system under test responds to certain input data. However, pretend does include a call recorder feature. Nice clean api: >>> from pretend import stub >>> x = stub(country_code=lambda: "US") >>> x.country_code() 'US' >>> from pretend import stub, raiser >>> x = stub(func=raiser(ValueError)) >>> x.func() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "pretend.py", line 74, in inner raise exc ValueError

Brian #5: The official Flask tutorial

Has been updated recently. simplified, updated, including the source code for the project. tutorial includes section on testing, including testing with pytest and coverage. Flask is part of Pallets, which develops and maintains several projects Click — A package for creating beautiful command line interfaces in a composable way Flask — a flexible and popular web development framework ItsDangerous — cryptographically sign your data and hand it over to someone else Jinja — a full featured template engine for Python MarkupSafe — a HTML-Markup safe string for Python Werkzeug — a WSGI utility library for Python You can now donate to pallets to help with the maintenance costs of these important packages. There’s a donate button on the pallets site that takes you to a PSF page. Therefore, donations are deductible in the US.

Michael #6: An introduction to Python bytecode

Python is compiled Learn what Python bytecode is, how Python uses it to execute your code, and how knowing what it does can help you. Python is often described as an interpreted language—one in which your source code is translated into native CPU instructions as the program runs—but this is only partially correct. Python, like many interpreted languages, actually compiles source code to a set of instructions for a virtual machine, and the Python interpreter is an implementation of that virtual machine. This intermediate format is called "bytecode." These are your .PYC files


def hello() print("Hello, World!") 2 0 LOAD_GLOBAL 0 (print) 2 LOAD_CONST 1 ('Hello, World!') 4 CALL_FUNCTION 1 CPython uses a stack-based virtual machine. That is, it's oriented entirely around stack data structures (where you can "push" an item onto the "top" of the structure, or "pop" an item off the "top").

View and explore using

import dis dis.dis(hello)

#80 Dan Bader drops by and we found 30 new Python projects

May 29, 2018 00:30:45


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Brian #1: Packaging Python Projects

Tutorial on the PyPA has been updated. Includes README.md instead of REAMDE.rst Initial example of setup.py no longer too minimal or too scary. Discussion of using twine to upload to test.pypi.org/legacy before uploading to non-test pypi Related project, flit

Dan #2: gidgethub — An async library for calling GitHub’s API

Talk to GitHub API to add/modify issues, pull-requests, comments, … Also helpers to parse GitHub’s webhook events so you can write bots that react to new issues, comments, commits etc. Used it in @Mariatta’s GitHub Bot tutorial:https://github.com/Mariatta/github-bot-tutorial Cool architecture for a “modern” Python web API library (async, sansio, decorator based event callbacks) supports different async backends: aiohttp, treq, Tornado sans-I/O: “protocol implementations written in Python that perform no I/O (this means libraries that operate directly on text or bytes)” Why? → “reusability. By implementing network protocols without any I/O and instead operating on bytes or text alone, libraries allow for reuse by other code regardless of their I/O decisions. In other words by leaving I/O out of the picture a network protocol library allows itself to be used by both synchronous and asynchronous I/O code” (Biggest issue in that workshop was getting everyone upgraded to Python 3.6…but more on that later)

Michael #3: pysystemd

Recall I recently build a Python-based systemd service for geo syncing my course materials A thin Cython-based wrapper on top of libsystemd, focused on exposing the dbus API via sd-bus in an automated and easy to consume way. By Alvaro Leiva, a production engineer at Facebook / Instagram Presented at PyCon 2018 Systemd: Manages your services and their lifetimes e.g. I want my web app to start on boot but only after mongodb has started pysystemd lets you control and query these from a Python API

Brian #4: PyCharm 2018.2 EAP 1 includes improved pytest support

From Bruno Oliveira “Oh my, full support for ~~#~~pytest fixtures and parametrized tests coming in ~~@~~pycharm 2018.2. “ “PyCharm 2018.2 supports using fixtures in Pytest. Using fixtures allows you to separate your setup code from the actual tests, making for more concise, and more readable tests. Additionally, there have been improvements to code navigation and refactoring Pytest tests, and to using parametrized tests.” It’s hard for me to fully express how FREAKING EXCITED I am about this. auto-complete now works with fixtures to test functions goto declaration now works with fixtures to test functions (not fixtures of fixtures, but they know about that already) re-running a failed parametrization works (yay!) re-running a single parametrization works (yay!)

Dan #5:

Why is installing Python 3.6 so hard? (Recent GitHub Bot workshop experience) Sometimes hard to tell what’s easy/difficult for beginners People hit crazy edge cases: running Linux Subsystem for Windows (WSL) on Windows host, install Python into wrong environment broken PPAs + bad StackOverflow advice → broken SSL and no pip on Ubuntu (deadsnakes PPA is the way to go) People install multiple Python environments: Anaconda + python.org distribution Hard to find instructions for compiling from source on Linux Shameless plug: https://realpython.com/installing-python/

Michael #6: 30 amazing Python projects (2018 edition)

Mybridge AI evaluates the quality by considering popularity, engagement and recency. To give you an idea about the quality, the average number of Github stars is 3,707. No 30: PDFTabExtract: A set of tools for extracting tables from PDF files helping to do data mining on scanned documents. No 28: Surprise v1.0: A Python scikit for building and analyzing recommender systems No 27: Eel: A little Python library for making simple Electron-like HTML/JS GUI apps No 25: Clairvoyant: A Python program that identifies and monitors historical cues for short term stock movement — Have you seen The Wall Street Code - VPRO documentary? No 21: Fsociety: Hacking Tools Pack. A Penetration Testing Framework. No 18: Maya: Datetime for Humans in Python No 16: Better-exceptions: Pretty and useful exceptions in Python, automatically No 13: Apistar: A fast and expressive API framework. For Python No 8: MicroPython: A lean and efficient Python implementation for microcontrollers and constrained systems No 6: spaCy (v2.0): Industrial-strength Natural Language Processing (NLP) with Python and Cython No 2: Pytorch: Tensors and Dynamic neural networks in Python with strong GPU acceleration No 1: Home-assistant (v0.6+): Open-source home automation platform running on Python 3

Our news

Michael: Notable mention Cris’s GDPR writeup: http://tryexceptpass.org/article/gdpr/ Did you know about dropbox smart sync? https://www.dropbox.com/smartsync

#79 15 Tips to Enhance your Github Flow

May 25, 2018 00:27:31


Sponsored by DigitalOcean: pythonbytes.fm/digitalocean

Brian #1: pytest 3.6.0

Revamp the internals of the pytest.mark implementation with correct per node handling which fixes a number of long standing bugs caused by the old design. This introduces new Node.iter_markers(name) and Node.get_closest_mark(name) APIs. - Depricating Node.get_marker(name). - reasons for the revamp - updating existing code to use the new APIs - Now when @pytest.fixture is applied more than once to the same function a ValueError is raised. This buggy behavior would cause surprising problems and if was working for a test suite it was mostly by accident. Support for Python 3.7’s builtin breakpoint() method, - see Using the builtin breakpoint function for details. - Provided by friend of the show Anthony Shaw monkeypatch now supports a context() function which acts as a context manager which undoes all patching done within the with block. whitespace only diffs in failed assertions include escaped characters to be easier to read. plus more… see changelog

Michael #2: Hello Qt for Python

The first Qt for Python technology preview release is almost here, and for this reason we want to give a brief example on how it will open the doors to the Python world. The real question is: how to access the methods of a Qt class? To simplify the process, we kept Qt APIs. (basically change -> to . in the API) Can it be more pythonic? “We want to include more Python flavor features to Qt for Python in the near future, but at the moment we are focusing on the TP.” The wheels situation: we are planning a set of wheels for Linux, macOS and Windows for 64bit and a 32bit version only for windows. AFAIK, this is Pyside2 reborn

Brian #3: MongoDB 4.0.0-rc0 available

MongoDB 4.0.0-rc0, the first release candidate of MongoDB 4.0, is out and is ready for testing. Multi-document ACID transactions Non-Blocking Secondary Reads lots of other goodies, see announcement Did we mention Transactions!

Michael #4: Pipenv review, after using it in production

Nice summary: “The current state of python’s packaging is awful, I don’t think there’s anyone who could disagree with that. This problem is recognized and there are many attempts at trying to solve the mess. Pipenv was the first and it has gained a lot of traction, however it doesn’t sit well with everyone. And it’s also not suited for every project — like libraries.” The multiple environment problem: The tl;dr is — supporting multiple environments goes against Pipenv’s (therefore also Pipfile’s) philosophy of deterministic reproducible application environments. So if you want to use Pipenvfor a library, you’re out of luck. That means many projects just can not use Pipenv for their dependency managment. The good Pipfile and Pipfile.lock really are superior to requirements.txt. By a ton. While I disliked it at first, having flake8 and security check builtin in a single tool is great Installing (exclusively) from a private respository works very well. Instead of replacing a dotfile somewhere in the system, specifying the repository in Pipfile is great Creating a new Pipfile is very easy No problems introducing Pipenv to it’s new users No problems installing from a mixture of indexes, git repositores… With --sequential it is actually deterministic, as advertised Virtualenv is much easier to get into and understand Dependencies can be installed into system (e.g. in Docker) — our case. At no point did anyone in the team even mentioned getting rid of Pipenv — which is a lot better than it sounds Related: PyCon 2018 talk about the history and future of Python packaging, including pipenv. Recent changes to the official wording around pipenv (removes the statement that it’s the official way of managing application dependencies)

Brian #5: 15 Tips to Enhance your Github Flow

using github projects to prioritize issues and track progress using tags on issues templates using hub and git-extras on command line commit message standards scoped commits style standards with pre-commit hooks automated tests and checks on pull requests protect master branch requiring code reviews squash pull requests …. more great topics

Michael #6: Pandas goes Python 3 only

Via Randy Olseon It's official: Starting January 1, 2019, pandas will drop support for #Python 2. This includes no backports of security or bug fixes. Basically following NumPy’s lead The final release before December 31, 2018 will be the last release to support Python 2. The released package will continue to be available on PyPI and through conda. Starting January 1, 2019, all releases will be Python 3 only.

Our news

It’s GDPR eve, are you ready? Need a GDPR laugh? See https://twitter.com/nadimpatel_/status/999111866633871361 XKCD Python Environments: https://xkcd.com/1987/

#78 Setting Expectations for Open Source Participation

May 18, 2018 00:26:07


Sponsored by Datadog: https://pythonbytes.fm/datadog Special guest: Kojo Idrissa -- https://twitter.com/Transition

Brian #1: The Forgotten Optional <code>else</code> in Python Loops

“Both for and while loops in Python also take an optional else suite (like the if statement and the try statement do), which executes if the loop iteration completes normally. In other words, the else suite will be executed if we don’t exit the loop in any way other than its natural way. So, no break statements, no return statement, or no exceptions being raised inside the loop.” Why? So you don’t have to invent a flag to indicate something wasn’t found if you are using the loop to search for something.

Kojo #2: libraries.io

https://libraries.io/ Find out what your dependencies are! Look into https://tidelift.com/

Michael #3: The other (great) benefit of Python type annotations

We've had type annotations for awhile When and why is sometimes unclear Lack of types an issue sometimes, especially annoying while learning new APIs or diving into a new large codebase, and made me completely reliant on documentation. Optional: You can’t break the code by adding them They have no effect performance-wise You may add them only where you see fit Straightforward benefits Employ static code analysis to catch type errors prior to runtime Cleaner code/the code is self-documenting: “don’t use a comment when you can use a function or a variable”, we can now say “don’t use comments to specify a type, when you can use type annotation” The other benefit (it's massive!): Code completion

Brian #4: Setting Expectations for Open Source Participation

Or Pay for Open Source with Kindness Brett Cannon’s morning talk this last Sunday at PyCon 2018 This talk (or a variation of it and it’s content) is essential material for anyone working with open source. Everything in open source has a cost whether it’s time, effort, or emotional output. Open source should be a series of unsolicited kindnesses. Be open, considerate, and respectful Remember most of this runs on volunteer time and that people have lives. Guidelines for communicating online: Assume you are asking for a favor. Assume your boss will read what you say. Assume your family will read what you say.

Kojo #5:

Python Community Events Michael and I (along with Trey Hunner) helped lead a New Attendee Orientation Join your local Python community Be kind to your fellow Pythonistas

Michael #6: ngrok

ngrok exposes local servers behind NATs and firewalls to the public internet over secure tunnels. Public URLs for testing on mobile devices, testing your chatbot, SSH access to your Raspberry Pi, sharing your local dev work on full stack web apps. Just a commandline away My use case: Course app development Features: Secure Tunnels Request Inspection Fast (HTTP 2)

Extras and our news:


Live recording video is out: https://youtu.be/s9uUSQvrIaE Now up to 8 video servers around the world, Japan, Sao Paulo, and Mumbai are the latest. Based on the systemd thing we discussed way back when (episode 54)

#77 You Don't Have To Be a Workaholic To Win

May 12, 2018 00:21:04


Sponsored by Datadog: pythonbytes.fm/datadog

Brian #1: Why Senior Devs Write Dumb Code

“Any fool can write code that a computer can understand. Good programmers write code that humans can understand.” - Kent Beck Code that is clean, straightforward, obvious, and easy to read actually takes practice to achieve. Follow principles like YAGNI, Singe Responsibility, DRY, etc. Avoid clever one-liners, weird abstractions. Esoteric language features. Code needs to be readable and easily understood while under time and stress pressure.

Michael #2: GeoAlchemy 2

GeoAlchemy 2 provides extensions to SQLAlchemy for working with spatial databases. GeoAlchemy 2 focuses on PostGIS. Aims to be simpler than its predecessor, GeoAlchemy. Using it: Connect (e.g. Postgres) Declare a Mapping class Lake(Base): __tablename__ = 'lake' id = Column(Integer, primary_key=True) name = Column(String) geom = Column(Geometry('POLYGON')) Create a table (via the engine) Create an Instance of the Mapped Class Inserts like standard SQLAlchmey Spatial Query from sqlalchemy import func query = session.query(Lake).filter( func.ST_Contains(Lake.geom, 'POINT(4 1)')) query = session.query(Lake.name, Lake.geom.ST_Buffer(2).ST_Area().label('bufferarea'))

Brian #3: QtPyConvert

An automatic Python Qt binding transpiler to the Qt.py abstraction layer. QtPyConvert supports the following bindings out of the box: PyQt4 PySide PyQt5 PySide2 Conversions leave code comments in place, with the help of RedBaron Converts to Qt.py Minimal Python 2 & 3 shim around all Qt bindings - PySide, PySide2, PyQt4 and PyQt5

Michael #4: You Don't Have To Be a Workaholic To Win: 13 Alternative Ways To Stand Out

Do we have to kill ourselves to get ahead? Don’t busy-brag Max Q analogy The tips Creativity Stubbornness Curiosity Kindness Planning Improvisation Enthusiasm Communication Presence Collaboration Willingness Patience Institutional Knowledge

Brian #5: RedBaron

RedBaron is a python library to make the process of writing code that modify source code as easy and as simple as possible. writing custom refactoring, generic refactoring, tools, Used by QtPyConvert to achieve the conversion while leaving code comments in place Uses the full syntax tree, FST. Like an AST, but keeps all information, including comments and formatting. possible uses: rename a variable in a source file... without clashing with things that are not a variable (example: stuff inside a string) inline a function/method extract a function/method from a series of line of code split a class into several classes split a file into several modules convert your whole code base from one ORM to another do custom refactoring operation not implemented by IDE

Michael #6: Project Beeware AppStore

Project BeeWare has just released its first iPhone app made in Python using its Briefcase tool. Simple travel app for currency and tip calculations Briefcase: A distutils extension to assist in packaging Python projects as standalone applications. Briefcase is a tool for converting a Python project into a standalone native application. You can package projects for: Mac Windows Linux iPhone/iPad Android AppleTV tvOS While there are other Python GUI toolkits aiming to enable Python developers to build and deploy iOS apps, like for instance the very nice Pythonista app, the BeeWare project is a bit different because it aims at cross-platform compatibility and native widgets with a set of different tools, like Briefcase and Toga.


Michael: Extra ssh breach Did you see that? https://www.reddit.com/r/Python/comments/8hvzja/backdoor_in_sshdecorator_package/ PyCon videos already up at https://www.youtube.com/pycon2018

#76 Goodbye zero-versioning

May 4, 2018 00:30:40


Sponsored by Datadog: pythonbytes.fm/datadog

Brian #1: Unlearning toxic behaviors in a code review culture

unhelpful behaviors: passing off opinion as fact overwhelming with an avalanche of comments asking people to fix problems they didn’t cause “while they’re at it”. asking judgmental questions being sarcastic using emojis not replying to comments ignoring (not calling out) toxic behavior from high performers helpful: use questions or recommendations to drive dialog collaborate, don’t back-seat drive respond to every comment know when to take a discussion offline use opportunities to teach, and don’t show off don’t show surprise of lack of knowledge by others automate what can be refuse to normalize toxic behavior managers: hire carefully, listen to your team, and enforce set the standard as your team is small and growing understand you might be part of the problem

Michael #2: Flask 1.0 Released

Dropped support for Python 2.6 and 3.3. The CLI is more flexible. FLASK_APP can point to an app factory, optionally with arguments. It understands import names in more cases where filenames were previously used. It automatically detects common filenames, app names, and factory names. FLASK_ENV describes the environment the app is running in, like development, and replaces FLASK_DEBUG in most cases. See the docs to learn more. If python-dotenv is installed, the flask CLI will load environment variables from .flaskenv and .env files rather than having to export them in each new terminal. The development server is multi-threaded by default to handle concurrent requests during development. flask.ext, which was previously deprecated, is completely removed. Import extensions by their actual package names. Accessing missing keys from request.form shows a more helpful error message in debug mode, addressing a very common source of confusion for developers. Error handlers are looked up by code then exception class, on the blueprint then application. This gives more predictable control over handlers, including being able to handle HTTPException. The behavior of app.logger has been greatly simplified and should be much easier to customize. The logger is always named flask.app, it only adds a handler if none are registered, and it never removes existing handlers. See the docs to learn more. The test_client gained a json argument for posting JSON data, and the Response object gained a get_json method to decode the data as JSON in tests. A new test_cli_runner is added for testing an app's CLI commands. Many documentation sections have been rewritten to improve clarity and relevance. This is an ongoing effort. The tutorial and corresponding example have been rewritten. They use a structured layout and go into more detail about each aspect in order to help new users avoid common issues and become comfortable with Flask. There are many more changes throughout the framework. Read the full

Brian #3: So, I still don’t quite get pipenv, ….

Best discussion of why pipenv is useful for applications I’ve come across so far is Pipenv: A Guide to the New Python Packaging Tool Starts with a discussion of situations where pip, pip freeze, and requirements.txt fall apart. requirements.txt often just have an applications direct dependencies, not sub-dependencies. pip freeze > requirements.txt will pin your versions to specific versions, but then you’ve got to keep track of dependencies and sub-dependencies. Pipfile intends to replace requirements.txt, with a simple-ish human readable format. Also includes extra things like dev environment support. Pipfile.lock intends to replace pinned requirements.txt files. Also includes hashes to validate versions haven’t been corrupted. pipenv also includes cool tools like dependency graphing, checking for updates, etc. pipenv should be used for applications, but not packages intended to be included in other applications. But you can use it during package development, just probably not include the Pipfile and Pipfile.lock in the repo or package distribution. - Brian’s comment

Bonus extra:

cookiecutter-pipenv: Cookiecutter Python Package Template with Pipenv

Michael #4: GraalVM: Run Programs Faster Anywhere

Why? Current production virtual machines (VMs) provide high performance execution of programs only for a specific language or a very small set of languages. Compilation, memory management, and tooling are maintained separately for different languages, violating the ‘don’t repeat yourself’ (DRY) principle. high performance VMs are heavyweight processes with high memory footprint and difficult to embed. Oracle Labs started a new research project for exploring a novel architecture for virtual machines. Our vision was to create a single VM that would provide high performance for all programming languages, therefore facilitating communication between programs. Released: GraalVM, a universal virtual machine designed for a polyglot world. GraalVM provides high performance for individual languages and interoperability with zero performance overhead for creating polyglot applications. GraalVM 1.0 allows you to run: JVM-based languages like Java, Scala, Groovy, or Kotlin JavaScript (including Node.js) LLVM bitcode (created from programs written in e.g. C, C++, or Rust) Experimental versions of Ruby, R, and Python Future: This first release is only the beginning. We are working on improving all aspects of GraalVM; in particular the support for Python

Brian #5: Testing a Flask Application using pytest

Small demo project, and article, that teaches the use of pytest in Flask. unit testing and functional testing Article covers testing models, with an example of a new user. project also has examples of using a test client to check the login page, password authentication, and a lot more. Very cool project.

Bonus: A cool new pytest plugin: pytest-caprng

Tests that use random or np.random may fail, but when you re-run them, they don’t fail, which makes them hard to debug. This plugin adds pytest flags --caprng-global-stdlib and --caprng-global-np, which saves the random state before each test so that if you re-run the test, the random-ness is not so random, and you can reproduce your failure. Also, thanks John for reminding me what “stochastic” means.

Michael #6: How to have a great first PyCon

Spending your time: which talks should I go to? The talks at PyCon are typically uploaded to YouTube within 24 hours after the talk ends. I am suggesting that you don’t need to worry about attending every talk. Open spaces: attend them and consider hosting your own! There are a few reasons I often pick open spaces over talks: Often the open spaces are more niche and topical than the talks: there are some subjects that exist in open spaces every year but which I’ve never seen a talk on Open spaces are all about interaction and discussion whereas talks are a monologue that often evolves into subsequent dialogues Open spaces aren’t recorded whereas the talks are, meaning you can’t really catch up on them later Tips for starting conversation, breakfast and lunch time… The hallway track 👣 Something you might consider doing while at PyCon is taking breaks in the hallway. In addition to joining or starting a table in the hallway, consider identifying groups that have a PacMan opening to join and make sure the groups you’re in are PacMan-friendly. Interacting online during PyCon 🐦 I recommend getting a Twitter account to make it easier to passively keep up with folks from PyCon after the conference ends. Sometimes people on Twitter will ask if anyone would like to join them for dinner and you might decide to reply and say you’d like to join. Networking isn’t a dirty word: it means making friends 👥 I hear two opposing concerns sometimes expressed about PyCon: Isn’t everyone here to get a job or hire people? Is it acceptable to go to PyCon looking for a job? PyCon is a networking event. That doesn’t necessarily mean everyone is there to get a job, but it also definitely doesn’t mean it’s unacceptable to job-seek at Python. Other topics include Volunteering Evening events: dinners and board games Give a lightning talk ⚡ Take care of yourself Final tip from commentor: If you are on windows, it's helpful to install a virtual image of a linux like the current ubuntu on your laptop, because you could run into situations where you want to follow a talk / training which doesn't work on windows and then you're missing a great opportunity to learn.

Our news

Come see us at PyCon!!! We’ll have stickers! Brian’s talk is Friday at 5 something. We are doing a live Python Bytes open session, join “friends of the show” to get notified I’ll be at Microsoft BUILD too PyGotham 2018 Call for Proposals http://PyCon.DE (24-26 October 2018 in Karlsruhe, Germany) starting our CfP tomorrow until May 20. http://de.pycon.org

#75 pypi.org officially launches

Apr 28, 2018 00:19:51


Sponsored by Datadog: pythonbytes.fm/datadog

Brian #1: numba

From the numba readme: “The easiest way to install numba and get updates is by using the Anaconda Distribution: https://www.anaconda.com/downloadThe need for speed without bothering too much: An introduction to numba Can get huge speed up for some computation heavy loops or algorithms.

Michael #2: pip 10 is out!

Time for: python -m pip install --upgrade pip Features: Python 2.6 is no longer supported - if you need pip on Python 2.6, you should stay on pip 9, which is the last version to support Python 2.6. Support for PEP 518, which allows projects to specify what packages they require in order to build from source. (PEP 518 support is currently limited, with full support coming in future versions - see the documentation for details). Significant improvements in Unicode handling for non-ASCII locales on Windows. A new "pip config" command. The default upgrade strategy has become "only-if-needed" Many bug fixes and minor improvements.

Brian #3: Keyword (Named) Arguments in Python: How to Use Them

Using keyword arguments is often seen when there are many arguments to a function that have useful defaults, and you only want to override the default with some of the arguments. Example: >>> print('comma', 'separated', 'words', sep=', ') comma, separated, words You can take positional arguments and require some to be named with various uses of * def foo(*, bar, baz): print(f'{bar} {baz}') Lots of other useful tricks in this article.

Michael #4: pypi.org officially launches

Legacy PyPI shutting down April 30 Listen to talk python 159 Starting April 16, the canonical Python Package Index is at https://pypi.org and uses the new Warehouse codebase. Launched the new PyPI, redirecting browser traffic and API calls (including "pip install") from pypi.python.org to the new site. The old codebase is still available at https://legacy.pypi.org for now. Monday April 30 (2018-04-30): We plan to shut down legacy PyPI https://legacy.pypi.org . The address pypi.python.org will continue to redirect to Warehouse. If your site/service links to or uses pypi.python.org, you should start using pypi.org instead: https://warehouse.readthedocs.io/api-reference/integration-guide/#migrating-to-the-new-pypi

Brian #5: Python Modules and Packages – An Introduction

In Python, it is, and understanding modules and packages is key to getting a good footing when learning Python. It’s also an area that trips up people when they start trying to create reusable code. How to create a Python module Locations where the Python interpreter searches for a module How to obtain access to the objects defined in a module with the import statement How to create a module that is executable as a standalone script How to organize modules into packages and subpackages How to control package initialization

Michael #6: Pandas only like modern Python

From December 31st, 2018, Pandas will drop support for Python 2.7. This includes no backports of security or bug fixes (unless someone volunteers to do those) The final release before December 31, 2018 will be the last release to support Python 2. The released package will continue to be available on PyPI and through conda. Starting January 1, 2019, all releases will be Python 3 only. The full reddit discussion is interesting.

Our news

Just launched: Python 3, an illustrated tour! talkpython.fm/illustrated

#74 Contributing to Open Source effectively

Apr 19, 2018 00:24:51


Sponsored by Datadog: pythonbytes.fm/datadog

Special guest: Matt Harrison - __mharrison__

Brian #1: Contributing to Open Source effectively The mechanics and conventions on how to contribute to open source projects can be confusing. After seeing a very well documented pull request that started with [WIP] in the subject line when it was first submitted, I tried to find out more about the conventions and mechanics of it all. I’m still learning, but here are a couple of resources:

How to write the perfect pull request is more of a mindset of how to initiate and receive PRs Approach to writing a Pull Request, including that [WIP] trick. Offering feedback Responding to feedback Forge Your Future with Open Source, @vmbrasseur book on contributing to open source, includes: Make a Contribution, which includes PRs Make a difference without making a pull request, which is suggests many ways to contribute to a project without contributing code, like reviewing others contributions, testing, triaging bugs, … Interacting with the community.

Matt #2: Jupyter, Mathematica, and the Future of the Research Paper

Paul Romer, economy professor at NYU As a longtime Linux user there was constantly the question of the “year of the Linux Desktop”. Maybe this is the year of the “Jupyter desktop” (also beta version of JupyterLab). Not just a tool for innovators or early adopters Refers to Article in Atlantic contrasting Mathematica and Jupyter: open-source developers have flocked to Python because it happens to be the de facto standard for scientific computing. Programming-language communities, like any social network, thrive—or die—on the strength of these feedback loops. https://www.theatlantic.com/science/archive/2018/04/the-scientific-paper-is-obsolete/556676/


Jupyter is a new open-source alternative [to Mathmatica] that is well on the way to becoming a standard for exchanging research results.

Python libraries let me replicate everything I wanted to do with Mathematica: Matplotlib for graphics, SymPy for symbolic math, NumPy and SciPy for numerical calculations, Pandas for data, and NLTK for natural language processing. Jupyter makes it easy to use Latex to display typeset math. With Matplotlib, Latex works even in the label text for graphs. (I have not yet tried the major update, JupyterLab, which is still in beta testing.) I’m more productive. I’m having fun. https://paulromer.net/jupyter-mathematica-and-the-future-of-the-research-paper/

Michael #3: Python Developers Survey 2017 Results

At the very end of 2017, JetBrains & The PSF teamed up to build a solid picture of the modern Python developer Here are some take-aways Almost 4 out of 5 Python developers use it as their main language, while for 21% it’s only a secondary language. Data analysis is as popular as web development with Python: Web development is the only category with a large gap (54% vs 33%) separating those using Python as their main language vs as a supplementary language. For other types of development, the differences are far less significant. At 28% to 27% application, There are as many Python web developers as Python data scientists Python 3 vs Python 2: 75% to 25% and accelerating Top Cloud Platform(s) 67%: AWS 29%: Google App Engine 26%: Heroku 23%: DigitalOcean 16%: Microsoft Azure Team Size 74%: 2-7 people 16%: 8-12 people 5%: 13-20 people 2%: 21-40 people 2%: > 40 people Operating Systems 49%: Windows 19%: Linux 15%: MacOS

Brian #4: *EdgeDB: A New Beginning* This is “news you can’t use” so far, because the product isn’t here yet. So why am I excited and interested in this:

It’s from Elvis @elprans and Yury @1st1, who have brought us asyncio and uvloop It’s not just a relational DB, it’s a DB based on PostgreSQL but with an entire new way to specify schema and interact with it. Goal is to be fast, user friendly, and remove the need for ORMs

Matt #5: Yellowbrick library

Visualization is important, I’ve found bugs by plotting before. Also important in evaluation of machine learning projects This is a project that has been around for about two years. I’ve recently adopted it in place of some home grown libraries for some consulting projects and in my corporate training Yellowbrick offers visualization for: Features Classification Regression Clustering Text Like sk-learn, uses a similar api (.fit, .transform, .poof (plot))

Michael #6: Depression AI

Alexa skill for people suffering with depression. Alexa store listing Based on Flask-Ask Discussed on Talk Python 146 Valley Hackathon 2018 winner 71% of people who make their bed in the morning report feeling happy. This was the inspiration behind DepressionAI. The aim behind this skill is to encourage people to perform daily activities that become very difficult when one is depressed. The skill detects positive and negative moods. If the user is having a bad day, it asks them a series of questions about what they have done that day (e.g. "Have you gotten out of bed?") and if they haven't, it encourages them to do so. Features Mood evaluation by a highly empathetic Alexa bot Suicidal intention detection and prevention attempt Location-based therapy reccomendations Suggestions for small activites to improve the user's mood Displays informative cards in the Alexa app Sample Phrases “Alexa, check on me." "I feel down." "I haven't got out of bed today." "Help me feel better." "Help me find a therapist"

#73 This podcast comes in any color you want, as long as it's black

Apr 12, 2018 00:18:35


Sponsored by Datadog: pythonbytes.fm/datadog

Brian #1: Set Theory and Python

“Let’s talk about sets, baby …” is what I have in my head while reading this. Great overview of set theory and how to use the set data type in Python. Covered: Creating sets Checking for containment (in, not in) union : set of things in either set or in both intersection: set of things in 2 sets difference: set of things in one set but not the other symmetric difference: set of things in either set but not in both

Michael #2: Trio: async programming for humans and snake people

The Trio project’s goal is to produce a production-quality, permissively licensed, async/await-native I/O library for Python. Like all async libraries, its main purpose is to help you write programs that do multiple things at the same time with parallelized I/O. Compared to other libraries, Trio attempts to distinguish itself with an obsessive focus on usability and correctness. Concurrency is complicated; we try to make it easy to get things right. Trio was built from the ground up to take advantage of the latest Python features Inspiration from many sources, in particular Dave Beazley’s Curio Resulting design is radically simpler than older competitors like asyncio and Twisted, yet just as capable. We do encourage you do use it, but you should read and subscribe to issue #1 to get warning and a chance to give feedback about any compatibility-breaking changes. Excellent scalability: trio can run 10,000+ tasks simultaneously without breaking a sweat, so long as their total CPU demands don’t exceed what a single core can provide. Supports Python 3.5+ and PyPy Uses trio.run(async_method, 3) trio.sleep(1.5) # Sleep, non-blocking async with trio.open_nursery() as nursery: print("parent: spawning child...") nursery.start_soon(child_func1) print("parent: spawning child...") nursery.start_soon(child_func2) print("parent: waiting for children to finish...") # -- we exit the nursery block here -- print("parent: child_func1 and child_func2 done!") trio provides a rich set of tools for inspecting and debugging your programs. Consider trio-asyncio for compatibility

Brian #3: black: The uncompromising Python code formatter

An amusing take on code formatting. From the readme:

“Black is the uncompromising Python code formatter. By using it, you agree to cease control over minutiae of hand-formatting. In return, Black gives you speed, determinism, and freedom from pycodestyle nagging about formatting. You will save time and mental energy for more important matters.” “Blackened code looks the same regardless of the project you're reading. Formatting becomes transparent after a while and you can focus on the content instead.” “Black makes code review faster by producing the smallest diffs possible.”

Datadog is a monitoring solution that provides deep visibility and tracks down issues quickly with distributed tracing for your Python apps.

Within minutes, you'll be able to investigate bottlenecks in your code by exploring interactive flame graphs and rich dashboards. Visualize your Python performance today, get started with a free trial with Datadog and they'll send you a free T-shirt.

See for yourself, visit pythonbytes.fm/datadog.

Michael #4: gain: Web crawling framework based on asyncio

Web crawling framework for everyone. Written with asyncio, uvloop and aiohttp. Simple and mostly automated Define class mapped to CSS selectors and data to save Concurrently level Start URL Page templates to match URLs Run

Brian #5: Generic Function in Python with Singledispatch

“Imagine, you can write different implementations of a function of the same name in the same scope, depending on the types of arguments. Wouldn’t it be great? Of course, it would be. There is a term for this. It is called “Generic Function”. Python recently added support for generic function in Python 3.4 (PEP 443). They did this to the functools module by adding @singledispatch decorator.” For people less familiar with “generic functions”. I think of this as providing similar functionality as C++’s function overloading. Allows you do things like this (full code example is in the article): from functools import singledispatch @singledispatch def fprint(data): "code for default functionality" @fprint.register(list) @fprint.register(set) @fprint.register(tuple) def _(data): "code for list, set, tuple" @fprint.register(dict) def _(data): "code for dict"

More complete code example:

from functools import singledispatch @singledispatch def fprint(data): print(f'({type(data).__name__}) {data}') @fprint.register(list) @fprint.register(set) @fprint.register(tuple) def _(data): formatted_header = f'{type(data).__name__} -> index : value' print(formatted_header) print('-' * len(formatted_header)) for index, value in enumerate(data): print(f'{index} : ({type(value).__name__}) {value}') @fprint.register(dict) def _(data): formatted_header = f'{type(data).__name__} -> key : value' print(formatted_header) print('-' * len(formatted_header)) for key, value in data.items(): print(f'({type(key).__name__}) {key}: ({type(value).__name__}) {value}') # >>> fprint('hello') # (str) hello # >>> fprint(21) # (int) 21 #... # >>> fprint({'name': 'John Doe', 'age': 32, 'location': 'New York'}) # dict -> key : value # ------------------- # (str) name: (str) John Doe # (str) age: (int) 32 # (str) location: (str) New York

Michael #6: Unsync: Unsynchronizing async/await in Python 3.6

A rant about async/await in Python (by Alex Sherman) What’s wrong? The two big friction points I’ve had are: Difficult to “fire and forget” async calls (need to specifically run the event loop) Can’t do blocking calls to asyncio.Future.result() (it throws an exception) We need to acquire an even loop, do some weird call to execute the async function in that event loop, and then synchronously execute the event loop ourselves. What can we do? C# had this great idea of executing each Task (their version of a Future) first synchronously in the main thread until an await is hit, and then queueing it into an ambient thread pool to continue later possibly in a separate thread. Python did not take this approach and my hunch is that the Python maintainers didn’t want to add an ambient thread pool to their language (which makes sense). Alex, however, is not the Python maintainers and did add an ambient thread (singular). I stuffed all the boiler plate into a decorator and the result looks like this: @unsync async def unsync_async(): await asyncio.sleep(0.1) return 'I like decorators' print(unsync_async().result()) using @unsync on a regular function (not an async one) will cause it to be executed in a ThreadPoolExecutor. To support CPU bound workloads, you can use @unsync(cpu_bound=True) to decorate functions which will be executed in a ProcessPoolExecutor

#72 New versioning: Episode (with 72 releases)

Apr 5, 2018 00:22:54


Sponsored by Datadog: pythonbytes.fm/datadog

Brian #1: ZeroVer: 0-based Versioning

“Software's most popular versioning scheme!” “Cutting-edge software versioning for minimalists” My favorite April Fools prank this year. Calls out many popular projects for never reaching 1.0 From the about page: “ZeroVer is the world's most popular software versioning convention, and the only one shown to harness the innovative power of zero. The benefits are innumerable and the effects on the software world are profound.” “Version 0.0.1 of ZeroVer was published by Mahmoud Hashemi, with help from Moshe, Mark, Kurt, and other patient collaborators, on 2018-04-01. ZeroVer is satire, please do not use it. We sincerely hope no project release schedules were harmed as a result of this humble attempt at programmer humor.”

Michael #2: GitHub Security Alerts Detected over Four Million Vulnerabilities

Last year GitHub launched “GitHub security alerts” GitHub’s security alerts notify repository admins when library vulnerabilities from the Common Vulnerabilities and Exposures (CVEs) list are detected in their repositories. Nearly half of all displayed alerts are responded to within a week and the rate of vulnerabilities resolved in the first seven days has been about 30%. When that statistics is restricted to only repositories with recent contributions, i.e., contributions in the last 90 days, things look even brighter, GitHub says, with 98% of such repositories being patched in fewer than seven days. More than four million vulnerabilities in over 500,000 repositories have been reported. Security alerts are only currently supported for repositories written in Ruby or JavaScript, while support for Python is planned for 2018. I also recommend pyup.io

Brian #3: Markdown Descriptions on PyPI

Dustin Ingram provides detailed steps on how to get this to work. README.md now supported by pypi.org “Only https://pypi.org will correctly render your new Markdown description. Legacy PyPI (http://pypi.python.org/) will still render your description as plaintext, but don’t worry, it’s going away real soon. And also, Github-Flavored Markdown Descriptions are supported. Another post, this one by Jon Wayne Parrot

Michael #4: Concurrency comparison between NGINX-unit and uWSGI

show performance of two web application servers nginx-unit (a new modern application web server) uWSGI (the best one application server) uWSGI and nginx-unit configured with 4 workers because test system has 4 cores. Effectively an empty “Hello world” Flask app Have a look at the pictures here: https://itnext.io/performance-comparison-between-nginx-unit-and-uwsgi-python3-4511fc172a4c Take away: I’m going to start paying attention to NGINX-unit

Brian #5: Loop better: A deeper look at iteration in Python

via Trey Hunner Generators are a great way to loop, but have a few gotchas Looping twice doesn’t work Containment checks muck up the generator “contents”. Unpacking has odd results. This article describes Python loops in detail and then applies that do describe why the gotchas act like they do. Covered: iterators, iterables, sequences, generators the iterator protocol Reading this will make you a better programmer, but might hurt your head.

Michael #6: Misconfigured Django Apps Are Exposing Secret API Keys, Database Passwords

Security researchers have been stumbling upon misconfigured Django applications that are exposing sensitive information such as API keys, server passwords, or AWS access tokens. He discovered 28,165 Django apps just this week where admins left debug mode enabled. Just by skimming through a few of the servers, the researcher found that the debug mode of many of these apps were exposing extremely sensitive information that would have allowed a malicious actor full access to the app owner's data. This is not a failure from Django's side. My recommendation is to disable debugging mode when deploying the application to production. Security researcher Victor Gevers said some of the servers running Django apps have already been compromised. He found at least one compromised server, running the Weevely web shell. Some servers Gevers found leaking sensitive data belonged to various government agencies carrying out critical operations. Gevers said he started notifying servers owners about their leaky Django apps. "At this moment we have reported 1,822 servers," Gevers said. "143 were fixed or taken offline."


We covered wagtail on episode 70. They are running a kickstarter campaign to get some new features out. There’s a video there.

#71 We can migrate to Python 3, careful please

Mar 28, 2018 00:24:01


Python Bytes 71

Sponsored by DigitalOcean: do.co/python

Special guest: Trey Hunner (@treyhunner)

Trey #1: The Conservative Python 3 Porting Guide

by various Red Hat folks mostly Python 2 is coming to the end of its life on January 1, 2020. Are you ready? This is one of the best guides I’ve found to porting your code from Python 2 to Python 3 One of the issues with many of the Python 3 porting guides is that the old ones recommend dropping Python 2 support suddenly, which isn’t recommended anymore. I do wish this guide recommended the future library instead of python-modernize. They’re both great, but modernize is a little less focused on writing things the Python 3 way and a little more focused on just getting your code working in both 2 and 3.

Michael #2: World-Class Software Companies That Use Python

by Jason Reynolds While it’s easy to see how you can tinker with Python, you might be wondering how this translates to actual business and real world applications. Industrial Light and Magic The studio has used Python in multiple other facets of their work. Developers use Python to track and audit pipeline functionality, maintaining a database of every image produced for each film. Google In the beginning, the founders of Google made the decision of “Python where we can, C++ where we must.” Currently powers YouTube among other things Facebook Ensures that the infrastructure of Facebook is able to scale efficiently Instagram the Instagram engineering team boasted that they were running the world’s largest deployment of the Django web framework, which is written entirely in Python. Instagram’s engineering team has invested time and resources into keeping their Python deployment viable at the massive scale (~800 million monthly active users) they’re operating at. PyCon 2017 keynote talk by Lisa Guo and Hui Ding Spotify This music streaming giant is a huge proponent of Python, using the language primarily for data analysis and back end services. On the back end, there are a large number of services that all communicate over 0MQ, or ZeroMQ, an open source networking library and framework that is written in Python and C++(among other languages). Quora choosing to use Python where they could because of its ease of writing and readability, and implemented C++ for the performance critical sections. They got around Python’s lack of typechecking by writing unit tests that accomplish much the same thing. Another key consideration for using Python was the existence of several good frameworks at the time including Django and Pylons. Netflix Lots of infrastructure and ops work done via Python https://talkpython.fm/episodes/show/16/python-at-netflix Dropbox Dropbox makes heavy use of Python Guido van Rossum works there! Lots of open source projects Client app in Python too Reddit This website had 542 million visitors every month across 2017, making it the fourth most visited website in the United States and seventh most visited in the world. In 2015, there were 73.15 million submissions and 82.54 billion pageviews. Behind it all, forming the software backbone, was Python.

Trey #3: Stop Writing Classes

by Jack Diederich This is one of my favorite PyCon talks to recommend to folks switching to Python from other programming languages. I especially like to recommend this talk to folks moving to Python from Java and C++. This is kind of an old talk. It's from 2012, so it's from the days of Python 2 but everything in it is still very applicable today. One of the great things about this talk is it doesn’t just show times that you should write functions instead of classes, it also shows an example or two of when classes really make sense. The big advice from this talk: if you have a class that only has two methods and one is the initializer, you probably need a function instead.

Michael #4: PyPi.org is alive

For the LONGest time, pypi has been run out of http://pypi.python.org/pypi Now the new version of pypi is out at pypi.org Rewritten in Pyramid Do you want to contribute? Now the barriers have come down Tweet with graphs

Trey #5: Pragmatic Unicode

by Ned Batchelder Another PyCon 2012 talk that is still relevant today, though it does use quite a bit of Python 2 syntax Ned describes the unicode sandwich in this talk. Talks with good metaphors really help shape your mental model of a topic. This was the talk that helped me really understand the unicode vs bytes issue that Python 3 largely solves for us (or at least forces us to do so upfront).

Michael #6: pygame on pypy usable

via René Dudfield 0.5x to 30x the speed That is pygame (same one that runs on cpython), works on pypy through its C extension API This is exciting because: pure python code being fast on pypy(after warmup), also mixed with the fast bits in C/asm. cpyext is getting faster in pypy. There is already work and discussion towards it being faster than CPython. maintaining one pygame code base is easier than maintaining several (pygame cffi/ctypes/cython, ...). with one code base it should be fast on both pygame, and pypy(in time). Where it can be slower: if you are going into C code for a lot of small operations. Like when using lots of pygame.Rect in a tight loop. This is because (currently) the cost of going from PyPy code into and out of CPython API code (like pygame) is a bit slow. Ray tracing in PyGame: On PyPy - 18.6 seconds. On Python 2.7 - 9 minutes, 28.1 seconds (30x slower)

Follow up and other news

Michael: #100DaysOfCode in Python course: talkpython.fm/100days

Trey: Python Morsels: pythonmorsels.com

#70 Have you seen my log? It's cute!

Mar 23, 2018 00:15:51


Sponsored by DigitalOcean: do.co/python

Brian #1: Online CookieCutter Generator

“Get a ZIP-archive with project by filling out the form.” By @kpavlovsky_pro Konstantin Pavlovsky

Michael #2: cutelog – GUI for Python's logging module

This is a graphical log viewer for Python's standard logging module. Features Allows any number of simultaneous connections Fully customizable look of log levels and columns Filtering based on level and name of the logger, as well as filtering by searching Search through all records or only through filtered ones View exception tracebacks or messages in a separate window Dark theme (with its own set of colors for levels) Pop tabs out of the window, merge records of multiple tabs into one Based on PyQt5 speaking of GUIs

Brian #3: wagtail 2.0

“Wagtail is a content management system built on Django. It’s focused on user experience, and offers precise control for designers and developers.” The Zen of Wagtail - nice philosophy of the project page to let you know if this kind of thing is right for you and your project. In 2.0 a new text editor Django 2 support better scheduled publishing … wagtail docs gallery of sites made with wagtail

Michael #4: peewee 3.0 is out

Peewee is a simple and small ORM. It has few (but expressive) concepts, making it easy to learn and intuitive to use. A small, expressive ORM Written in python with support for versions 2.7+ and 3.4+ (developed with 3.6) Built-in support for SQLite, MySQL and Postgresql. Numerous extensions available (postgres hstore/json/arrays, sqlite full-text-search, schema migrations, and much more). Although this was pretty much a complete rewrite of the 2.x codebase, I have tried to maintain backwards-compatibility for the public APIs. Exciting because of its async support via peewee-async peewee-async is a library providing asynchronous interface powered by asyncio for peewee ORM. database.set_allow_sync(False) async def handler(): await objects.create(TestModel, text="Not bad. Watch this, I'm async!") all_objects = await objects.execute(TestModel.select()) for obj in all_objects: print(obj.text)

Brian #5: Machine Learning Basics

“Plain python implementations of basic machine learning algorithms” From the repo: A repository of implementations of basic machine learning algorithms in plain Python (Python Version 3.6+). All algorithms are implemented from scratch without using additional machine learning libraries. The intention of these notebooks is to provide a basic understanding of the algorithms and their underlying structure, not to provide the most efficient implementations. Linear Regression Logistic Regression Perceptron k-nearest-neighbor k-Means clustering Simple neural network with one hidden layer Multinomial Logistic Regression

Michael #6: Cerberus

Cerberus provides powerful yet simple and lightweight data validation functionality out of the box designed to be easily extensible, allowing for custom validation Origin of the name: CERBERUS, n. The watch-dog of Hades, whose duty it was to guard the entrance; schema = {'name': {'type': 'string'}, 'age': {'type': 'integer', 'min': 10}} v = Validator(schema) document = {'name': 'Little Joe', 'age': 5} v.validate(document) # False v.errors # {'age': ['min value is 10']}

Follow up and other news


#100DaysOfCode in Python course: talkpython.fm/100days

#69 Digging into StackOverflow's 2018 survey results

Mar 18, 2018 00:24:00


Python Bytes 69

Sponsored by DigitalOcean: https://do.co/python

Brian #1: pynb: Jupyter Notebooks as plain Python code with embedded Markdown text

pynb lets you manage Jupyter notebooks as plain Python code with embedded Markdown text, enabling: Python development environment: Use your preferred IDE/editor, ensure style compliance, navigate, refactor, and test your notebooks as regular Python code. Version control: Track changes, review pull requests and merge conflicts as with regular Python code. The cell outputs are stored separately and don't interfere with versioning. Consistent execution state: Never lose track again of the execution state. Notebooks are always executed from clean iPython kernels and the cell execution is cached. You also get parameterized notebooks with batch and programmatic execution.

Michael #2: Microsoft’s quantum computing language is now available for macOS

New language Q# (snippet examples) How do you run a quantum app? Based on topological qubits and quantum computers Now out on macOS & Linux Need to use VS Code (and vs code extension) Comes with Python interoperability (only other language) Also in Jupyter Some real-world examples. See this Wired article. D-wave IBM is making quantum computers commercially available. Since 2016, it has offered researchers the chance to run experiments on a five-qubit quantum computer via the cloud and at the end of 2017 started making its 20-qubit system available online too.

Brian #3: pytest talk in Spanish

"pytest: recommendations, basic packages for testing in Python and Django" By A. Vallbona (@avallbona) From PyConES 2017 with English slides, and video in Spanish. Some of the topics covered: pytest-django model-mommy to easily create fixtures based on django models pytest-lazy-fixture allows the use the fixtures as parameters to parameterize pytest-mock, pytest-cov, pytest-flake8 freezegun to helps us to "freeze" time eradicate to eliminate commented code pytest-xdist to run tests in parallel

Bonus pytest topic:

pytest.org just added a Reference page, a full reference to pytest’s API.

Michael #4: StackOverflow Developer Survey Results 2018

Sample size: Over 100,000 developers 55% contribute to open source 64% have CS degrees Experience and Belonging Connection to other devs (increasing over time) Competing with peers (decreasing over time) Not as good as my peers (decreasing over time) How Much Time Do Developers Spend on a Computer? Most: 9-12 hours Python beats C# in usage for the first time Languages: Most loved: #1 Rust, #2 Kotlin, #3 Python Most dreaded: VB 6 and CoffeeScript Most wanted: #1 Python 25%, #JavaScript 19%, #3 Go 16% Databases: Loved: PostgreSQL Dreaded: IBM Db2, Memcached, and Oracle Most wanted: MongoDB Editor: VS Code Dev OSes: Windows: 49% macOS: 27% Linux: 23%

Brian #5: demoshell

@doughellmann Doug Hellman (@doughellmann) announces demoshell Inspired by a tweet from @genehack “Hey, speakers, if you're doing live demos in a shell, clear the screen after every command to get the prompt back at the top, so folks in the back can see what you're doing.” demoshell is a simplified shell for live demonstrations. It always shows the command prompt at the top of the screen and pushes command output down instead of letting it scroll up. In his words: “I put it up there to start a discussion. I’d be happy if a bunch of people showed up and wanted to take it over and actually turn it into something useful. I invite people to give it a look. And warn them that too much interest is going to be met with commit privileges on the repo. :-)”

Michael #6: Clear statement on Python 2 EOL

Will there be a period where Py2.7 is in security-only status before hitting EOL? via Nicola Iarocci‏ @nicolaiarocci Yay, @gvanrossum makes it adamantly clear: “Let's not play games with semantics. The way I see the situation for 2.7 is that EOL is January 1st, 2020, and there will be no updates, not even source-only security patches, after that date.” https://buff.ly/2pbZmBZ Support (from the core devs, the PSF, and python.org) stops completely on that date.

Follow up and other news


Eve: MongoDB & Flask-backed RESTful APIs course is out! https://training.talkpython.fm/courses/explore_eve/eve-building-restful-mongodb-backed-apis-course Shoutout to everyone I met at PyCon Slovakia


A couple of recent episodes on Test & Code focusing on project test development: What tests to write first Prioritize software tests with RCRCRC Upcoming topics will include beefing up test coverage with things like equivalence partitioning, boundary value analysis, state transition diagrams, state tables, negative testing, … Also learning a lot about developing an open source project and all the tools surrounding that. I’ll discuss those topics in episodes as well. Project used in both episodes, cards : a project task tracking / todo list app that will be expanded as I go along talking about different test and software development topics.

#68 Python notebooks galore!

Mar 6, 2018 00:19:09


Sponsored by DigitalOcean! http://do.co/python

Brian #1: dumb-pypi

This takes some fiddling with and trial and error. I definitely need to write up my experiences with this as a blog post. Combine with pip download (covered in episode 24), this makes it super easy to create a static locally hosted pypi server, either for all of your packages, or for your proprietary packages. Roughly: pip download -d my-packages-dir <package name> ls my-packages-dir > package-list.txt dumb-pypi --package-list my-packages-dir \ --packages-url <url of my server> \ --output-dir my-pypi Now add something like this to requirements.txt or pip commands: --trusted-host <my server name> -i http://<my server>/my-pypi/simple

Michael #2: Requests-HTML: HTML Parsing for Humans

This library intends to make parsing HTML (e.g. scraping the web) as simple and intuitive as possible. When using this library you automatically get: Full JavaScript support! CSS Selectors (a.k.a jQuery-style, thanks to PyQuery). XPath Selectors, for the faint at heart. Mocked user-agent (like a real web browser). Automatic following of redirects. Connection–pooling and cookie persistence. The Requests experience you know and love, with magical parsing abilities

Brian #3: A phone number proxy

Naomi Pentrel, @naomi_pen on twilio blog Set up a phone number that you can share for temporary events to send and receive texts that get forwarded to your actual number.

Michael #4: Notebooks galore part 1: Datalore

In cloud and ready to go Intelligent code editor Out-of-the-box Python tools Collaboration Integrated version control Incremental calculations: Improve and adjust models without hustling with additional recalculations. Datalore follows dependencies between multiple computations and automatically applies relevant recalculations.

Brian #5: bellybutton

by Chase Stevens, @hchasestevens Tool for creating personal static analysis/style tools like pycodestyle, pylint, and flake8 Teams often have some of their own style requirements that can’t be expressed as flake8 flags and exceptions. Example: deprecating internal library functions and catching that by the linter.

Michael #6:Notebooks galore part 2

Python 3.6 Jupyter Notebook on Azure Google Colaboratory JupyterLab is Ready for Users JupyterLab is an interactive development environment for working with notebooks, code and data. Most importantly, JupyterLab has full support for Jupyter notebooks. Additionally, JupyterLab enables you to use text editors, terminals, data file viewers, and other custom components side by side with notebooks in a tabbed work area. you can pip install python packages within python code itself. Super useful in situation #1 when you need a package that's not included but you don't have access to the shell. If you need to upgrade a package. For example the Pandas version is a little old on Azure, so you can upgrade by simply running: import pip pip.main(['install', 'pandas', '--upgrade'])

#67 Result of moving Python to Github

Mar 1, 2018 00:21:56


Sponsored by DigitalOcean! http://do.co/python

Brian #1: Building a blog with Pelican

We did cover Pelican in episode 38, but this is a nice tutorial in 7 parts on building a blog. Peter Kazarinoff, @pkazarinoff Nice blog with a focus on engineering students. Starts with installing Python and git and some other tools. Step by step, every action to get a a blog up as a static site hosted on github pages.

Michael #2: Notifiers

Got an app or service and you want to enable your users to use notifications with their provider of choice? Working on a script and you want to receive notification based on its output? A one stop shop for all notification providers with a unified and simple interface. A unified interface means that you already support any new providers that will be added, no more work needed! Some providers Slack Gmail Telegram Gitter … Python 3 only

Brian #3: Using Makefiles in Python projects

Krzysztof Żuraw, @krzysztof_zuraw Alerted to this article from kidpixo, @kidpixo We don’t usually think of Makefiles and Python together, but they can be a handy place to keep common scripts for a project all in one place. This article is a nice gentle intro to Makefiles and shows some cool uses: cleaning out .pyc files cleaning out egg directories linting running tests with flags starting a test server deploying sorting import files

Michael #4: Result of moving Python to Github

See the graph linked in the post A couple of quick numbers (including PRs too) from 2017 compared to 2016: the number of commit has increased by 190% inserted lines of code has increased by 140% number of unique contributors has increased by 1300% number of returning contributors has increased by 900% One comment was: “Personally, I would like them moving to Gitlab instead, but still good news.” I tend to disagree.

Brian #5: Self-Deprecation Needs to Stop

Maurice Hayward, @maurice_hayward Inspired by some tweets by Stephanie Hurlburt, @sehurlburt Stop saying these words when describing yourself or your accomplishments. These words are now under BAN: "My project is..." - very small/basic/simple - not that good - a thing I wrote - just by a newbie - something I didn't spend a lot of time/effort on - silly - not that useful Just state the topic and let others be the judge. Really think about the value you bring, then let everybody know. Be Proud of Yourself!

Michael #6: 5 speed improvements in Python 3.7

Calling methods faster (maybe) Python 3.7 adds 2 new Opcodes, LOAD_METHOD and CALL_METHOD for when the compiler sees x.method(...) it uses these new Opcodes. Bound methods with no arguments are now faster str.find() is faster for some characters Some unicode characters have an unfortunate issue when scanning a string for occurrences using str.find(x), seeing up to 25x slow down. These are still slower, but now 3x slower than ASCII characters instead of 25x! os.fwalk is 2x faster Regular expressions are faster A change was made in Python 3.6 which slowed down this call when flags were passed which were integers. Python 3.7 “fixes” the slowdown but is still not as fast as Python 3.5 Regular expressions are faster for case-insensitive matching The speed improvement is significant, if you’re matching ASCII characters you can see up to a 20x improvements in matching time since it’s now doing a lookup instead of running lower() over each character.

Follow up and other news


Python package maintainers, help test the new PyPI! pytest/pycharm webinar is up.

#66 Wait, NoSQL with ACID and transactions?

Feb 23, 2018 00:21:43


Sponsored by Rollbar: https://pythonbytes.fm/rollbar

Brian #1: Object-Oriented Programming (OOP) in Python 3

Real Python Nice modern introduction to classes, inheritance, and OOP. Classes, objects, attributes, instances, and inheritance. One gotcha not mentioned The __init__() method of a base class is not called automatically by derived classes. If you override it, you need to call super().__init__(). Also, check out attrs for much of our OOP needs

Michael #2: ScriptedForms

Quickly create live-update GUIs for Python packages using Markdown and a few custom HTML elements. Just write in markdown + variables / UI types Based on Jupyter

Brian #3: MongoDB to add multi-document transactions and ACID

Mind blown. Didn’t see this coming “MongoDB 4.0 will add support for multi-document transactions, making it the only database to combine the speed, flexibility, and power of the document model with ACID data integrity guarantees. Through snapshot isolation, transactions provide a globally consistent view of data, and enforce all-or-nothing execution to maintain data integrity.” Due out this summer.

Michael #4: Python packaging pitfalls

Just a short list of packaging blunders Forgetting to clean the build dir Forgetting to specify package data Fine grained MANIFEST.in Using package_data, or worse: fine grained package_data Listing excludes/prunes before includes/grafts Hardcoding packages list in setup.py Hardcoding py_modules list in setup.py Importing your package in setup.py Importing unavailable tools in setup.py Messing with the environment Your tests do not test the installed code

Brian #5: Blogging principles

Julia Evans @b0rk Be honest about what you know Try not to write anything too long. (My note: don’t shy away from long tutorials. Just don’t only do long stuff) Be positive. Write for the past you. Stick with your own experience. It’s ok if not everyone likes it Don’t try to keep one upping yourself.

Michael #6: pipenv is officially official

Pipenv — the officially recommended Python packaging tool from Python.org, free (as in freedom). Pipenv is a tool that aims to bring the best of all packaging worlds (bundler, composer, npm, cargo, yarn, etc.) to the Python world. Windows is a first–class citizen, in our world. Benefits? It automatically creates and manages a virtualenv for your projects adds/removes packages from your Pipfile as you install/uninstall packages generates the ever–important Pipfile.lock, which is used to produce deterministic builds.

Follow up and other news


Productive pytest with PyCharm webinar was recorded Thursday 22nd of Feb. Will be available here: https://www.jetbrains.com/community/webinars/


Embed Python in Unreal Engine 4 https://github.com/20tab/UnrealEnginePython Pandas documentation sprint https://python-sprints.github.io/pandas

#65 Speed of your import statements affecting performance?

Feb 14, 2018 00:27:07


Sponsored by Rollbar: pythonbytes.fm/rollbar

Brian #1: pygal : Simple Python Charting

Output SVG or PNG Example Flask App (also django response) part of documentation. Enough other bits of doc to get you a chart in a web page super fast.

Michael #2: Thoughts on becoming a self-taught programming

Basic format: I'm 31 days into self-studying Python and am loving every minute of it! A few questions: What were you doing before you began self-studying programming? What made you want to study programming on your own? How did you start (which resources and language)? How long did it take for you to feel confident enough in your skills and knowledge to know you could be employed as a programmer? What else did you do besides self-study that helped you in your journey to becoming a programmer? What's next for you?

Brian #3: How to speed up Python application startup time (timing imports in 3.7)

Python 3.7 includes -X importtime option that allows you to profile the time it takes to do all the imports. Way cool tool to help optimize the startup time of an application.

Michael #4: AnPyLar - The Python web front-end framework

Create web applications with elegance, simplicity and yet full power with Python and components MISSION: Empower all Python programmers to work not only on the back-end but also on the front-end with the same language of choice Features Reactive programming and Promises Python standard formatting as templates reusable components Scoped styling for component Integrated routing engine

Brian #5: Migrating to Python 3 with pleasure

“A short guide on features of Python 3 for data scientists” Quick tutorial through examples of pathlib. Type hinting and how cool it works with editors (PyCharm example shown) Adding runtime type enforcement for specific methods using enforce Using function annotations for units, as done in astropy. Matrix multiplication with @. Globbing with **. found_images = glob.glob('/path/**/*.jpg', recursive=True) Also … underscores in numeric literals, f-strings, true division with /, integer division with //, and lots of more fun goodies.

Michael #6: Moving to Python 3

Many of these issues were corrected just by running 2to3, which not only fixed many of the compatibility issues Outdated external libraries which needed to be updated to newer versions featuring Python 3 compatibility basestring to str, urlparse to urllib.urlparse and similar major changes Dictionary change like iteritems() to items(), or .items() now returning a view. Things that weren't needed anymore, like Django's force_unicode or __future__ library tools. Once we finished working on the "low-hanging fruits", the next step was to run Aphrodite's test suite and achieve zero errors. Lessons learned Code coverage was originally around 70%, Keeping the Python 3 branch up to date with master A non-trivial feature was delivered during the migration (via feature branch) The pickle protocol version in python 3 can be higher than the highest available in Python 2.7. So we needed to add versioning to our Django caches Each modified file had to comply with flake8 linting rules Afrodita is currently running on Google App Engine Flexible, and one of the features our team loves with is traffic splitting With this feature, we can do canary releases with ease: We just deploy our new version of the service, and start redirecting small amounts of traffic traffic while we monitor for unexpected errors. After some minor bugfixes, we could bring the traffic of the Python 3.6 version to 100% with confidence. We also had the old version available for instant rollback, thanks to how parallel versions and traffic splitting work in GAE flexible.

Our news


Upcoming webinar: Productive pytest with Pycharm


My GUI example: https://github.com/mikeckennedy/pyramid-web-builder-python-gui

#64 The GUI phoenix rises with wxPython

Feb 9, 2018 00:21:01


Sponsored by DigitalOcean: http://do.co/python

Brian #1: wxPython 4, Pheonix is now live and supports Python 3

wxPython on PyPI 4.0.0, 4.0.1 release notes If you haven’t played with wxPython for a while, now might be a good time.

Michael #2: typeshed

Typeshed contains external type annotations for the Python standard library and Python builtins, as well as third party packages. This data can e.g. be used for static analysis, type checking or type inference. Used as the basis of mypy and PyCharm’s magic Each Python module is represented by a .pyi "stub". This is a normal Python file (i.e., it can be interpreted by Python 3), except all the methods are empty. Python function annotations (PEP 3107) are used to describe the types the function has. Here’s what one of these exeternal definitions looks like: class NodeVisitor(): def visit(self, node: AST) -> Any: ... def generic_visit(self, node: AST) -> None: ...

Brian #3: Coverage 4.5 adds configurator plug-ins

“There’s one new feature: configurator plug-ins, that let you run Python code at startup to set the configuration for coverage. This side-steps a requested feature to have different exclusion pragmas for different versions of Python.”

Michael #4: Python integrated into Unreal Engine

via Pirogov Alexander‏ ( @Pie_Daddy ) tl;dr: Autodesk university plans to integrate Python into Unreal Engine for the data integration pipeline and ease the process of bringing assets into the game. Autodesk is working on that will solve complicated problems with bringing CAD data into the Unreal Engine. Where they are today: The Datasmith workflow toolkit, currently in beta, makes moving data into Unreal Engine as frictionless as possible. Datasmith provides high-fidelity translation of common scene assets such as geometry, textures, materials, lights and cameras from popular DCC and CAD applications into Unreal Engine.

Brian #5: Python 3.7.0b1 : Beta means we should be testing it!!!

If not people like us and our listeners, then who? Seems like we’re a good set of beta testers. What are you going to test? I'm going to look at breakpoint() and data classes.

Michael #6: Releases abound!

Django security releases issued: 2.0.2 and 1.11.10 https://www.djangoproject.com/weblog/2018/feb/01/security-releases/ Python 3.4.8 (security) https://www.python.org/downloads/release/python-348/ Python 3.5.5 (security) https://www.python.org/downloads/release/python-355/ libexpat XML lib had a security issue Channels 2.0 is a major rewrite of Channels https://channels.readthedocs.io/en/latest/releases/2.0.0.html See Talk Python’s interview for more details Notably: Python 2.7 and 3.4 are no longer supported.

Our news


Speaking at PyCon 2018. “PyCharm and pytest”. Speaking with Paul Everitt Upcoming webinar: Productive pytest with Pycharm Feb 22, registration open


Webinar Recording: “MongoDB Quickstart with Python and PyCharm” with Michael Kennedy

#63 We're still on a desktop GUI kick

Feb 1, 2018 00:21:12


Sponsored by DigitalOcean: http://do.co/python

Brian #1: A brief tour of Python 3.7 data classes

a great write-up of the upcoming data classes via Anthony Shaw “Data classes are a way of automating the generation of boiler-plate code for classes which store multiple properties. They also carry the benefit of using Python 3’s new type hinting.” Default magic methods In the default setting, any dataclass will implement __init__, __repr__, __str__ and __eq__ for you. The __init__ method will have keyword-arguments with the same type annotations that are specified on the class. The __eq__ method will compare all dataclass attributes in order. All fields are declared at the top of the class and type hinting is required. Also covered type hinting mutability (and frozen) customizing the fields post-init processing : optional __``*post_init_*``_ will run after the generated _``*_init_*``_ inheritance

Michael #2: SQLite [The Databaseology Lectures - CMU Fall 2015]

Lots of DBs covered here: http://db.cs.cmu.edu/seminar2015/ SQLite at this YouTube video

Brian #3: dryable : a useful dry-run decorator for python

short circuit methods within your project during dry runs. example shows how to add a command line flag --dry-run. The test code is useful for understanding it also.

Example something.py import dryable

@dryable.Dryable('foo') def return_something(): return 'something'


from something import return_something import dryable def test_normal_return(): dryable.set(False) assert return_something() == 'something' def test_dry_return(capsys): dryable.set(True) assert return_something() == 'foo'

Michael #4:

These are some pretty cool examples. https://github.com/victordomingos/PT-Tracking/ https://github.com/victordomingos/RepService/ https://github.com/victordomingos/ContarDinheiro.py

Brian #5: PEP Explorer - Explore Python Enhancement Proposals

Cool idea. Might need some work though. I can’t find any accepted PEPs for 3.7, including 557, data classes. I’m ok with giving Anthony some shade on this, as we highlighted his writing in the first item.

Michael #6: TKInter Tutorial

via @likegeeks Create your first GUI application Create a label and button widgets Input and combo boxs, menus, progressbars and more Our news


I built something with Gooey this weekend, it was wonderful. Self-serve team purchases and discounts at Talk Python Training

#62 Wooey and Gooey are simple Python GUIs

Jan 26, 2018 00:28:41


Brought to you by Datadog pythonbytes.fm/datadog

Brian #1: Dan Bader takes over Real Python

Announcement email, with what Michael, Fletcher, and Jeremy are doing now Dan is on the show and tells us all about it.

Michael #2: Still more Python GUIs

https://github.com/wooey/Wooey A Django app that creates automatic web UIs for Python scripts. Wooey is a simple web interface to run command line Python scripts. Think of it as an easy way to get your scripts up on the web for routine data analysis, file processing, or anything else. Wooey was envisioned as a system to allow data analysts to be able to easily: Autodocument workflows for data analysis (simple model saving). Enable fellow co-workers with no command line experience to utilize python scripts. Enable the easy wrapping of any program in simple python instead of having to use language specific to existing tools such as Galaxy. Try the demo server: https://wooey.herokuapp.com/ https://github.com/chriskiehl/Gooey Turn (almost) any Python command line program into a full GUI application with one line See the screenshots here Gooey converts your Console Applications into end-user-friendly GUI applications. It lets you focus on building robust, configurable programs in a familiar way, all without having to worry about how it will be presented to and interacted with by your average user. And Toga: https://pybee.org/project/projects/libraries/toga/

Brian #3: Python’s misleading readability

Ned Batchelder is and or are not obvious and can confuse people new to the language, new to programming. 1000 + 1 is 1001 → 1000 + 1 == 1001 answer == "y" or "yes``" → answer in {"y", "yes"}

Michael #4: warp2 access

python2 code from python3 It communicates with the subprocess using pickle, so there are limitation to using it - if you need to send unpicklable data, that’s a problem.

Brian #5: Help! My tests can’t see my code!

Probably should be an episode on Test & Code, and maybe I’ll do that also, but it’s a big enough roadblock to many newcomers to pytest, that I want to get the word out on how to fix it. A best practice is to put your test code in a folder called tests. Now, if you are sitting in the parent directory, where you can see both your modules/packages under test and the tests directory, and you run pytest, your test code has to have some way to import the code under test. If you are in a hurry. Homework due in an hour, project manager breathing down your neck, or whatever, then there are two easy options: python -m pytest python adds the current directory where you start it to PYTHONPATH, pytest does not. pip install pytest-pythonpath https://pypi.python.org/pypi/pytest-pythonpath This plugin adds the current directory to PYTHONPATH, and adds some hooks that let you define search paths in your pytest.ini file. When you have time.. Create a setup.py file for your code. And… pip install -e ./your_project This allows you to continue working on your code while letting your test code see the code under test This method is friendlier to tox.

Michael #6: Cement - Framework for CLI

Cement is an advanced CLI Application Framework for Python. Its goal is to introduce a standard, and feature-full platform for both simple and complex command line applications Also supports rapid development needs without sacrificing quality. Core features Core pieces of the framework are customizable via handlers/interfaces Extension handler interface to easily extend framework functionality Config handler supports parsing multiple config files into one config Argument handler parses command line arguments and merges with config Log handler supports console and file logging Plugin handler provides an interface to easily extend your application Hook support adds a bit of magic to apps and also ties into framework Handler system connects implementation classes with Interfaces Output handler interface renders return dictionaries to console Cache handler interface adds caching support for improved performance

Our news


Conferences! PyCascades in Vancouver BC on Jan 22, 23. Was great, get to it next year. PyColumbia, February 9, 10 and 11 Medellin, Colombia - I won't be there but if you are able to make it get your tickets PyCon Slovakia, March 9-11 in Bratislava. I'll be speaking there and doing a workshop. pycon us: Cleveland OH May 10th. I just finalized all my travel plans. I hope to see you there, please stop by our booth. PyCarribian: Santo Domingo, Dominican Republic, 17-18 February, 2018 Podcast http://pythonoutloud.com/

#61 On Being a Senior Engineer

Jan 16, 2018 00:22:22


Sponsored by DigitalOcean: http://do.co/python

Brian #1: PEP 412's dict key sharing for classes

"memory use is reduced by 10% to 20% for object-oriented programs with no significant change in memory use for other programs." To benefit from this, make sure all attributes used in life of class instances are initialized within __init__(). Video from PyCon 2017 Brandon Rhodes The Dictionary Even Mightier PyCon 2017 Look at description at about 14 minutes on in the video Suggested by Ned Letcher

Michael #2: Python Hunter

via Ivan Pejić Hunter is a flexible code tracing toolkit, not for measuring coverage, but for debugging, logging, inspection and other nefarious purposes. It has a Python API, terminal activation (see Environment variable activation). and supports tracing other processes (see Tracing processes). The default action is to just print the code being executed Based on cython

Brian #3: Ten Things I Wish I’d Known About bash

I started with ksh on Solaris/HP-UX, used zsh for few years. Mostly now, I use bash, because it’s everywhere. Mac/Windows/Linux For windows: git for windows Even if you don't need git, git for windows comes with fully integrated unix tools and bash and it just works as you expect. you can launch windows applications most of the frequent bash commands are there If you really don’t want bash, consider cmder

Michael #4: Snakefooding Python Code For Complexity Visualization

Snakefood is a tool written by Martin Blais to create Python dependency graphs. Combined with GraphViz, snakefood can create beautiful visualizations of Python codebases. Python Web Frameworks: The different development philosophies of Bottle, Django, Flask, and Pyramid are apparent by looking at their snakefood graphs. Bottle: A fast and simple micro framework for Python web applications. Django: A batteries-included web framework for perfectionists with deadlines. Flask: A microframework for Python. Pyramid: A small, fast, down-to-earth, open source Python web framework. It makes real-world web application development and deployment more fun, more predictable, and more productive. Also Queueing Implementations

Brian #5: On Being a Senior Engineer

2012 article that's still very valid Obligatory Pithy Characteristics of Mature Engineers Mature engineers ... seek out constructive criticism of their designs. understand the non-technical areas of how they are perceived. do not shy away from making estimates, and are always trying to get better at it. have an innate sense of anticipation, even if they don’t know they do. understand that not all of their projects are filled with rockstar-on-stage work. lift the skills and expertise of those around them. make their trade-offs explicit when making judgements and decisions. don’t practice CYAE (“Cover Your Ass Engineering”) are empathetic. don’t make empty complaints. are aware of cognitive biases: Self-Serving Bias Fundamental Attribution Error Hindsight Bias Outcome Bias Planning Fallacy The Ten Commandments of Egoless Programming Understand and accept that you will make mistakes. You are not your code. No matter how much “karate” you know, someone else will always know more. Don’t rewrite code without consultation. Treat people who know less than you with respect, deference, and patience. The only constant in the world is change. The only true authority stems from knowledge, not from position. Fight for what you believe, but gracefully accept defeat. Don’t be “the coder in the corner.” Critique code instead of people – be kind to the coder, not to the code. also: Novices versus Experts Dirty secret: mature engineers know the importance of (sometimes irrational) feelings people have. (gasp!) “It is amazing what you can accomplish if you do not care who gets credit.”

Michael #6: Python UI frameworks

TkInter (tutorial) - not amazing, not at all (example). PySide and Qt - hard to install, weird licensing and versioning, but has a nice designer Kivy and PyGame/PyOpenGL - game / simulation like wxPython seems not bad actually example widgets wxFormBuilder - a RAD tool for wxWidgets GUI design wxGlade is a GUI designer What else? A few platform specific examples The problem: was discussed last week Some more Electron.JS like solutions github.com/ChrisKnott/Eel Eel is a little Python library for making simple Electron-like offline HTML/JS GUI apps, with full access to Python capabilities and libraries. It hosts a local webserver, then lets you annotate functions in Python so that they can be called from Javascript, and vice versa. CEFPython - Chrome browser control, a HTML 5 based Python GUI framework.

#60 Don't dismiss SQLite as just a starter DB

Jan 11, 2018 00:26:29


Brought to you by Datadog pythonbytes.fm/datadog

Brian #1: Who's at nine?

Organic Idiocy Inspired by Michael talking about programming Alexa in episode 33 Twitter thread Using Flask-Ask for Alexa Flask-Assistant for Google Home Talk Python 146 is all about Flask Ask and Assistant this week. ;)

Michael #2: Retiring Python as a teaching language

Why did he write this? Then one day a student will innocently ask "Instead of running the poker simulator from the command line, how can I put it in a window with a button to deal the next hand?" The ensuing Twitter conversation was very interesting. Scroll this status, it’s pretty comprehensive https://twitter.com/mkennedy/status/949688651058835456

Brian #3: Don't dismiss SQLite as just a starter DB

SQLite is a single file db that comes with Python. A listener pointed us to a couple cool things about SQLite A great interview with the developer The Changelog, episode 201. It's extensive documentation on how SQLite is tested. Of course, for web applications and other applications that have to deal with extreme concurrency, you need a client server database Many applications don't have extreme concurrency needs. Sticking with SQLite might be just fine for quite a long time for many apps.

Michael #4: Chalice: Python Serverless Microframework for AWS

Chalice is a python serverless microframework for AWS. It allows you to quickly create and deploy applications that use Amazon API Gateway and AWS Lambda. It provides: A command line tool for creating, deploying, and managing your app A familiar and easy to use API for declaring views in python code (Flask) Automatic IAM policy generation Compare to Zappa: https://github.com/Miserlou/Zappa

Brian #5: Fastest way to uniquely a list in Python >=3.6

Nice analysis of different ways to uniquify a list. Punchline: The fastest way to uniqify a list of hashable objects (basically immutable things) is: list(set(seq)) And the fastest way, if the order is important is: list(dict.fromkeys(seq))

Michael #6: PyTexas and PyCon AU vidoes are up

PyTexas Notable PyTexas videos Micropython What is ML? C for yourself Python and .NET PyCon AU Notable PyCon AU videos Gradual typing Hot reloading Python web-servers at scale Prototyping Python Microservices in Production Secrets of a WSGI master. Python 3 for People Who Haven't Been Paying Attention Identity 2.0: the what, why and how of social and federated login Python: Ludicrous mode (with Django) Scaling Down: Running Large Sites Locally

Our news


Mastering PyCharm is out. Includes

Learn to manage Python projects in PyCharm (large and small) Create web applications (Pyramid, Flask, Django, and more) Use PyCharm's special data science mode Refactor your Python code with confidence Learn about code smells and duplicate code tooling Access git, github, and use git flow Use the visual debugger to understand code flow and state Make your code more reliable with unit testing and pytest Create new Python packages And lots more

Webcast with JetBrains: MongoDB Quickstart with Python and PyCharm Jan 30

#59 Instagram disregards Python's GC (again)

Jan 5, 2018 00:25:39


Sponsored by DigitalOcean: do.co/python

Brian #1: gc.freeze() and Copy-on-write friendly Python garbage collection

Copy-on-write friendly Python garbage collection - Instagram gc.freeze() now part of Python 3.7 - github pull request

Michael #2: SpeechPy - A Library for Speech Processing and Recognition

A Library for Speech Processing and Recognition More foundation for data science than shooting out words. Based on MFCC (Mel Frequency Cepstral Coefficient) The first step in any automatic speech recognition system is to extract features i.e. identify the components of the audio signal that are good for identifying the linguistic content and discarding all the other stuff which carries information like background noise, emotion etc. Citation section is a nice touch

Brian #3: PyBites Code Challenges : Bites of Py

Like code katas, coding challenges you can do on your own. “Bites of Py are self contained 20-60 min Python (3.6) code challenges you can code and verify in the browser.” Use pytest to check answers See pytest output so you can partially solve challenges and see where it fails. BTW, min() takes a key, like sort() and sorted(). I learned that this morning.

Michael #4: How big is the Python Family

CPython, Jython, IronPython, Python for .NET, Cython, PyPy, MicroPython, and recently Grumpy This is why I don’t like the word “Python interpreter” but rather use “Python runtime” even though it’s less common.

Brian #5: Dramatiq: simple task processing

Interview on Podcast.init Cookbook included in documentation to get started pretty quick. Inspired by Celery, but probably a bit easier to get into if you are new to task processing. License is interesting

Michael #6: Controlling Python Async Creep

From friend of the show Cristian Medina Boundary between sync and async can get tricky The complication arises when invoking awaitable functions. Doing so requires an async defined code block or coroutine. A non-issue except that if your caller has to be async, then you can’t call it either unless its caller is async. Which then forces its caller into an async block as well, and so on. This is “async creep”. Solutions or techniques Waiting for blocks of async code The general guideline is to start with things that wait on I/O, like file or socket access, HTTP requests, etc. Once you know which pieces to optimize, start identifying the ones that can run on top of each other. Nice example using a web service Use a thread Next example creating a dedicated asyncio loop in the secondary thread Mixing sync and async Let’s look at something more complicated. What if you have a library or module where most functions can run in parallel, but you only want to do so if the caller is async? This could prove useful to any python packages that are wanting to add support for asynchronous execution while still supporting legacy code.

Extra (michael): The PyTennessee conference will be held February 10-11, 2018. We recently announced our schedule (https://www.pytennessee.org/schedule/), and tickets are on sale now (https://pytn2018.eventbrite.com/). A smaller, regional conference is a great way to meet people, make new Python friends, and hear some great talks without having to fight the crowds of the larger conferences.

If anyone wants to buy a ticket and wants a 10% discount, they can use the code PythonBytes during checkout.

In the news

Not much to do about this but pay attention: A critical design flaw in virtually all microprocessors allows attackers to dump the entire memory contents off of a machine/mobile device/PC/cloud server etc. https://twitter.com/nicoleperlroth/status/948684376249962496 https://www.nytimes.com/2018/01/03/business/computer-flaws.html Probably excellent coverage on https://risky.biz/ From NY Times: The two problems, called Meltdown and Spectre, could allow hackers to steal the entire memory contents of computers, including mobile devices, personal computers and servers running in so-called cloud computer networks. There is no easy fix for Spectre, which could require redesigning the processors, according to researchers. As for Meltdown, the software patch needed to fix the issue could slow down computers by as much as 30 percent — an ugly situation for people used to fast downloads from their favorite online services.

Our news

Michael: Everything Bundle: talkpython.fm/everything

Includes Mastering PyCharm, Python 3: An Illustrated Tour, Intro to Ansible, and much more.

#58 Better cache decorators and another take on type hints

Dec 26, 2017 00:15:27


Sponsored by DigitalOcean: http://do.co/python

Brian #1: Instagram open sources MonkeyType

Carl Meyer, an engineer on Instagram’s infrastructure team. (Note: we talked about Dropbox’s pyannotate in episode 54. pyannotate is not on Python3 yet and generates comment style annotations that are Py2 compatible) MonkeyType is Instagram’s tool for automatically adding type annotations to your Python 3 code via runtime tracing of types seen. Requires Python 3.6+ Generates only Python 3 style type annotations (no type comments)

Michael #2: cachetools

Extensible memoizing collections and decorators Think variants of Python 3 Standard Library @lru_cache function decorator Caching types: cachetools.Cache Mutable mapping to serve as a simple cache or cache base class. cachetools.LFUCache Least Frequently Used (LFU) cache implementation cachetools.LRUCache Least Recently Used (LRU) cache implementation cachetools.TTLCache LRU Cache implementation with per-item time-to-live (TTL) value. And more Memoizing decorators cachetools.cached Decorator to wrap a function with a memoizing callable that saves results in a cache. Note that cache need not be an instance of the cache implementations provided by the cachetools module. cached() will work with any mutable mapping type, including plain dict and weakref.WeakValueDictionary. Can pass key function for hash insertions and lock object for thread safety.

Brian #3: Going Fast with SQLite and Python

Charles Leifer Many projects start with SQLite, as it’s distributed with Python as sqlite3. This article discusses some ways to achieve better performance from SQLite and shares some tricks. transactions, concurrency, and autocommit user-defined functions using pragmas compilation flags

Michael #4: The graphing calculator that makes learning math easier.

A full graphing calculator Programmable in Python Exam approved: Take the SAT and the ACT. Free browser emulator

Brian #5: Installing Python Packages from a Jupyter Notebook

Jake VanderPlas using conda import sys !conda install --yes --prefix {sys.prefix} numpy using pip import sys {sys.executable} -m pip install numpy plus a discussion of why this is weird in Jupyter

Michael #6: Videos from PyConDE 2017 are online

via Miroslav Šedivý @eumiro Lots of interesting talk titles Almost all in English

#57 Our take on Excel and Python

Dec 21, 2017 00:15:48


Sponsored by DigitalOcean: http://digitalocean.com

Brian #1: Testing Python 3 and 2 simultaneously with retox

Anthony Shaw tox allows you to run the same tests in multiple configurations. For example, multiple Python interpreters (2 vs 3), or on different hardware, or using different options, etc. tox can also tests your packaging code (on by default, but can be disabled) detox allows multiple configurations to be tested in parallel with multiprocessing typically running all tests 2-4 times faster retox does this with a GUI also adds “watch” capability

Michael #2: Robo 3T / RoboMongo

MongoDB GUI with embedded shell CLI interaction GUI when you want it No. 34 repository on GitHub

Brian #3: regular expressions

Regular Expressions Practical Guide Python examples for some common expressions How to use the built in re package for email addresses, URLs, phone numbers substitution with re.sub() splitting a string with re.split() what some of the escape shortcuts mean, like \w for word, \s for whitespace, etc. iterating through matches with re.finditer() Using compiled expressions Regular Expressions for Data Scientists another great intro, that also talks about: re.search() re.findall() match groups

Michael #4: MongoEngine

MongoEngine is a Document-Object Mapper (think ORM, but for document databases) for working with MongoDB from Python. Map classes to MongoDB (think SQLAlchemy but for document databases) Adds features lacking from MongoDB Schema Required fields Constraints Relationships

Brian #5: Introducing PrettyPrinter for Python

a powerful, syntax-highlighting, and declarative pretty printer for Python 3.6 goals Implement an algorithm that tries very hard to produce pretty output, even if it takes a bit more work. Implement a dead simple, declarative interface to writing your own pretty printers. Python developers rarely write __repr__ methods because they're a pain; no one will definitely write pretty printing rules for user-defined types unless it's super simple. Implement syntax-highlighting that doesn't break on invalid Python syntax.

Michael #6: Excel and Python

Replace VBA Python in Excel as the main scripting language They need feedback (fill out their survey, upvote the issue)

Our news

Michael: * Webcast: https://www.wintellect.com/webinar/lets-build-something-mongodb-python/

#56 The pendulum of time swings beautifully in PyPI

Dec 14, 2017 00:16:29


Sponsored by Rollbar! pythonbytes.fm/rollbar

Brian #1: Pendulum for datetimes

on github See also arrow maya datetime, and Dealing with datetimes like a pro in Python dateutil

Michael #2: Flask asynchronous background tasks with Celery and Redis

Easiest way to a significant scalability to your app: queuing What is Celery: Celery is an asynchronous task queue/job queue based on distributed message passing. It is focused on real-time operation, but supports scheduling as well How Celery works: Celery client: This will be connect your Flask application to the Celery task Celery worker: A process that runs a background task Message broker: The Celery client communicates to the Celery worker through a message broker (redis in this case) All examples on Windows

Brian #3: Building a Simple Web App With Bottle, SQLAlchemy, and the Twitter API

Guest article on RealPython, by Bob Belderbos of PyBytes Fun full project start to finish using Tweepy to load tweets. Ends with a bottle app running on Heroku

Michael #4: Python extension for VSCode updated, now brought to you by Microsoft

Don Jayamanne, creator of the Python extension for Visual Studio Code, joins Microsoft Full announcement: https://blogs.msdn.microsoft.com/pythonengineering/2017/11/09/don-jayamanne-joins-microsoft/ Had Don on Talk Python back on episode 101. What does Microsoft Python team publishing the extension mean? For all practical purposes the transition should be transparent to you. Additionally: The extension will remain open source and free Development will continue to be on GitHub, under the existing license More dev resources means (generally) faster turnaround on bug fixes and new features Microsoft is hiring for Visual Studio Code / Python! They are hiring devs immediately to continue and expand work on our Python support for Visual Studio Code. If you are passionate about developer tools and productivity, this could be an ideal endeavor!

Brian #5: A Comprehensive Guide To Web Design

Crash course in web design principles, not the mechanics

Michael #6: Requestium

Integration layer between Requests and Selenium for automation of web actions. Merges the power of Requests, Selenium, and Parsel into a single integrated tool for automatizing web actions. The library was created for writing web automation scripts that are written using mostly Requests but that are able to seamlessly switch to Selenium for the JavaScript heavy parts of the website, while maintaining the session. Features Enables switching between a Requests' Session and a Selenium webdriver while maintaining the current web session. Integrates Parsel's parser into the library, making xpath, css, and regex much cleaner to write. Improves Selenium's handling of dynamically loading elements. Makes cookie handling more flexible in Selenium. Makes clicking elements in Selenium more reliable. Supports Chrome and PhantomJS.

Our news

Test & Code 33: Testing in Data Science with Kathrine Jarmul Thanks to the 9 folks to that have left an Amazon review for Python Testing with pytest.

#55 Flask, Flask, Flask, 3x Flask

Dec 7, 2017 00:20:18


Sponsored by DigitalOcean: http://digitalocean.com

Brian #1 The Flask Mega-Tutorial, reborn

This very popular tutorial, written in 2012, has been rewritten. Miguel Grinberg has rewritten it with the help of a kickstarter campaign. Part 1 of the tutorial is up, and he’s releasing 1 part per week. Want it faster, you can get it all in an eBook right now. A video version is coming in January.

Michael #2: Django 2.0 Released

This release starts Django’s use of a loose form of semantic versioning Features A simplified URL routing syntax that allows writing routes without regular expressions. A responsive, mobile-friendly contrib.admin. Window expressions to allow adding an OVER clause to querysets. Python 3 only django.contrib.auth The default iteration count for the PBKDF2 password hasher is increased from 36,000 to 100,000. Lots more changes

Brian #3: The Big Ol' List of Rules

Flake8 is a popular code linter that combines pyflakes, pycodestyle, and mccabe. pycodestyle is the new pep8 to enforce PEP8 suggestions. These are mostly style guide items, and not actual bugs. pyflakes is more like a traditional linter in that it catches things that are probably oversight or bugs. mccabe is harder to explain, but it generally tells you if your code might be too complicated, using Cyclomatic Complexity. Flake8 produces error codes if your code has problems Ennn and Wnnn for pycodestyle errors and warnings Fnnn for pyflakes errors Cnnn for mccabe errors The The Big Ol' List of Rules is a very nice breakdown of every error, what it means, and has links to other documents where they are defined. Very nice work from Grant McConnaughey

Michael #4: requests-staticmock

via Anthony Shaw The Session object allows you to persist certain parameters across requests. It also persists cookies across all requests made from the Session instance, and will use urllib3's connection pooling. So if you're making several requests to the same host, the underlying TCP connection will be reused, which can result in a significant performance increase A Session object has all the methods of the main Requests API. requests-staticmock is a static HTTP mock interface for testing classes that leverage Python requests with no monkey patching!

Brian #5: PEP 557 -- Data Classes have been approved

You can play with them now if you want, with the 3.7.0a3 developer build. However, 3.7 isn’t scheduled for release until June 2018.

Very short Example lifted directly from PEP 557 doc.

@dataclass class C: a: int # 'a' has no default value b: int = 0 # assign a default value for 'b'

In this example, both a and b will be included in the added __init__ method, which will be defined as:

def __init__(self, a: int, b: int = 0): pass Why not just use attrs? (Also lifted from the pep doc) attrs moves faster than could be accommodated if it were moved in to the standard library. attrs supports additional features not being proposed here: validators, converters, metadata, etc. Data Classes makes a tradeoff to achieve simplicity by not implementing these features.

Michael #6: Quart: 3x faster Flask

Python has evolved since Flask was first released around 8 years ago, particularly with the introduction of asyncio. Asyncio has allowed for the development of libraries such as uvloop and asyncpg that are reported (here, and here) to improve performance far beyond what was previously possible. Quart provides the easiest transition for Flask apps to use asyncio as it shares the Flask-API. tl;dr: Upgrading this Flask-pyscopg2 app to a Quart-asyncpg app gives a performance speedup of 3x without requiring a major rewrite or adjustment of the code View methods become async / await methods

Our news


Pythonic staff of enlightnement I have already encountered the Pythonic Staff of Enlightenment, see the photo that Anthony tweeted of you guys brandishing it at PyCon US. Now so can you: https://www.enstaved.com/pythonic-staff-of-enlightenment-now-on-sale/

#54 PyAnnotate your way to the future

Nov 29, 2017 00:18:51


Sponsored by DigitalOcean. They just launched Spaces, get started today with a free 2 month trial of Spaces by going to do.co/python

Brian #1: The PSF awarded $170,000 grant from Mozilla Open Source Program to improve sustainability of PyPI

Situation The Python Packaging Index (PyPI) is the principal repository of software packages for the Python programming language. There are over 100 million Python packages are downloaded from PyPI every week. The Python community depends on PyPI for the ongoing functioning of the entire Python ecosystem. There are no paid staff at the PSF who work on PyPI, and there are only a handful of people who contribute regularly. This leads to a situation where we have to depend on volunteers to be on-call for outages and respond to critical security vulnerabilities in core Python Infrastructure. Next steps The first milestone for Warehouse is redirecting portions of the production pypi.python.org to Warehouse including traffic for the simple index and package downloads. At that milestone Warehouse will be the main entryway to Python packages for all but a small fraction of the interactions PyPI sees. The bulk of the work will be bringing Warehouse to feature parity with the administrative capabilities users need from the Package Index. We'll keep you posted as we figure out when you can expect that to be true.

Michael #2: Dropbox releases PyAnnotate

Mypy is an experimental optional static type checker for Python that aims to combine the benefits of dynamic (or "duck") typing and static typing You can develop programs with dynamic typing and add static typing after your code has matured, or migrate existing Python code to static typing. mypy is great, but it only works after you have added type annotations to your codebase. To easy the pain of adding type annotations to existing code, we’ve developed a tool, PyAnnotate, that observes what types are actually used at runtime, and inserts annotations into your source code based on those observations. We’ve now open-sourced the tool. run your code with a special profiling hook enabled. This observes all call arguments and return values and records the observed types in memory. At the end of a run the data is dumped to a file in JSON format. A separate command-line utility can then read this JSON file and use it to add inline annotations to your source code.

Brian #3: pytest-annotate is now open-source!

- Use pyannotate without a driver file: pip install pytest-annotate # to run code while collecting types pytest --annotate-output=./annotate.json # to see what will change with type hint comments pyannotate --type-info ./annotate.json <path_to_code> # to modify code pyannotate -w --type-info ./annotate.json <path_to_code>

Michael #4: Run Python script as systemd service

Great for making your own “services” on Linux Incredibly easy, just follow the gist linked above

Brian #5: pytest 3.3.0 released

changelog includes 12 new features Most excited about: Now pytest displays the total progress percentage while running tests. Now captures and displays output from the standard logging module.

Michael #6: Why d = {} is faster than d = dict()

It turns out that using str(), list(), dict() and tuple() for creating empty sequences isn't as fast as their shorthand counterparts ('', [], {}, ()). We can inspect what happens with the dis module…


F1 eSports now more exciting than real F1: https://arstechnica.com/cars/2017/11/formula-1-esports-now-more-exciting-than-the-real-thing-and-thats-a-problem/

#53 Getting started with devpi and Git Virtual FS

Nov 22, 2017 00:22:10


Sponsored by Rollbar! Get the bootstrap plan at pythonbytes.fm/rollbar

Brian #1: Exploring Line Lengths in Python Packages

Jake VanderPlas @jakevdp PEP8 recommends 79 character line lengths. This article looks at line lenghts used in NumPy, SciPy, Pandas, ScikitLearn, Matplotlib, and AstroPy In the form of a Jupyter notebook so you can follow along with all the code and graphs. Fitting the graphs to distributions. Closing questions from Jake: Where do other Python packages fit on the mode/spread graph? Has the coding style in these packages, reflected in line length, evolved over time? How do individual contributors behave? Do they tend to have similar habits across packages? What do these distributions look like for code written in other languages?

Michael #2: NumPy: Plan for dropping Python 2.7 support

The Python core team plans to stop supporting Python 2 in 2020. We found that supporting Python 2 is an increasing burden on our limited resources; thus, we plan to eventually drop Python 2. Our current plan is as follows. Until December 31, 2018, all NumPy releases will fully support both Python2 and Python3. Starting on January 1, 2019, any new feature releases will support only Python3.

Brian #3: How to Learn Pandas

Ted Petrou @TedPetrou Alternating between reading documentation and using it for small projects. Getting the most out of documentation Using Jupyter Notebook Using Kaggle kernels, which are datasets in the form of Jupyter notebooks. Creating your own kernels Try answering questions on SO to test your knowledge Set up some projects.

Michael #4: Microsoft and GitHub team up to take Git virtual file system to macOS, Linux

Watch the 10 min Microsoft presentation to understand this quickly. Git doesn’t work that well for larger projects Yes, it was built for Linux (640 MB) But there are larger projects Visual Studio and related tools: 3,000 MB (5x) Windows: 270 GB (421x), 4,000 people committing per day. solution was to develop Git Virtual File System (GVFS) Before virtual: 12 hours to clone 3 hours to checkout 8 min for git status 30 min to commit After virtual: 90 sec clone 30 sec checkout 3 sec git status 8 sec commit Microsoft says that, so far, about half of its modifications have been accepted upstream, with upstream Git developers broadly approving of the approach the company has taken to improve the software's scaling. GitHub is interested in this for the paid, enterprise side Currently Windows only but Microsoft and GitHub are also working to bring similar capabilities to other platforms, with macOS coming first, and later Linux.

Brian #5: Getting started with devpi

Stefan Scherfke @sscherfke A walkthrough of setting up and using devpi , a local mirror/cache/local store PyPI server. Setting up the server User management Working with package indexes Uploading packages Using it to point your pip at

Michael #6: Marketing-for-Engineers

A curated list of marketing tools and resources to grow your product such as: finding beta testers growing first user base advertising project without a budget scaling marketing activities for building constant revenue streams. What is the hardest part of creating a successful product / web app? (hint: it’s not programming or having the idea)


Black Friday Sale for Python Testing with pytest & all other pragmatic eBooks. From 11/22 through Friday 12/1, all ebooks at pragprog.com are 40% off. That makes the pytest book about $14 Use coupon code turkeysale2017 to get the discount. PyCon Columbia, @pyconcolombia, is February 9, 10 and 11 - 2018 and tickets are available now. (Recommended by Oscar Arbelaez)

#52 Call your APIs with uplink and test them in the tavern

Nov 16, 2017 00:21:40


Sponsored by DigitalOcean. They just launched Spaces, get started today with a free 2 month trial of Spaces by going to do.co/python

Brian #1: Restful API testing with Tavern

Michael #2: Uplink

RESTful client API via decorators Create a class to represent the API Add methods with arguments, map to API calls. e.g. @get("/users/{username}") def get_user(self, username): """Get a single user.""" Uplink includes support for concurrent requests with asyncio (for Python 3.4+) Twisted (for all supported Python versions) Not production ready, but very exciting.

Brian #3: Using json-schema for REST API endpoint tests

Sponsor DIGITAL OCEAN SPACES Get started today with a free 2 month trial of Spaces by going to do.co/python

Michael #4: Live coding to music!

via Ian Watt Talk at PyCon UK by Ryan Kirkbride called “Programming Music for Performance: Live coding with FoxDot”

Brian #5: Weekly Python Chat

Michael #6: 10 common beginner mistakes in Python

Via checkIO: https://py.checkio.org/ Incorrect indentation, tabs and spaces Using a Mutable Value as a Default Value Write a lot of comments and docstrings Scoping Edge cases first (let’s go easy on the indents) Copying Creating count-by-one errors on loops (range is half closed) Wrong capitalization Using class variables incorrectly

Our news


Flash briefing? Firefox Quantum!

#51 How to make your code 80 times faster

Nov 9, 2017 00:21:33


This episode is brought to you by Datadog: pythonbytes.fm/datadog

Brian #1: Exploring United States Policing Data with Python

How to take a publicly available data set and, using jupyter, ipython, matplotlib, numpy, pandas, and scipy: ask questions of the data and get answers visualize results with plots fill in and/or remove blank data The example is interesting, and easy to follow. It doesn’t explain all the code, just shows it. You can go look that stuff up later. A few notes as I worked through half of the example: pip install scipy step 1.7 plt.show() end of 2.3, don't need .to_html().replace('\n','') Use shift-enter to run a cell I’m concerned with the validity of the results due to the dropping of rows with missing data. Some columns aren’t used for some questions, so for those purposes, the data shouldn’t be abandoned. Still a very nice tutorial.

Michael #2: How to make your code 80 times faster

Often hear people who are happy because PyPy makes their code 2 times faster or so. Here is a short personal story which shows PyPy can go well beyond that. Evolutionary algorithms: the ambitious plan was to automatically evolve a logic which could control a (simulated) quadcopter To drive the quadcopter, a Creature has a run_step method which runs at each delta_t inputs is a numpy array containing the desired setpoint and the current position on the Z axis; outputs is a numpy array containing the thrust to give to the motors. To start easy, all the 4 motors are constrained to have the same thrust run_step is called at 100Hz simply tried to run this code on CPython: ~6.15 seconds/generation Then tried with PyPy 5.9: Ouch! We are ~5.5x slower than CPython. This was kind of expected: numpy is based on cpyext, which is infamously slow first obvious step is to use numpypy instead of numpy: PyPy+numpy, and more than 2x faster than the original CPython So, let's try to do better. As usual, the first thing to do is to profile and see where we spend most of the time. we know that the matrix is small, and always of the same shape. So, let's unroll the loop manually Tada: This is around 80 (eighty) times faster than the original CPython+numpy implementation, and around 35-40x faster than the naive PyPy+numpypy one

Brian #3: Giving Open-Source Projects Life After a Developer's Death

Michael #4: Solar Powered Internet Connected Lawn Sprinkler Project

via listener suggestion / written: Lenin a little project with Adafruit’s Feather HUZZAH board and MicroPython Combines with Home Assistant Mostly based on AdaFruit, they have a detailed list of the hardware used. based on the MQTT protocol, which is a Client-Server Internet of Things connectivity protocol, comes with micropython Nice references back to AdaFruit tutorials Talk Python #108: MicroPython and Open Source Hardware at Adafruit: https://talkpython.fm/108

Brian #5: Some New Python Books

Python Tricks: A Buffet of Awesome Python Features by Dan Bader Illustrated Guide to Python 3 by Matt Harrison While we’re at it, there are some older Python books that could use some review love. If you’ve read these, please leave a review. It helps more than you may realize. Python Testing with pytest, by Brian Okken Test-Driven Development with Python, by Harry Percival Two Scoops of Django, Daniel & Audrey Roy Greenfield

Michael #6: Anaconda Distribution 5.0 released

Over 100 packages have been updated or added to the distribution. JupyterLab alpha preview 0.27.0 is now included, and MKL has been updated to 2018.0.0. The new version features all new compilers on macOS and Linux, providing substantial security and performance improvements. Where possible, all build recipes are now using conda-forge as a base, via https://github.com/AnacondaRecipes. A new channel, pkgs/main, has been added to defaults. The new channel is given top priority within defaults and holds packages built with the new compiler stack. The new version of Anaconda Distribution now features more flexible dependency pinning.

#50 Bundling , shipping, and protecting Python applications

Nov 2, 2017 00:19:17


Python Bytes 50

Sponsored by DigitalOcean. They just launched Spaces, get started today with a free 2 month trial of Spaces by going to do.co/python

Brian #1: Think Like a Pythonista

2017, by @standupdev Luciano Ramalho The PyBay2017 playlist Covered in “Think Lika a Pythonista” Creating a container type, a Deck of Cards. Luciano shows how to utilize duck typing, builtin types, and operator overloading while creating a type without inheritance. Uses a Jupyter notebook to work with the code. Describes and shows monkeypatching to implement shuffle. Watch until the end, he takes feedback from the audience to optimize some code.

Michael #2: Serpent.AI - Game Agent Framework

Turn ANY video game in a sandbox environment for AI & Bot programming with Python. goal with Serpent.AI is to lower the barriers to entry when it comes to using games as sandboxes for code experiments. It unlocks your entire existing game library (Steam, DRM-Free etc.) to be used as potential game agent environments and it does so natively It also doesn't try to dictate how you solve your problems. Your game agent is your canvas! Even a twitch channel with live PyCharm + Jupyter + Game. Here’s a cool example: https://go.twitch.tv/videos/173580782 Provides some useful conventions but is absolutely NOT opinionated about what you put in your agents: Want to use the latest, cutting-edge deep reinforcement learning algorithm? ALLOWED. Want to use computer vision techniques, image processing and trigonometry? ALLOWED. Want to randomly press the Left or Right buttons? sigh ALLOWED.

Brian #3: MkDocs

I’ve been creating pytest plugins using the pytest-plugin cookiecutter. One option is to start the documentation using mkdocs, so I thought I’d try it out. For the most part, you have a yaml file to configure things, and a directory with markdown files in it. Then you call mkdocs build and blammo, your documentation is built. I like markdown, so I’m going to try working with mkdocs more. Also want to try: Generating documentation from source code using Christian Medina’s How to write your own Python documentation generator article and the code in a snippet, gendocs.py. I know about Sphinx, but I’m not a fan of reStructured text.

Michael #4: PyInstaller 3.3 released

PyInstaller is a program that freezes (packages) Python programs into stand-alone executables, under Windows, Linux, Mac OS X, FreeBSD, Solaris and AIX. The main goal of PyInstaller is to be compatible with 3rd-party packages out-of-the-box. Libraries like PyQt, Django or matplotlib are fully supported, without having to handle plugins or external data files manually. The #1 thing that stands out to me in this release: Python 3.6 support! PyInstaller can produce single immutable self contained dependency free portable exe files using the --one-file option. Consider the --noconsole option too cx_freeze vs pyinstaller? I can tell you that pyinstaller does a much better job of actually detecting and including dependencies. I recently tried both for freezing a multi-threaded, scipy based application and cx_freeze was a real hassle to get functional. Pyinstaller more or less just magically worked in my case whereas cx_freeze took hours of debugging.

Brian #5: PEX: A library and tool for generating .pex (Python EXecutable) files

Developed by twitter. Originally part of the twitter.commons package. pex is a tool to create PEX files, which are “files are self-contained executable Python virtual environments.”, from pex.readthedocs.io. Python can import from zip files. You can add instructions at the beginning of a zip file to make it look like a python script. pex allows you to do that. Watch WTF is PEX?, a 16 min video describing how it works. Brian Wickman

Michael #6: Using Cython to protect a Python codebase

A Python project that required the whole codebase to be protected They used Cython By following this guide, you should be able to cythonize a Python codebase with non-trivial package/module structure, thus making it difficult for evil hackers to reverse engineer it and steal your programming know-how. Although protecting Python sources from reverse engineering seems like a futile task at first, cythonizing all the code leads to a reasonable amount of security This was a Flask project! The current standard for Python archives is the wheel format (.whl), which aims to replace the .egg format. So, let's try to create a wheel with python setup.py bdist_wheel! Apparently, the archive contains not only compiled code, but also the sources. There is a way to fix this, however it is counter-intuitive. Our news Python for Windows developers: A survey → https://docs.google.com/forms/d/e/1FAIpQLSdygLS0G91t5E8LCGtZvdfzeqdePr2jFqoiR30HZjmGbaJjNQ/viewform-

#49 Your technical skills are obsolete: now what?

Oct 25, 2017 00:25:57


Sponsored by DigitalOcean. They just launched Spaces, get started today with a free 2 month trial of Spaces by going to do.co/python

Brian #1: Conference videos for DjangoCon 2017 and PyGotham 2017

PyGotham 2017 videos on pyvideo DjangoCon 2017 on YouTube One I’ve watched so far: DjangoCon US 2017 - Django vs Flask by David "DB" Baumgold slides Very good introduction to Flask while comparing some of the features of Django to Flask and what the current frequent practices are for doing things in Flask like: Data modeling with SQLAlchemy, MongoEngine, or Peewee User admin with Flask-Security, which wraps Flask-Login, Flask-Permissions, and other commonly used together packages. Blueprints in Flask solve a similar problem as apps in Django. Flask-Marshmallow for APIs

Michael #2: Python 3.6.3 released on Tue. All machines at FB are already running it (3 days)

Tweet: Did you hear that 3.6.3 was released on Tue? How about that all machines at FB are already running it? Over 36.3% of our Python apps are 3.6 via @llanga See Jason Fried’s presentation on culture: Rules for Radicals: Changing the Culture of Python at Facebook More Python 3 news Ubuntu 17.10: “Python 2 is no longer installed by default. Python 3 has been updated to 3.6.” PSA: Python 3.3 is end-of-life in 2 days. Are you prepared?

Brian #3: Your technical skills are obsolete: now what?

by Itamar Turner-Trauring We’re big proponents of keeping your skills current, of learning new techniques and technologies. But how does that fit in with life and work. This article is an opinion of how to work on new skills while at work, do it quickly, and look good to your manager. It starts with a good discussion of real business reasons why some projects use older technology. Basically, cost vs benefit of change. Steps to be part of the solution: Identify obsolete and problematic technologies. Identify potential replacements. Get management buy in to get resources (you) to do a pilot project exploring new technology. This process will help you be better at identifying problems, even if you don’t get approval to fix it. He ends with a comment that if you don’t get approval, all is not lost, you have skills to apply to a new job. I’d like to make sue you do a few more steps before giving up and looking for a new job. Before you consider a move to a new team or company, I think… You should give your manager the benefit of the doubt and use this to start a conversation. Make sure you understand their reasons for saying no. Make sure you are not proposing too much time taken away from your primary role in the company. State that you want to improve your skills by providing value for the team and the company. Is the “no” due to just bad timing? Is there a higher priority problem to work on? You’ve just shown that you are someone interested in keeping your skills sharp and helping the company by expanding your role. If you’re still stuck at this point, then consider a move but also, … Read this: Team Geek: A Software Developer's Guide to Working Well with Others - Brian Fitzpatrick Especially: - pg 117 : “Offensive vs Defensive work”. 50-70% of your time at work needs to be focused on creating new value for your company or your customers. No more than 30-50% on repaying technical debt. (Okken: Limit your process improvement / new technology exploration to no more than 10-20%, but try to never drop it below 5% of your time) - pg 113 : “It’s easier to ask for forgiveness than permission.” This is a fine line between doing the right thing and doing something you can get reprimanded for. Use good judgement. - Forgotten page number: A big part of your job is making your boss’s job easier and making your boss and your team look good.

Michael #4: Visualizing Garbage Collection Algorithms

By Ken Fox Follow up from the excellent deep dive article in GC from Brian Most developers take automatic garbage collection for granted. It’s very difficult to see how GCs actually work. GCs visualized (click on each image): Cleanup At The End: aka No GC (e.g. Apache web server creates a small pool of memory per request and throws the entire pool away when the request completes) Reference Counting Collector (e.g. Python’s first pass GC, Microsoft COM, C++ Smart Pointers. Memory fragmentation is interesting) The red flashes indicate reference counting activity. A very useful property of reference counting is that garbage is detected as soon as possible — you can sometimes see a flash of red immediately followed by the area turning black. Mark-Sweep Collector (e.g. is this Python’s secondary collector? Probably is my guess) Mark-sweep eliminates some of the problems of reference count. It can easily handle cyclic structures and it has lower overhead since it doesn’t need to maintain counts. Mark-Compact Collector (Oracle’s Hotspot JVM’s tenured object space uses mark-compact) Mark-compact disposes of memory, not by just marking it free, but by moving objects down into the free space The crazy idea of moving objects means that new objects can always just be created at the end of used memory. This is called a “bump” allocator and is as cheap as stack allocation, but without the limitations of stack size. Copying Collector, aka Generational GC The foundation of most high-performance garbage collection systems

Brian #5: pathlib — Filesystem Paths as Objects

from Doug Hellman’s PyMOTW-3 pathlib was introduced with Python 3.4 If you need to work with the file system in Python, you should be using pathlib. Doug’s article is a really good overview. Features Building paths with overloaded / operator Parsing paths with .parts, .parents, .suffix, .stem Concrete paths such as Path.home(), Path.cwd() Getting directory contents with .iterdir() Pattern matching with .glob() and .rglob() Reading and writing files with path objects. Working with directories and symbolic links File properties, permissions Deleting files and directories see also https://docs.python.org/3/library/pathlib.html The official docs are pretty good too

Michael #6: LUMINOTH: Open source Computer Vision toolkit

Deep Learning toolkit for Computer Vision Supports object detection and image classification, but are aiming for much more. It is built in Python, using TensorFlow and Sonnet (Google’s Deep Learning framework and DeepMind’s graph library) Easily train neural networks to detect and classify objects with custom data. Use state of the art models such as Faster R-CNN (Region-based Convolutional Neural Networks) Comes with GPGPU support Simple training Train your model by just typing lumi train. Do it locally or using Luminoth's built-in Google Cloud Platform support to train in the cloud. Once training is done, you can use our Tensorboard integration to visualize progress and intermediate results. Are also working on providing pre-trained checkpoints on popular datasets such as Pascal VOC2012

Bonus article:

The Cleaning Hand of Pytest - My experiences with different approaches to testing

by Wiktor Żurawik Two case studies of having to use unittest after using pytest Be sure to check out the “useful links” at the end of the article. Our news PyTennessee 2018 Movie: All work, all play (available on netflix, here’s the trailer)

#48 Garbage collection and memory management in Python

Oct 19, 2017 00:17:50


Sponsored by DigitalOcean. They just launched Spaces, get started today with a free 2 month trial of Spaces by going to do.co/python

Brian #1: The Python Graph Gallery

“cool graphs” x “head explodes with options”

Michael #2: pynesis

High level python library for using kinesis streams

What are Kinesis streams? AWS Kinesis streams

Enables you to build custom applications that process or analyze streaming data for specialized needs. Continuously capture and store terabytes of data per hour from hundreds of thousands of sources such as website clickstreams, financial transactions, social media feeds, IT logs, and location-tracking events.

High level kinesis client. Support python 2.7 and 3.6, and has helpers for using it within Django.

Some features: Supports python 2 & 3 Django helpers included Automatically detects shard count changes Checkpoints/sequences persistence can be customized Provided Checkpointer implementations for memory, django model and redis Provided Dummy kinesis implementation for development/testing

Brian #3: Things you need to know about garbage collection in Python

Michael #4: WSGI Is Not Enough Anymore, part 1 and part 2

Explores the factors that make WSGI a less attractive option for developing web applications with Python. Most major web frameworks use WSGI (Pyramid, Flask, Django, Bottle, etc.) This has been a major benefit / breakthrough The Web Server Gateway Interface (WSGI) is a specification which was first developed in 2003, and then revised in 2010, in order to create a standard for Python web frameworks to interact with web servers. The bad news is that WSGI comes with two major drawbacks: WSGI compatible servers are synchronous WSGI compatible servers only supports the HTTP protocol Problem 1: Concurrency By design, a WSGI server is synchronous. This means it blocks each request until a response arrives from the application. Scaling is done necessarily via threads (with GIL limitations), web gardens (multiple processes per server), and web farms (multiple servers) Problem 2: HTTP is the only protocol HTML5 introduced, among other things, web sockets, which create a bi-directional communication layer between servers and clients. But they are not supported, so polling (yuck) is the only option Python frameworks which rely on WSGI do not implement web socket communication and must rely on 3rd party solutions and extra components and resources. Part 2 discusses solutions via event driven programming Part 3 (pending) talks about libraries for solving the concurrent problem in Python

Brian #5: Queues in Python

Dan Bader I was in search of a LIFO queue and ran across this article by Dan. For LIFO: ### collections.deque as LIFO queue q = collections.deque() # insert elements q.appendleft(item) #iterate for item in q: print(item) ### queue.LifoQueue q = queue.LifoQueue() # insert elements q.put(item) #iterate while not q.empty(): item = q.get() print(item) ### list as LIFO queue q = [] # insert elements q.append(item) #iterate for item in q[::-1]: print(item)

Michael #6: Using Reflection: A Podcast About Humans Engineering

by Mark Weiss Check out Jesse Davis’s episode for a starter. Engineering journey, what they value about engineering and skills they have come to recognize in themselves. Dig into what makes teams successful, and how we help them succeed. Our news Michael: Free MongoDB course has had over 5,000 signups in the first few days. Check it out http://freemongodbcourse.com

#47 PyPy now works with way more C-extensions and parking your package safely

Oct 12, 2017 00:16:44


Sponsored by DigitalOcean. They just launched Spaces, get started today with a free 2 month trial of Spaces by going to do.co/python

Brian #1: PyPy v5.9 Released, Now Supports Pandas, NumPy

NumPy and Pandas work on PyPy2.7 v5.9 Cython 0.27.1 (released very recently) supports more projects with PyPy, both on PyPy2.7 and PyPy3.5 beta Optimized JSON parser for both memory and speed. CFFI updated Nice to see continued improvements and work on PyPy

Michael #2: WTF Python?

Python, being awesome by design high-level and interpreter-based programming language, provides us with many features for the programmer's comfort. But sometimes, the outcomes of a Python snippet may not seem obvious to a regular user at first sight. Here is a fun project attempting to collect such classic and tricky examples of unexpected behaviors in Python and discuss what exactly is happening under the hood! Examples: Skipping lines? ​​Modifying a dictionary while iterating over it Backslashes at the end of string is is not what it is! I’m thinking of doing some fun follow on projects with this. More on that later.

Brian #3: Python Exercises

“… focus on the language itself and the standard library.” Some non-obvious Python exercises to help hone your Python skills, and possibly use in coding exercises of a job interview or maybe pre-interview screen. Topics Basic syntax Text Processing OS Integration Functions Decorators & Generators Classes, Modules, Exceptions, Lists, Dictionaries, Multiprocessing & Testing! always including testing when ~~interviewing someone~~ practicing your coding.

Michael #4: Exploiting misuse of Python's "pickle"

If you program in Python, you’re probably familiar with the pickle serialization library, which provides for efficient binary serialization and loading of Python datatypes. Hopefully, you’re also familiar with the warning printed prominently near the start of pickle’s documentation:

Warning: The pickle module is not intended to be secure against erroneous or maliciously constructed data. Never unpickle data received from an untrusted or unauthenticated source.

this blog post will describe exactly how trivial it is to exploit such a service, using a simplified version of the code I recently encountered as an example. Executing Code: So, what can we do with a vulnerable service? Well, pickle is supposed to allow us to represent arbitrary objects. An obvious target is Python’s subprocess.Popen objects!

Brian #5: A Complete Beginner's Guide to Django

Lots of Django tutorials already, but this may appeal to folks with a more academic bent. Complete with wireframes, UML class hierarchies and use case diagrams. Series with 6 parts done, a 7th part planned, which will be the last part. Some fun comic like drawings, and lots of screenshots.

Michael #6: pypi-parker

Helper tooling for parking PyPI namespaces to combat typosquatting. pypi-parker lets you easily park package names on PyPI to protect users of your packages from typosquatting. Typosquatting is a problem: in general, but also on PyPI. There are efforts being taken by pypa to protect core library names, but this does not (and really cannot and probably should not attempt to) help individual package owners. For example, reqeusts rather than requests, or crytpography rather than cryptography. Why? Self-serve is a good thing. Let's not try and get rid of that. Work with it instead. What? pypi-parker provides a custom distutils command park that interprets a provided config file to generate empty Python package source distributables. These packages will always throw an ImportError when someone tries to install them. You can customize the ImportError message to help guide users to the correct package.

Our news


Just launched freemongodbcourse.com Come and sign up to learn MongoDB and some Python Python3 usage has doubled in the past year (thanks Donald Stufft)

#46 Spicy lecture notes and unicorn console spinners

Oct 5, 2017 00:16:51


Sponsored by DigitalOcean. They just launched Spaces, get started today with a free 2 month trial of Spaces by going to do.co/python

Brian #1: Scipy lecture notes

“One document to learn numerics, science, and data with Python” Topics Python language tutorial NumPy, Matplotlib, scipy Debugging, optimizing, image manipulation Statistics, scikit-image, scikit learn 3D plotting Nice table of contents layout that makes it easy to jump right to whatever you need to learn. Just in time learning for scientific Python.

Michael #2: Building a desktop notification tool for Linux using python

The term desktop notifications refer to a graphical control element that communicates certain events to the user without forcing them to react to this notification immediately. Example: we are going to build a notification tool which displays the current rate of bitcoins in INR. Based on notify2 package

Brian #3*:* pytest-benchmark

Easily wrap some time constraints around some code to make sure certain parts of your system don’t slow down. Good table or graph based preliminary times with statistics Can generate golden sets of numbers, then compare against those and fail based on changes in particular stats like min, mean, etc. Can have max and min times for benchmarks even without previous training. Lots of fun flags and utilities. good integration with pytest

Michael #4: Alice in Python projectland

via Vicki Boykis Python project structure and packaging standardization is still not a solved problem In the JVM, as long as you have your path structured correctly, build tools will understand it and create a package for you into an executable JAR. But, when I started looking for the same standardization in Python, it wasn’t as straightforward. Some questions I had as I worked: Should I be using virtualenvs? Pipenvs? Setuptools? Should I have a setup.cfg? What are wheels, or eggs, for that matter? Does each folder need an __init__.py? What does that file even do? How do I reference modules along the same PYTHONPATH? Hat tip to pipreqs Conclusion: Python project structure and packaging can be intimidating, but, if you take it step by step, it doesn’t have to be.

Brian #5: How to teach technical concepts with cartoons

Just draw more pictures. You don’t have to be a good artist for drawings to help with retention when you are trying to teach technical concepts.

Michael #6: Halo: Beautiful terminal spinners in Python

We’ve talk about progressbars: tqdm: https://github.com/tqdm/tqdm doesn’t have to be. Cool methods like spinner.start([text]) spinner.succeed([text]) spinner.fail([text]) Windows File Progress Dialog Author: https://xkcd.com/612/ Extras releases: stay current. go upgrade Python 3.6.3 released pytest 3.2.3 released New Test & Code episodes 31: I'm so sick of the testing pyramid 32: David Hussman - Agile vs Agility, Dude's Law, and more

#45 A really small web API and OS-level machine learning

Sep 29, 2017 00:19:33


This episode is brought to you by Rollbar: pythonbytes.fm/rollbar

Brian #1: pico

"a very small web application framework for Python" Recommended by Ivan Pejić lightning talk from EuroPython 2017 This would be a good web framework for building internal services and tools that non-web developers need to interact with and modify. Very simple. Not REST, but not confusing either.

Michael #2: High Sierra ships, first major OS with machine learning built in?

September 26th macOS High Sierra was released (yay) Mostly a foundational release with barely visible changes but awesome things like APFS replacing HFS+, etc. Comes with CoreML Apple’s intent with the new CoreML framework is to package up prebuilt ML models and execution engines and make them possible for third-party apps to use. Developers can take a trained machine learning algorithm, package it up as an MLModel, and integrate it into their apps. Apple offers a few default machine learning models that developers can download and use too Rather than sharing your data with a central server, grouping it together with a lot of other people's data, and improving machine learning models that way, Apple stresses that everything CoreML does is happening on the device. On Macs that support Metal—generally, Macs from 2012 and later—CoreML uses a mix of CPU processing and GPGPU processing, depending on the task. Add on the fact that High Sierra has external GPU support now and you have a sweet combo.

Brian #3: A guide to logging in Python

Simply put, the best logging introduction I've read so far.

Michael #4: Let me introduce: slots

So what are slots? __slots__ are a different way to define the attributes storage for classes in Python. for normal Python classes, a dict is used to store the instance's attributes. With __slots__ we don't have an attribute called __dict__ inside our instance. But we have a new attribute called __slots__. But why would you need to use slots when you have a dict? Well the answer is that __slots__ are a lot lighter and slightly faster. Outcome: ~57% less memory usage thanks to just one line of code. __slots__ are also slightly faster. Covered in depth in my Write Pythonic Code Like a Seasoned Developer course.

Brian #5: pipenv revisited

Covered in episode 11. However, there are some notable changes since then. Reminder: pepenv handles virtualenv and pip interaction for you pipenv install creates a virtualenv (if one doesn't exist) and installs stuff into a virtualenv. pipenv shell uses the virtualenv exit allows you to get out of the virtualenv pipenv lock -r will generate a requirements.txt file for you, so you can use it even if you need a requirements.txt file. Notable changes: New 4 minute screencast with Kenneth demonstrating how to use it. Watching him use it makes it very simple to understand. Specify multiple package indexes, and even specify a particular index for particular packages. So you can combine both pypi with a company index and a group index and maybe one for your project. pipenv check will tell you about any known security vulnerabilities in your installed packages 9 months old with 192 releases, so keep an eye on it for new features all the time.

Michael #6: Stack Overflow gives an even closer look at developer salaries

Tabs and spaces aren't the only things that influence developer pay… Some of the broad trends are no big surprise; for example, the chosen cities tend to pay more than their respective nations do, for example. DevOps specialists and data scientists both earn well. Other aspects of the data are a little more surprising. Graphics programmers, for example, aren't particularly well paid, in spite of having a relatively specialized, complex niche. And while earnings in four of the countries are surprisingly similar, those in America are substantially higher, regardless of experience; in fact, the median salary of a developer in the US is comparable to that of someone with 20 years of experience in Canada or Germany and markedly higher than 20-year veterans in France and the UK. Even after taking into account the US' higher healthcare costs, America is the place to be if you're a programmer. Comments I do have to wonder how much Silicon Valley skews that salary chart, as the Web 2.0 companies pay HUGE comparatively [ref] I asked Stack Overflow's data scientist that question, and she said not much; even without its outlier cities, the US pays much more than the rest of the world. [ref] Healthcare cost are only part of it. I got paid about $600/month 9 months a year by my government to study in university. [ref] I feel like a lot of IT people lack soft skills, and it caps their salary at a lower end. [ref]

Our news:

Hardcopies of Python Testing with pytest now shipping on Amazon, as well as Pragmatic. When you get your copy, let me know. Send a pic to @brianokken

#44 pip install malicious-code

Sep 20, 2017 00:26:35


This episode is brought to you by Datadog: pythonbytes.fm/datadog

Michael #1: Ten Malicious Libraries Found on PyPI

Code packages available in PyPI contained modified installation scripts. Vulnerabilities were introduced into the setup.py execution of packages for approximately 20 packages on PyPI Package names that closely resembled those used for packages found in the standard Python library (e.g. urlib vs urllib) The packages contained the exact same code as the upstream libraries except for an installation script. Officials with the Slovak authority said they recently notified PyPI administrators of the activity, and all identified packages were taken down immediately. Removal of the infected libraries, however, does nothing to purge them from servers that installed them. From PSF: Unlike some language package management systems, PyPI does not have any full time staff devoted to it. It is a volunteer run project with only two active administrators. As such, it doesn't currently have resources for some of the proposed solutions such as actively monitoring or approving every new project published to PyPI. Historically and by necessity we've relied on a reactive strategy of taking down potentially malicious projects as we've become aware of them. Comments pip gets more paranoid in the install process Downloads were not super bad Stestagg is sitting on lots of misspellings -Undergrad thesis compromised Ruby and NodeJS too related: original warning: http://www.nbu.gov.sk/skcsirt-sa-20170909-pypi/ stdlib names no longer allowed: https://github.com/pypa/warehouse/pull/2409

Brian #2: PyPI migration to Warehouse is in progress

Thanks to Jonas Neubert for researching this topic and writing a blog post titled Publishing your First PyPI Package by/for the Absolute Beginner The steps to publish to PyPI have changed with the move to warehouse and pypi.org. pypi.org is no longer in read-only mode, it is where you publish packages The old APIs at pypi.python.org/pypi are disabled, if you have a .pypirc file you'll have to update the URLs You no longer need to register package names before first uploading, the project gets created on the fly during the first upload of the package. The best way to update anything in a package is to change your local package and upload it again, see https://github.com/pypa/warehouse/issues/2170. This includes even just changes to the description. Manual file upload is gone. As of right now it looks like you still need to register through pypi.python.org, then do the rest of the interactions with pypi.org. See https://github.com/pypa/warehouse/issues/2065 Markdown support for package descriptions, like README.md seems to be coming: https://packaging.python.org/specifications/#description-content-type Jonas’ blog post is from 13 Sep 2017, so it might be the most up to date tutorial on all the steps to get a package onto PyPI.

Brian #3: Live coding in a presentation

Last week’s discussion of David Beazley’s Fun of Reinvention talk got me thinking about doing live coding during a presentation since he did it so well. Several links regarding how to do various levels of live coding: Advice for live coding: https://code.tutsplus.com/articles/the-holy-grail-of-conference-talks-live-coding--net-30217 Not quite live coding: https://vanslaars.io/post/not-quite-live-coding/ Avoiding live coding: https://codeplanet.io/techniques-avoid-live-coding-part/ Live coding: practice, have a backup plan, don’t forget to talk, plan content not quite: use git tags avoiding it: My favorite effect is fade-in slideshows where part of the code is shown at a time so you can talk about it and people know which bit to look at

Michael #4: Notable REST / Web Frameworks

Falcon: https://falconframework.org/

Unburdening APIs for over 4.70 x 10-2 centuries. (4.7 years) Falcon is a bare-metal Python web API framework for building very fast app backends and microservices. Complementary: Falcon complements more general Python web frameworks by providing bare-metal performance and flexibility wherever you need it. Compatible: Thanks to WSGI, Falcon runs on a large variety of web servers and platforms. Falcon works great with CPython 2.6, 2.7, and 3.3+. Try PyPy for an extra speed boost.

Hug: http://hug.rest

Drastically simplify API development over multiple interfaces. With hug, design and develop your API once, then expose it however your clients need to consume it. Be it locally, over HTTP, or through the command line. Built-in documentation

Brian #5: tox

“The name of the tox automation project derives from "testing out of the box". It aims to "automate and standardize testing in Python". Conceptually it is one level above pytest and serves as a command line frontend for running tests and automate all kinds of tasks around the project. It also acts as a frontend for Continuous Integration Systems to unify what you do locally and what happens in e.g. Jenkins or Travis CI.” - Oliver Bestwalter a small tox.ini file: [tox] envlist = py27,py35, py36 [testenv] deps=pytest commands=pytest You place this in your package source directory and then run tox, which will: Use setup.py to create a sdist create a virtual environment for each environment in envlist Install dependencies in the environments Install your package into the environment Run the tests Do this for multiple environments, so multiple Python versions (as an example) Much more powerful than that, but that’s how many people use it. Further Reading: http://tox.readthedocs.io/en/latest/index.html http://tox.readthedocs.io/en/latest/example/basic.html https://blog.ionelmc.ro/2015/04/14/tox-tricks-and-patterns/

Michael #6: flake8-tidy-imports deprecated imports

You can declare {python2to3} as a banned-module import, and it will check against a long list of import moves and removals between python 2 and python 3, suggesting relevant replacements if available. I meticulously compiled this list by reading release notes from Python 3.0-3.6 as well as testing in a large legacy python codebase, but I presumably missed a few. Example: flake8 file.py file.py:1:1: I201 Banned import 'mock' used - use unittest.mock instead.

Michael #7 (bonus!): Help Me Offer Coaching to First-Time PyGotham Speakers

Via A. Jesse Jiru Davis I want to raise $1200 for public-speaking coaching for first-time speakers at PyGotham, the New York City Python conference. Will you chip in? Jesse is a PyGotham conference organizer, but I’m launching this fundraiser independently of PyGotham. As of September 19, I have raised my goal. Thanks to everyone who donated! Our news


Finished writing my free MongoDB course (subscribe to get notified of release at https://training.talkpython.fm/getnotified ) python-switch kind of went off the hook (see this and that)


Book is shipping: Python Testing with pytest

#43 Python string theory, v2

Sep 14, 2017 00:18:48


Python Bytes 43

This episode is brought to you by Rollbar: pythonbytes.fm/rollbar

Brian #1: future-fstrings

A backport of fstrings to python < 3.6 Include an encoding string the top of your file (this replaces the utf-8 line if you already have it) And then write python3.6 fstring code as usual! # -*- coding: future_fstrings -*- thing = 'world' print(f'hello {thing}') In action: $ python2.7 main.py hello world I’m still undecided if I like this sort of monkeying with the language through the encoding mechanism back door.

Michael #2: The Fun of Reinvention

Keynote from PyCon Israel David Beazley rocks it again Let’s take Python 3.6 features and see how far we can push them Builds an aspect-oriented constraint system using just 3.6 features

Brian #3: Sound Pattern Recognition with Python

Usingscipy.io.wavfile.read to read a .wav file. Looking for peaks (knocks). Using minimum values to classify peaks, and minimum distance between peaks. This is an interesting start into audio measurements using Python. Would be fun to extend to some basic scope measurements, like sampling with a resolution bandwidth, trigger thresholds, pre-trigger time guards, etc.

Michael #4: PEP 550: Execution Context

From the guys at magic.io Adds a new generic mechanism of ensuring consistent access to non-local state in the context of out-of-order execution, such as in Python generators and coroutines. Thread-local storage, such as threading.local(), is inadequate for programs that execute concurrently in the same OS thread. This PEP proposes a solution to this problem. A few examples of where Thread-local storage (TLS) is commonly relied upon: Context managers like decimal contexts,numpy.errstate, and warnings.catch_warnings. Request-related data, such as security tokens and request data in web applications, language context forgettext etc. Profiling, tracing, and logging in large code bases. The motivation from uvloop is obviously at work here.

Brian #5: Intro to Threads and Processes in Python

Beginner’s guide to parallel programming Threads and processes are both useful for different kinds of problems. This is a good quick explanation of when and where to use either. With pictures! Threads Like mini processes that live inside one process. Share mem space with other threads. Cannot run simultaneously in Python (there are some workarounds), due to GIL. Good for tasks waiting on IO. Processes Controlled by OS Can run simultaneously Good for CPU intensive work because you can use multiple cores.

Michael #6: Alternative filesystems for Python

PyFilesystem: Filesystem Abstraction for Python. Work with files and directories in archives, memory, the cloud etc. as easily as your local drive. Uses Write code now, decide later where the data will be stored unit test without writing real files upload files to the cloud without learning a new API sandbox your file writing code File system backends AppFS Filesystems for application data. S3FS Amazon S3 Filesystem. FTPFS File Transfer Protocol. MemoryFS An in-memory filesystem. MountFS A virtual filesystem that can mount other filesystems. MultiFS A virtual filesystem that combines other filesystems. OSFS OS Filesystem (hard-drive). TarFS Read and write compressed Tar archives. TempFS Contains temporary data. ZipFS Read and write Zip files. and more Our news

Michael: switch statement extension to Python: github.com/mikeckennedy/python-switch

#42 Behold: The Python 2 death clock

Sep 8, 2017 00:23:52


Sponsored by DataDog! pythonbytes.fm/datadog

Brian #1: What Kenneth Did Last Week (well, recently)

Kenneth Reitz

Homebrew Python Tap

Python 2.5 through 3.6 available through homebrew https://github.com/kennethreitz/homebrew-pythons $ brew tap kennethreitz/pythons $ brew install python-2.5 https://github.com/requests/requests-threads/ “ Twisted Deferred Thread backend for Requests.” Can be used with async/await or with twisted. https://github.com/kennethreitz/background “Runs things in the background.” https://github.com/kennethreitz/setup.py “setup.py (for humans)” “This repo exists to provide an example setup.py file, that can be used to bootstrap your next Python project. It includes some advanced patterns and best practices for setup.py, as well as some commented–out nice–to–haves.”

Michael #2: Python 2 Death Clock

Python 2.7 will not be maintained past 2020. No official date has been given, so this clock counts down until April 12th, 2020, which will be roughly the time of the 2020 PyCon. I am hereby suggesting we make PyCon 2020 the official end-of-life date, and we throw a massive party to celebrate all that Python 2 has done for us. Python 2, thank you for your years of faithful service. Python 3, your time is now.

Brian #3: Small Functions considered Harmful

Cindy Sridharan "General programming advice doled out invariably seems to extoll the elegance and efficacy of small functions." This is sometimes pushed to the extreme of having one line functions that are only called from one place. Understand that doing this increases your code size by 4 lines every time you do it. 1 line for the function call isn't removed because you moved the guts into a function. 2 lines for function definition and guts 2 lines to properly space your new function around other functions. Supposed Benefit: Do one thing; a function should only ever do one thing and do it well. Problems: "Instead of a reasonably airtight abstraction that can be understood (and tested) as a single unit, we now end up with even smaller units that’ve been carved out to delineate each and every component of “the one thing” until it’s fully modular and entirely DRY." "...pragmatism and reason are sacrificed at the altar of a dogmatic adherence to DRY, ..." premature abstractions. breaking up the code into smaller functions before you really understand the problem space can make it harder to refactor later. micro-functions tend to have longer names because you need more names. Longer names aren't always a good thing when you have many long names on a page. loss of locality: One bit of functionality that used to be in one function is now spread across many functions and possibly moved far away from use. class pollution: class interfaces grow with smaller functions and hide the real intended interface. harder to read, especially for newcomers. There is still a place for small functions. But use it in moderation. Communicating with future developers clearly is more important than following dogmatic rules about function size.

Michael #4: Why Python 3

All the cool Python 3 features that'll make you switch today! Presented as a random code sample surprise Examples: Annotations: def my_add(a: int, b: int) -> int Keyword only arguments: def f(a, b, *args, option=True) Yield from: yield from range(5) Enums: class Color(Enum)

Brian #5: EANABs

Equally Attractive Non-Alcoholic Beverage There is drinking that happens often when you get a bunch of adults together. Often with work or tech gatherings. That’s fine. But make sure you emphasize that drinking is not required. @treyhunner brought it up recently and suggested that all conferences and tech events should have this. "I sometimes feel excluded when events include nice alcohol but only cheap soda" Stanford site has a bunch of great recipes. “EANABS are required at all Stanford parties, …” If you have specialty local beers, try to find specialty local sodas. If you have nice spiked punch, have a NA version also. If you have cocktails, advertise your ability to serve mocktails.

Michael #6: The Incredible Growth of Python

via StackOverflow Recently explored how wealthy countries (those defined as high-income by the World Bank) tend to visit a different set of technologies than the rest of the world. Largest differences we saw was in the programming language Python. High-income countries, the growth of Python is even larger than it might appear from tools like Stack Overflow Trends, or in other rankings. [StackOverflow] makes the case that Python has a solid claim to being the fastest-growing major programming language. June 2017 was the first month that Python was the most visited tag on Stack Overflow within high-income nations. (Grown has grown by 2.5-fold since 2012) Python compared to smaller, growing technologies graph is incredible. Also: Python overtakes R, becomes the leader in Data Science, Machine Learning platforms

#41 Python Concurrency From the Ground Up and Caring for our Community

Aug 31, 2017 00:23:21


Brought to you by Rollbar! Create an account and get special credits at pythonbytes.fm/rollbar

Guest co-host: Miguel Grinberg

Miguel #1: lolviz

Generates graphical representations of Python data structures using graphviz. Great as a teaching tool! Currently supports dicts, lists, lists of lists, linked lists and binary trees. Jupyter knows how to render these graphics. In regular Python it can also be used, but it is a bit cumbersome. I hope the project grows to support more complex data structures in the future!

Michael #2: Odo for data transforms

Odo migrates between many formats. odo(df, list) # create new list from Pandas DataFrame odo(df, []) # append onto existing list odo(df, 'myfile.json') # Dump dataframe to line-delimited JSON odo('myfiles.*.csv', Iterator) # Stream through many CSV files odo(df, 'postgresql://hostname::tablename') # Migrate dataframe to Postgres odo('myfile.*.csv', 'postgresql://hostname::tablename') # Load CSVs to Postgres odo('postgresql://hostname::tablename', 'myfile.json') # Dump Postgres to JSON odo('mongodb://hostname/db::collection', pd.DataFrame) # Dump Mongo to DataFrame

Miguel #3: Python Concurrency From the Ground Up

This is probably my favorite tech talk of all times. There are no slides, the entire talk is a live coding session. David Beazley covers concurrency with threads and processes, and then goes on to build an asynchronous framework along the lines of asyncio just using generators, all in front of your eyes. If you spend 45 minutes watching this talk you’ll end up with a much better understanding of Python concurrency.

Michael #4: FAT Python : the next chapter in Python optimization

via Anthony Shaw The FAT Python project was started by Victor Stinner in October 2015 to try to solve issues of previous attempts of “static optimizers” for Python. The PEPs PEP 511 is a proposal to add a process to optimize an AST instance. The AST instance is a object-oriented representation of your code. A bespoke optimizer could look at a set of domain specific changes, e.g. NumPy or Pandas “anti-patterns” and optimize them in the syntax tree. In replacement of a static linter that simply recommends changes, the optimizer could make those changes for you. PEP 509: Python is hard to optimize because almost everything is mutable: builtin functions, function code, global variables, local variables, … can be modified at runtime. The speedup of optimizations depends on the speed of guard checks. PEP 509 proposes to add a private version to dictionaries to implement fast guards on namespaces. PEP 510 proposes to add a public API to the Python C API to add specialized codes with guards to a function. When the function is called, a specialized code is used if nothing changed, otherwise use the original bytecode. Can download and compile this variation of CPython Basic function with a return is 24% improvement over 3.6 (and 46% faster than 2.7) Combining these 3 PEPs, we could see both implementation of guards as well as well as a range of optimizers out on PyPi.

Miguel #5: sshuttle

You probably know that there are security risks when going online at public wi-fi hotspots at coffee shops, hotels or airports. Most people don’t realize this, but even if you access sites over https://, DNS queries made to connect to those sites are not encrypted, so they give away which sites you visit. sshuttle is fantastic tool (written in Python, BTW) that creates a secure tunnel between your machine and another machine (which can be in a secure location such as your home or office) and forwards all network traffic through that other system with strong encryption. A poor man’s VPN! All you need to use sshuttle is SSH access to the secure system. No need to install anything on the remote system besides SSH! Simply run sshuttle --dns --r username@your-server and from then on all traffic will be tunneled to your secure server with strong encryption, including DNS queries!

Michael #6: Node.js forks again – this time it's a war of words over codes of conducts

After years of battling a string of systematic failures of governance and leadership, the Node.js community reached a breaking point. Monday saw a stream of resignations, one after the other throughout the day from Node.js' technical steering committee (TSC), a group that manages the day-to-day governance for the Node.js project. A third of the committee had quit their positions by the end of the day, including its first woman member. One person has left the project entirely. The resignations followed a single event -- a vote that failed to remove a former director, a longstanding member of the community, from the leadership group. Many of the complaints, since removed from the committee's pages, document a litany of violations of the community's code of conduct. The failure to have him removed from the position was seen as the embodiment of years of efforts to reform a pattern of harmful behaviors that was tearing the community apart. The inability for members of the TSC to "look at the entire picture" of a person's behavior rather than each broken rule is where trust in the system broke down, Kapke said. Moments after the failed leadership vote, Kat Marchán pushed the button that created Ayo.js, a new open-source project forked from Node.js.

Our news


Blog The New and Improved Flask Mega-Tutorial


RESTful and HTTP APIs in Pyramid

#40 Packet Manipulation with Scapy

Aug 24, 2017 00:22:59


We have guest hosts filling in for Michael while he is on vacation. This week we have Eric Chou, author of the book “Mastering Python Networking” and a self-proclaimed Network Automation Nerd.

Eric #1: DevOps Automation Tool: Ansible

DevOps Automation framework written in Python, code hosted on GitHub. Top 10 OpenSource projects in 2014 by OpenSource.com, along with Docker, Kubernetes, Apache Hadoop, OpenStack, and OpenDaylight, etc. Excellent documentation for all modules. Agentless, ‘networking vendor’ friendly, execute code locally that interacts with the device via SSH and API. Lots of Network modules, including Cisco, Juniper, Arista, etc. In fact, you can find Cisco and Juniper testimonial on the Ansible site. Easy to learn and extend if you already know a little bit about Python, YAML, and Jinja2.

Brian #2: Python Practices for Efficient Code: Performance, Memory, and Usability

(I’m too opinionated to leave out my thoughts when covering this article, even though it’s very well written and I mean no disrespect to Satwik Kansal)

Try not to blow off memory use generators to calculate large sets of results for big number crunching, use numpy Use format instead of + for large strings. (or f-strings - Brian) Use slots for classes (psshh, use attrs - Brian) Python 2 or 3 Write code compatible with both. (disagree, use 3 unless you can’t for a very good reason, then write code that’s easy to convert to 3 later. - Brian) Write Beautiful code because “The first impression is the last impression." follow style guides use static analysis tools. Recommended using something called coala that’s installed as “coala-bears. (Brian: Maintenance cost is a real thing. Make your code look good because it’s cheaper in the long run. Use pycodestyle, pydocstyle, flake8, and if using sublime, use Flake8Lint) Speed up your performance Multiprocess, not Multi-thread Analyzing your code Use cProfile, memory_profiler, objgraph, resource Testing and CI nose or pytest or doctest (Brian: BTW, I really appreciate the links to pythontesting.net for tutorials on these.) (Brian: No. Use pytest) measure coverage and and try for 100% (Brian: No. use coverage to be alerted of sudden changes, and of code that possibly needs more testing and/or deleted)

Eric #3: Packet Manipulation Program: Scapy

Free Python-based interactive packet manipulation program and library, GitHub. Craft the packet from the ground up, you can use it to decode packets or craft packets. You are in control instead of limited to what the creator of the tool can imagine, i.e. hping3, curl. Can be used together with the Python interpreter. Particularly useful for network security Crafting common attacks: malformed packets (such as IP version 3), Ping of Death (large paylaod), Land Attack (redirect the client response back to the client itself) for denial-of-service. Penetration Testing (TCP port scan) and Fuzzing by providing invalid, unexpected, or random data.

Brian #4: Using Headless Chrome with Selenium

Miguel Grinberg quick demo of using headless chrome with selenium and unittest. (Brian: Eventually I’ll get Miguel to use pytest more.) Replace the normal Firefox with Chrome in the webdriver of Selenium, and passing a ‘headless’ argument to make it so the window doesn’t keep popping up and down when testing.

Eric #5: Graph Visualization with Graphviz

Open Source graph visualization software. Perfect for graphing the large datacenter topology automatically or any other network diagrams. Extensive documentation and gallery of examples. Did I mention this is ‘automatible’? Thus avoid drifts between reality and actual network. Python package graphviz (lower case g) for Graphviz integration.

Brian #6: PyCascades CFP still open until the 28th

Python conference in Vancouver, BC. Talks Jan 22, 23, Sprints Jan 24th Speakers get free admission. Talks are all 25 min slots. No Q&A after talks in front of full audience, but speakers will hang out up front for a few minutes for individual questions I’m going to submit at least one proposal. But I’m kinda swamped this week, so the proposal will unfortunately be rushed.

Extra Eric:

Mastering Python Networking book Network Labs: Cisco Virtual Internet Routing Lab (VIRL), Cisco DevNet, GNS3 (Graphic Network Simulator).

Extra Brian:

Copy editing and final testing with most recent Python and pytest done for Python Testing with pytest

#39 The new PyPI

Aug 17, 2017 00:43:06


Mahmoud #1: The New PyPI

Donald Stufft and his PyPA team have been hard at work replacing the old pypi.python.org The new site is now handling almost all the old functionality (excepting deprecated features, of course): https://pypi.org/ The new site has handled downloads (presently exceeding 1PB monthly bandwidth) for a while now, and uploads as of recently. A nice full-fledged, open-source Python application, eagerly awaiting your review and contribution: https://github.com/pypa/warehouse/ More updates at: https://mail.python.org/pipermail/distutils-sig/

Brian #2: CircuitPython Snakes its Way onto Adafruit Hardware

Adafruit announced CircuitPython in January “CircuitPython is based on the open-source MicroPython which brings the popular Python language to microcontrollers. The goal of CircuitPython is to make hardware as simple and easy as possible.” Already runs on Metro M0 Express, Feather M0 Express, and they are working on support for Circuit Playground Express, and now Gemma M0 New product is Gemma M0: Announced at the end of July. It’s about the size of a quarter and is considered a wearable computer. “When you plug it in, it will show up as a very small disk drive with main.py on it. Edit main.py with your favorite text editor to build your project using Python, the most popular programming language. No installs, IDE or compiler needed, so you can use it on any computer, even ChromeBooks or computers you can’t install software on. When you’re done, unplug the Gemma M0 and your code will go with you." They’re under $10. I gotta get one of these and play with it. (Anyone from Adafruit listening, want to send me one?) Here's the intro video for it: https://www.youtube.com/watch?v=nRE_cryQJ5c&feature=youtu.be Creating and sharing a CircuitPython Library is a good introduction to the Python open source community, including: Creating a library (package or module) Sharing on GitHub Sharing docs on ReadTheDocs Testing with Travis CI Releasing on GitHub

Mahmoud #3: Dataclasses

Python has had classes for a long time, but maybe it’s time for some updated syntax and semantics, something higher level perhaps? dataclasses is an interesting case of Python’s core dev doing their own take on community innovation (Hynek’s attrs: https://attrs.org) Code, issues, and draft PEP at https://github.com/ericvsmith/dataclasses

Brian #4: Pandas in a Nutshell

Jupyter Notebook style post. Tutorial by example with just a bit of extra text for explanation. Data structures: Series – it’s a one dimensional array with indexes, it stores a single column or row of data in a Dataframe Dataframe – it’s a tabular spreadsheet like structure representing rows each of which contains one or multiple columns Series: Custom indices, adding two series, naming series, … Dataframes: using .head() and .tail(), info(), adding columns, adding a column as a calculation of another column, deleting a column, creating a dataframe from a dictionary, reindexing, summing columns and rows, .describe() for simple statistics, corr() for correlations, dealing with missing values, dropping rows, selecting, sorting, multi-indexing, grouping,

Mahmoud #5: Static Typing

PyBay 2017, which ended a day before recording, featured a neat panel on static typing in Python. One member each from Google, Quora, PyCharm, Facebook, and University of California Three different static analysis tools (four, if you count PyLint) They’re all collaborating already, and open to much more, as we can see on this collection of the stdlib’s type defs: https://github.com/python/typeshed A fair degree of consensus around static types being most useful for testable documentation, like doctests, but with more systemic implications Not intended to be an algebraic type system (like Haskell, etc.)

Brian #6: Full Stack Python Explains ORMs

What are Object Relational Mappers? “An object-relational mapper (ORM) is a code library that automates the transfer of data stored in relational databases tables into objects that are more commonly used in application code.” Why are they useful? “ORMs provide a high-level abstraction upon a relational database that allows a developer to write Python code instead of SQL to create, read, update and delete data and schemas in their database.” Do you need to use them? Downsides to ORMs: Impedance mismatch : “the way a developer uses objects is different from how data is stored and joined in relational tables” Potential for reduced performance: code in the middle isn’t free Shifting complexity from the database into the application code : people usually don’t use database stored procedures when working with ORMs. A handful of popular ones including Django ORM, SQLAlchemy, Peewee, Pony, and SQLObject. Mostly listed as pointing out that they are active projects, brief description, and links for more info. Matt also has a SQLAlchemy page and a peewee page for more info on them.

Extra Mahmoud:

hyperlink riot.im + (server code in Python)

Extra Brian:

Python Testing with pytest has a Discussion Forum. It’s something that I think all Pragmatic books have. Just this morning I answered a question about the difference between monkeypatch and mock and when you would use one over the other.

#38 Hacking Classic Nintendo Games with Python

Aug 9, 2017 00:24:57


Matt #1: Hacking Classic Nintendo Games with Python

Gist: used the FCEUX (http://www.fceux.com/web/home.html) Nintendo emulator’s debugger to hex edit memory and change what’s happening during play Hex changing is how the old school Game Genie worked Given by my Twilio colleague Sam Agnew at PyCon 2017, and all the talks are up on YouTube Sam was inspired by Guto Maia’s PyNES: https://gutomaia.net/pyNES/ Sam uses the Lua programming language to automate changing the Mario and Zelda’s hex values. He then creates a Flask app where PyCon attendees could send a text message containing a hex address and 2 digit hex value to a phone number. the input would then be read into the game as he was playing What I particularly enjoyed about this talk is that it takes a bunch of topics that sound really complicated, like hex editing memory values, and makes it more accessible to less experienced developers because they can see the results Follow along with this blog post: https://www.twilio.com/blog/2015/08/romram-hacking-building-an-sms-powered-game-genie-with-lua-and-python.html

Brian #2: The Pac-Man Rule at Conferences

by Eric Holscher “When standing as a group of people, always leave room for 1 person to join your group.” “Leaving room for new people when standing in a group is a physical way to show an inclusive and welcoming environment. “

Matt #3: Bokeh

Python data visualization library where the visualization output is designed for presentation in web browsers Just released v0.12.6 in June, which has a slew of improvements. awesome development team and constantly improving v0.12.6 is last planned release before 1.0 Wide range of visualizations you can create with Bokeh, including classic ones just bar charts box plots, and also interactive visuals Basically if you thought d3.js visualizations were awesome but didnt want to spend that much time hand crafting some complicated JavaScript, Bokeh will be your jam Flask-based tutorial: https://www.fullstackpython.com/blog/responsive-bar-charts-bokeh-flask-python-3.html

Brian #4: Mosh (mobile shell)

Persuasive video: https://www.youtube.com/watch?v=XsIxNYl0oyU from 2012 From the main page: Remote terminal application that allows roaming, supports intermittent connectivity, and provides intelligent local echo and line editing of user keystrokes. Mosh is a replacement for SSH. It's more robust and responsive, especially over Wi-Fi, cellular, and long-distance links. Mosh is free software, available for GNU/Linux, BSD, macOS, Solaris, Android, Chrome, and iOS. This has been around since 2012. I just heard of it. Are people using it?

Matt #5: Pelican static site generator

Static site generators take in a markup format such as reStructuredText or Markdown, along with a template engine such as Jinja and output HTML (or XML, JSON, etc) files that can be hosted anywhere It’s kind of a throw back to the early days of the web when everything was snappy Major new version 3.7.0 released at the end of 2016 with a minor v3.7.1 bump released early this year Lots of improvements to Python 3 compatibility. I use Pelican with Python 3.6.2. exclusively now. Significant customization by changing the configuration files. Lots of folks think static site generators are just for blogs, which is what most of the original static generators were built to create, but you really can create any type of site, including single page apps (when you combine a static site generator with a front end JavaScript framework). Just wrote a getting started tutorial: How to Create Your First Static Site with Pelican and Jinja2

Brian #6: pytest-watch

pytest 3.2.0 was released recently. Great for pytest users. Bummer for me that just recently tested all the code examples in the Python Testing with pytest book against pytest 3.1.3. So I wrote a bunch of tests to check every invocation of pytest in the book. I’m running it against both pytest 3.1.3 and pytest 3.2.0 I’m automating this by running both versions every time I save a new test with pytest-watch $ pip install pytest-watch $ cd <test directory> $ ptw . Run ptw . in two windows, each with a virtualenv with different pytest versions, and I can test both constantly as I save tests. Will later convert this to tox, but for now, this is a huge timesaver.

(bonus) Matt #7: Twilio Voices

New program where you get paid $500 for each published technical blog post you write for the Twilio blog. Every post has the code and walks the reader through how to recreate something you built. Examples: Wedding at Scale, How I Hack My University Registration System Tell stories with code We put each post through a rigorous outline, voice and tech review process Doesn’t have to use Twilio, so you can write a post on pytest-watch, Mosh, Pelican, Bokeh, or any other library you’ve been meaning to work with and get paid when the post is published This is what I’ve been working on at Twilio for the past couple of months so we’ll work directly together on the posts

#37 Rule over the shells with Sultan

Aug 2, 2017 00:18:15


Brian #1: New URL for Python Developer’s Guide

How to contribute to CPython

Some really useful links that I hadn’t noticed before. Also great ideas to include in a contributing guide for any large open source project:

Core developers and contributors alike will find the following guides useful: How to Contribute to Open Source (from https://opensource.guide) Building Welcoming Communities (from https://opensource.guide) Guide for contributing to Python: Getting Started Where to Get Help Lifecycle of a Pull Request Running & Writing Tests Beginner tasks to become familiar with the development process Helping with Documentation Increase Test Coverage Advanced tasks for once you are comfortable Silence Warnings From the Test Suite Fixing issues found by the buildbots Fixing “easy” Issues (and Beyond) Using the Issue Tracker and Helping Triage Issues Triaging an Issue Experts Index Following Python’s Development How to Become a Core Developer Committing and Pushing Changes Development Cycle Continuous Integration Git Bootcamp and Cheat Sheet

Michael #2: Sultan: Command and Rule Over Your Shell

Python package for interfacing with command-line utilities, like yum, apt-get, or ls, in a Pythonic manner

Simple example

from sultan.api import Sultan s = Sultan() s.sudo("yum install -y tree").run()

Better in a context manager:

from sultan.api import Sultan with Sultan.load(sudo=True) as s: s.yum("install -y tree").run()

Even works remotely:

from sultan.api import Sultan with Sultan.load(sudo=True, hostname="myserver.com") as sultan: sultan.yum("install -y tree").run()

Brian #3: Flake8Lint

Sublime Text plugin for lint Python files. Includes these linters and style checkers: Flake8 (used in "Python Flake8 Lint") is a wrapper around these tools: pep8 is a tool to check your Python code against some of the style conventions in PEP8. PyFlakes checks only for logical errors in programs; it does not perform any check on style. mccabe is a code complexity checker. It is quite useful to detect over-complex code. According to McCabe, anything that goes beyond 10 is too complex. See Cyclomatic_complexity. There are additional tools used to lint Python files: pydocstyle is a static analysis tool for checking compliance with Python PEP257. pep8-naming is a naming convention checker for Python. flake8-debugger is a flake8 debug statement checker. flake8-import-order is a flake8 plugin that checks import order in the fashion of the Google Python Style Guide (turned off by default).

Michael #4: Magic Wormhole

Get things from one computer to another, safely. A library and a command-line tool named wormhole, which makes it possible to get arbitrary-sized files and directories (or short pieces of text) from one computer to another. The two endpoints are identified by using identical "wormhole codes” Video from PyCon 2016: https://www.youtube.com/watch?v=oFrTqQw0_3c The codes are short and human-pronounceable, using a phonetically-distinct wordlist. As a library too: The wormhole module makes it possible for other applications to use these code-protected channels.

Brian #5: Python Virtual Environments Primer

why do we need virtual environments what are they how to use them / how do they work also virtualenvwrapper using different versions of python pyvenv

Michael #6: How Rust can replace C, with Python's help

Why Rust? Rust has a type system feature that helps eliminate memory leaks, proper interfaces, called 'traits', better type inference, better support for concurrency, (almost) first-class functions that can be passed as arguments. It isn’t difficult to expose Rust code to Python. A Rust library can expose a C ABI (application binary interface) to Python without too much work. Some Rust crates (as Rust packages are called) already expose Python bindings to make them useful in Python. A new spate of projects are making it easier to develop Rust libraries with convenient bindings to Python – and to deploy Python packages that have Rust binaries Rust-CPython: What it is: A set of bindings in Rust for the CPython runtime. This allows a Rust program to connect to CPython, use its ABI, run Python programs through it, and work with representations of Python objects in Rust itself. Who it’s for: Rust programmers who want to hook into CPython and control it from the inside out. PyO3 What it is: For Rust developers, the PyO3 project provides a basic way to write Rust software with bindings to Python in both directions. A Rust program can interface with Python objects and the Python interpreter, and can expose Rust methods to a Python program in the same way a C module does. Who it’s for: Those writing modules that work closely with the Python runtime, and need to interact directly with it. Snaek What it is: Another project in the early stages, Snaek lets developers create Rust libraries that are loaded dynamically into Python as needed, but don’t rely on being linked statically against Python’s runtime. Doesn’t use CTypes but CFFI Who it’s for: Those who want to expose methods written in Rust to a Python script, or for Rust developers who don’t want or need to become familiar with Python. And there is a cookiecutter project / template too https://github.com/mckaymatt/cookiecutter-pypackage-rust-cross-platform-publish “A very important goal of the project,” writes its maintainers, “is that it be able to produce a binary distribution (Wheel) which will not require the end user to actually compile the Rust code themselves.”

#36 Craft Your Python Like Poetry and Other Musings

Jul 28, 2017 00:22:34


Brought to you by Rollbar! Create an account and get special credits at pythonbytes.fm/rollbar

Brian #1: Craft Your Python Like Poetry

Line length is important. Shorter is often more readable. line break placement makes a huge difference in readability and applies to comprehensions function call parameters chained function calls. (Dot alignment is pleasing and nothing I have considered previously) dictionary literals

Michael #2: The Fedora Python Classroom Lab

Makes it easy for teachers and instructors to use Fedora in their classrooms or workshops. Ready to use operating system with important stuff pre-installed With GNOME or as a headless environment for Docker or Vagrant Lots of prebuilt goodies, especially around data science: IPython, Jupyter Notebook, multiple Pythons, virtualenvs, tox, git and more

Brian #3: How a VC-funded company is undermining the open-source community

A San Francisco startup called Kite is being accused of underhanded tactics. An Atom plugin called Minimap, downloaded more than 3.5 M times, open source, and developed primarily by one person. @abe33 abe33 hired by Kite, then adds a “Kite Promotion” “feature” to Minimap that examines user code and inserts links to related parts of Kite website. (Presumably in the minimap?) Users rightfully ticked. Next. autocomplete-Python, also an Atom addon, seems to be taken over by Kite engineers and changes the autocomplete from local Jedi engine to cloud Kite engine (also therefore sending users code to Kite). Seems like that ought to have been a separate plugin, not a take over of an existing one. Again, users not exactly supportive of the changes.

Michael #4: Newspaper Python Package

News, full-text, and article metadata extraction in Python 3 Behold the example code: from newspaper import Article url = 'http://fox13now.com/2013/12/30/new-year-new-laws-obamacare-pot-guns-and-drones/' article = Article(url) article.download() article.parse() article.authors # ['Leigh Ann Caldwell', 'John Honway'] article.publish_date # datetime.datetime(2013, 12, 30, 0, 0) article.nlp() article.keywords # ['New Years', 'resolution', ...] article.summary # 'The study shows that 93% of people ...'

Brian #5: IEEE Spectrum: The Top Programming Languages 2017

We’re #1. We’re #1. Python on top of the list IEEE very open about their methodology. Combo of Google, Google Trends, GitHub, Twitter, Reddit, StackOverflow, HackerNews, CareerBuilder, Dice, and IEEE Xplore Digital Library Python #1 in lots of categories. Java still has more job openings, supposedly. Although I think it’s because Java people are quitting to go work on Python projects.

Michael #6: SciPy 2017 videos are out

Bunch of tutorials Keynote - Coding for Science and Innovation, Gaël Varoquaux Dash - A New Framework for Building User Interfaces for Technical Computing, Dask - Advanced Techniques, Matthew Rocklin Scientific Analysis at Scale - a Comparison of Five Systems, Jake V. Keynote - Academic Open Source, Kathryn Huff Plus lots more

#35 How developers change programming languages over time

Jul 19, 2017 00:24:44


Brian #1: Python Quirks : Comments

Python developers put comments in their code. # Like this """ And like this """ "And like this." ["Not usually like this","but it's possible"] Philip Trauner timed all of these. Actual # comments are obviously way faster. He also shows the AST difference. Don’t abuse the language. Unused unreferenced strings are not free.

Michael #2: Python 3.6.2 is out!

Security bpo-30730: Prevent environment variables injection in subprocess on Windows. Prevent passing other environment variables and command arguments. bpo-30694: Upgrade expat copy from 2.2.0 to 2.2.1 to get fixes of multiple security vulnerabilities including: CVE-2017-9233 (External entity infinite loop DoS), CVE-2016-9063 (Integer overflow, re-fix), CVE-2016-0718 (Fix regression bugs from 2.2.0’s fix to CVE-2016-0718) and CVE-2012-0876 (Counter hash flooding with SipHash). Note: the CVE-2016-5300 (Use os-specific entropy sources like getrandom) doesn’t impact Python, since Python already gets entropy from the OS to set the expat secret using XML_SetHashSalt(). bpo-30500: Fix urllib.parse.splithost() to correctly parse fragments. For example, splithost('//') now correctly returns the host, instead of treating @evil.com as the host in an authentification (login@host). Core and Builtins bpo-29104: Fixed parsing backslashes in f-strings. bpo-27945: Fixed various segfaults with dict when input collections are mutated during searching, inserting or comparing. Based on patches by Duane Griffin and Tim Mitchell. bpo-30039: If a KeyboardInterrupt happens when the interpreter is in the middle of resuming a chain of nested ‘yield from’ or ‘await’ calls, it’s now correctly delivered to the innermost frame. Library bpo-30038: Fix race condition between signal delivery and wakeup file descriptor. Patch by Nathaniel Smith. bpo-23894: lib2to3 now recognizes rb'...' and f'...' strings. bpo-24484: Avoid race condition in multiprocessing cleanup (#2159) Windows bpo-30687: Locate msbuild.exe on Windows when building rather than vcvarsall.bat bpo-30450: The build process on Windows no longer depends on Subversion, instead pulling external code from GitHub via a Python script. If Python 3.6 is not found on the system (via py -3.6), NuGet is used to download a copy of 32-bit Python. Plus about 40 more fixes / changes

Brian #3: Contributing to Open Source Projects: Imposter Syndrome Disclaimer

“How to contribute” often part of OSS projects. Adrienne Lowe of codingwithknives.com has an “Imposter Syndrome Disclaimer” to include in your contributing documentation that’s pretty great. She’s also collecting examples of people using it, or similar. From the disclaimer:

“Imposter syndrome disclaimer: I want your help. No really, I do. There might be a little voice inside that tells you you're not ready; that you need to do one more tutorial, or learn another framework, or write a few more blog posts before you can help me with this project. I assure you, that's not the case. … And you don't just have to write code. You can help out by writing documentation, tests, or even by giving feedback about this work. (And yes, that includes giving feedback about the contribution guidelines.)“

Michael #4: The Dark Secret at the Heart of AI

via MIT Technology Review There’s a big problem with AI: even its creators can’t explain how it works Last year, an experimental vehicle, developed by researchers at the chip maker Nvidia, didn’t look different from other autonomous cars, but it was unlike anything demonstrated by Google, Tesla, or General Motors, and it showed the rising power of artificial intelligence. The car didn’t follow a single instruction provided by an engineer or programmer. Instead, it relied entirely on an algorithm that had taught itself to drive by watching a human do it. The result seems to match the responses you’d expect from a human driver. But what if one day it did something unexpected—crashed into a tree, or sat at a green light? As things stand now, it might be difficult to find out why. And you can’t ask it: there is no obvious way to design such a system so that it could always explain why it did what it did. There’s already an argument that being able to interrogate an AI system about how it reached its conclusions is a fundamental legal right We’ve never before built machines that operate in ways their creators don’t understand. How well can we expect to communicate—and get along with—intelligent machines that could be unpredictable and inscrutable

Brian #5: Arrange Act Assert pattern for Python developers

James Cooke Good introduction to test case structure. Split your tests into setup, action, assertions. Pattern also known by: Given, When, Then Setup, Test, Teardown Setup, Exercise, Verify, Teardown Also covered in: testandcode.com/10 pythontesting.net/strategy/given-when-then-2

Michael #6: Analyzing GitHub, how developers change programming languages over time

From source{d}: Building the first AI that understands code Have you ever been struggling with an nth obscure project, thinking : “I could do the job with this language but why not switch to another one which would be more enjoyable to work with” ? Derived from The eigenvector of “Why we moved from language X to language Y”, Erik Bernhardsson ** Dataset available 4.5 Million GitHub users 393 different languages 10 TB of source code in total I find it nice to visualize developer’s language usage history with a kind of Gantt diagram. We did not include Javascript because Most popular languages on GitHub At last! Here is the reward: the stationary distribution of our Markov chain. This probability distribution is independent of the initial distribution. It gives information about the stability of the process of random switching between languages. Rank Language Popularity, % Source code, % 1. Python 16.1 11.3 2. Java 15.3 16.6 3. C 9.2 17.2 4. C++ 9.1 12.6 5. PHP 8.5 24.4 6. Ruby 8.3 2.6 7. C# 6.1 6.5

Python (16.1 %) appears to be the most attractive language, followed closely by Java (15.3 %). It’s especially interesting since only 11.3 % of all source code on GitHub is written in Python.

Although there are ten times more lines of code on GitHub in PHP than in Ruby, they have the same stationary distribution. What about sticking to a language ? Developers coding in one of the 5 most popular languages (Java, C, C++, PHP, Ruby) are most likely to switch to Python with approx. 22% chance on average. Similarly, a Visual Basic developer has more chance (24%) to move to C# while Erik’s is almost sure in this transition with 92% chance. People using numerical and statistical environments such as Fortran (36 %), Matlab (33 %) or R (40 %) are most likely to switch to Python in contrast to Erik’s matrix which predicts C as their future language.

#34 The Real Threat of Artificial Intelligence

Jul 13, 2017 00:22:57


Sponsored by Rollbar! Get the bootstrap plan at pythonbytes.fm/rollbar

Brian #1: Easy Python logging with daiquiri

Standard library logging package is non-intuitive. Daiquiri is better. Logs to stderr by default. Use colors if logging to a terminal. Support file logging. Use program name as the name of the logging file so providing just a directory for logging will work. Support syslog. Support journald. JSON output support. Support of arbitrary key/value context information providing. Capture the warnings emitted by the warnings module. Native logging of any exception. This works: import daiquiri daiquiri.setup() logger = daiquiri.getLogger() logger.error("something wrong happened") Also check out logzero

from logzero import logger logger.debug("hello") logger.info("info") logger.warn("warn") logger.error("error")

Michael #2: The Real Threat of Artificial Intelligence

What worries you about the coming world of artificial intelligence? Too often the answer to this question resembles the plot of a sci-fi thriller. People worry that developments in A.I. will bring about the “singularity” This doesn’t mean we have nothing to worry about. On the contrary, the A.I. products that now exist are improving faster than most people realize and promise to radically transform our world, not always for the better AI will reshape what work means and how wealth is created, leading to unprecedented economic inequalities and even altering the global balance of power This kind of A.I. is spreading to thousands of domains (not just loans), and as it does, it will eliminate many jobs. Bank tellers, customer service representatives, telemarketers, stock and bond traders, even paralegals and radiologists will gradually be replaced by such software. Part of the answer will involve educating or retraining people in tasks A.I. tools aren’t good at. Artificial intelligence is poorly suited for jobs involving creativity, planning and “cross-domain” thinking — for example, the work of a trial lawyer. The solution to the problem of mass unemployment, I suspect, will involve “service jobs of love.” These are jobs that A.I. cannot do, that society needs and that give people a sense of purpose. Examples include accompanying an older person to visit a doctor, mentoring at an orphanage This leads to the final and perhaps most consequential challenge of A.I. The Keynesian approach I have sketched out may be feasible in the United States and China, which will have enough successful A.I. businesses to fund welfare initiatives via taxes. But what about other countries?

Brian #3: The three laws of config dynamics

The birth of configuration files Law 1 Config values can be transformed from one form to another, but can be neither created nor destroyed. Law 2 The total length of a config file can only increase over time. Law 3 The length of a perfect config file in a development environment is exactly equal to zero. Docker can help

Michael #4: Five Tips To Get You Started With Jupyter Notebook

Don’t Put Your Entire Code in a Single Cell There are different types of cells Executing Cells (shift + enter) Explore Interactive Mapping Options (via ArcGIS) To explore new modules, use questions and TAB auto-complete (Object?)

Brian #5: Cost of Coupling Versus Cost of De-coupling

Two elements are coupled wrt a given change iff changing one element implies changing the other. Decoupled code, or loosely coupled, follows DRY principles, uses smaller components, is more modular, etc. But also has more files, more classes, handles more cases, and takes longer to write. There is a place for both. Kent describes two phases, Explore and Extract. Explore more learning tracer bullets, spike projects, first drafts, happy path implementation coupled code, copy/paste coding, etc work fine and are faster because the design and architecture aren’t the goal, learning is the goal answer questions quickly ask better questions based on learnings Extract Candidate Release, final draft, architected Economies of scale take over Return on investment Minimize cost of changes as code base grows.

Michael #6: 100 Days of Code at PyBites

The Challenge: Join the #100DaysOfCode Stats: We wrote roughly 5K lines of code, divided into 100 scripts, one each day We auto-tweeted our progress each day which was tracked in our log file. Module Index: We ended up using exactly 100 modules as well (weird coincidence LOL) Showcase of 10 Utilities The rumors are true: our next 100 days project will be around learning Django


First book review of up, http://chrisshaver64.ddns.net/bl0046 Python for Entrepreneurs has officially launch! Over 19 hours of content. Get it at https://talkpython.fm/launch

#33 You should build an Alexa skill

Jul 6, 2017 00:17:49


Sponsored by Rollbar! pythonbytes.fm/rollbar

Brian #1: Linting as Lightweight Defect Detection for Python

flake8, pycodestyle, formerly pep8 tool https://pycodestyle.readthedocs.io/en/latest/ pep257 can be checked with flake8-docstrings pydocstyle, http://www.pydocstyle.org/

Michael #2: You should build an Alexa skill

Jacqueline Wilson wrote Amazon Alexa Skill Recipe with Python 3.6 Ingredients: A developer account on https://developer.amazon.com (“Amazon Developer Console”) An AWS account on https://aws.amazon.com (“AWS Console”) Beginner knowledge of Python 3.x syntax Create a “What’s for dinner” bot Amazon calls these utterances: “What should I have for dinner?” “Do you have a dinner idea?” “What’s for dinner?” Tie the commands to an AWS Lambda function (returns a JSON response) Test via Alexa Skill Testing Tool

Brian #3: RISE

Reveal IPython Slide Extension Making slides with Jupyter notebooks

Michael #4: Closer

Run, monitor and close remote SSH processes automatically Closer was born because I had trouble with killing up processes I set up remotely via SSH. That is, you want to run some SSH process in the background, and then you want to kill it, just like you would a local subprocess. Main features: kill the remote process (either by choice, or automatically at the end of the calling process) capture the remote process’s output live monitoring of remote process output get a callback upon remote process’ death

Brian #5: Checklist for *Python libraries APIs*

Michael #6: Fades

Fades is a system that automatically handles the virtualenvs in the cases normally found when writing scripts and simple programs, and even helps to administer big projects. fades will automagically create a new virtualenv (or reuse a previous created one), installing the necessary dependencies, and execute your script inside that virtualenv, with the only requirement of executing the script with fades and also marking the required dependencies. At the moment you execute the script, fades will search a virtualenv with the marked dependencies, if it doesn’t exists fades will create it, and execute the script in that environment. Indicating dependencies (in code or via CLI) import somemodule # fades == 3 import somemodule # fades >= 2.1 import somemodule # fades >=2.1,<2.8,!=2.6.5 Can control the Python version the env is based upon Can ask for a “refresh” on the virtual env You can also configure fades using .ini config files. How to clean up old virtualenvs?

Listener comment, RE: Episode 32:

Jan Oglop:

Hello Michael and Brian, I wanted to thank you for amazing work you do. And let you know that you have helped me to find the working place from my dreams! My colleagues has similar hobbies and loves python as much as I do!

Thank you again!

#32 8 ways to contribute to open source when you have no time

Jul 1, 2017 00:23:10


Brian #1: Introducing Dash

UI library for analytical web applications

Michael #2: Keeping Python competitive

Article on LWN, interview with Victor Stinner He sees a need to improve Python performance in order to keep it competitive with other languages. Not as easy to optimize as other languages. For one thing, the C API blocks progress in this area Python 3.7 is as fast as Python 2.7 on most benchmarks, but 2.7 was released in 2010. Users are now comparing Python performance to that of Rust or Go, which had only been recently announced in 2010. In his opinion, the Python core developers need to find a way to speed Python up by a factor of two in order for it to continue to be successful. JITs may be part of the answer, notably Pyjion by Dino Viehland and Brett Cannon An attendee suggested Cython, which does AoT compilation, but its types are not Pythonic. He suggested that it might be possible to use the new type hints and Cython to create something more Pythonic.

Brian #3: PyPI Quick and Dirty

A completely incomplete guide to packaging a Python module and sharing it with the world on PyPI. - Hynek Schlawack

Michael #4: Minimal examples of data structures and algorithms in Python

Simple algorithmic examples in Python, including linked lists reversing linked lists GCD Queues Binary search depth first search many, many more

Brian #5: 8 ways to contribute to open source when you have no time

Michael #6: NumPy receives first ever funding, thanks to Moore Foundation

For the first time ever, NumPy—a core project for the Python scientific computing stack—has received grant funding. The proposal, “Improving NumPy for Better Data Science” will receive $645,020 from the Moore Foundation over 2 years, with the funding going to UC Berkeley Institute for Data Science. The principal investigator is Dr. Nathaniel Smith. The NumPy project was started in 2006 by Travis Oliphant.

#31 You should have a change log

Jun 21, 2017 00:21:50


Brian #1: TinyMongo

Like MongoDB, but built on top of TinyDB. Even runs on a Raspberry Pi, according to Stephen

Michael #2: A dead simple Python data validation library

validus.isemail('someone@example.com') Validation functions include: isrgbcolor() isphone() isisbn() isipv4() isint() isfloat() isslug() isuuid() Requires Python 3.3+

Brian #3: PuDB

In episode 29, https://pythonbytes.fm/29, I talked about launching pdb from pytest failures. @kidpixo pointed out that PuDB was a better debugger and can also be launched from pytest failures. Starting pudb from pytest failed tests (from docs): pytest --pdbcls pudb.debugger:Debugger --pdb --capture=no Using pytest-pudb plugin to do the same: pytest --pudb

Michael #4: Analyzing Django requirement files on GitHub

From the pyup.io guys Django is the most popular Python web framework. It is now almost 12 years old and is used on all kinds of different projects. Django developers pin their requirements (64%): Pinned or freezed requirements (Django==1.8.12) make builds predictable and deterministic. Django 1.8 is the most popular major release (24%) A bit worrisome are the 1.9 (14%), 1.7 (13%) and 1.6 (13%) releases on the second, third and fourth place. All of them are no longer receiving security updates, 1.7 and 1.6 went EOL over 2 years ago. Yikes: Only 2% of all Django projects are on a secure release Among all projects, more than 60% use a Django release with one or more known security vulnerabilities. Only 2% are using a secure Django release. On the remaining part of more than 30% it's unclear what exactly is going to be installed. That's because the Django release is either unpinned or has a range.

Brian #5: Changelogs

http://keepachangelog.com https://github.com/hawkowl/towncrier

Michael #6: Understanding Asynchronous Programming in Python

by Doug Farrell via Dan Bader’s site A synchronous program is what most of us started out writing, and can be thought of as performing one execution step at a time, one after another. Example: A web server Could be synchronous Could be fully optimized but You’re at best still waiting on network IO back to all the web clients The Real World is Asynchronous: Kids are a long running task with high priority, superseding any other task we might be doing, like the checkbook or laundry. Example 1: Synchronous Programming (using queuing) Example 2: Simple Cooperative Concurrency (using generators) Example 3: Cooperative Concurrency With Blocking Calls (same, but with slow operations) Example 4: Cooperative Concurrency With Non-Blocking Calls (gevent) Example 5: Synchronous (Blocking) HTTP Downloads Example 6: Asynchronous (Non-Blocking) HTTP Downloads With gevent Example 7: Asynchronous (Non-Blocking) HTTP Downloads With Twisted Example 8: Asynchronous (Non-Blocking) HTTP Downloads With Twisted Callbacks

Errata/Giving Credit:

Also in episode 29, https://pythonbytes.fm/29, I talked about pipcache as an alias for pip download. I think I said the author of a blog post contacted me. It wasn’t him. It was @kidpixo. Sorry kidpixo, keep the ideas coming.

For fun: Python Private Methods


Our news

Beta 3 of Python Testing with pytest should come out this week with Chapter 7: Using pytest with other tools, which includes using it with pdb, coverage.py, mock, tox, and Jenkins. Next beta will be the appendices, including a clean up and rewrite of pip and venv appendices, plus a plugin sampler pack, and a tutorial on packaging. Thanks to everyone who has submitted Errata. Finished recording RESTful and HTTP Services in Pyramid AND MongoDB for Python Developers. Add your email address at https://training.talkpython.fm to get notified upon release of each.

#30 You are not Google and other ruminations

Jun 15, 2017 00:24:37


Python Bytes 30

Sponsored by Datadog: Try Datadog and get a free shirt at pythonbytes.fm/datadog.

Brian #1: Problems and Solutions are different at different scales

You are not Google Enough with microservices

Michael #2: Introducing NoDB - a Pythonic Object Store for S3

Released in April 2017 by Rich Jones An incredibly simple, Pythonic object store based on Amazon's S3 static file storage. NoDB isn't a database.. but it sort of looks like one! Kind of like a document database, supports indexing Can use Pickling or JSON Mostly useful for prototyping, casual hacking, and (maybe) even low-traffic server-less databases for Zappa apps! Can see a few use cases for NoDB: Prototyping schemas Storing API event responses for later replay Capturing event logs Storing simple form data (email addresses, etc.) Storing non-relational analytics data Firing Lambda event triggers Version controlling evolving Python objects Storing and loading trained machine learning models https://github.com/Miserlou/NoDB

Brian #3: Elizabeth for mock data Part 1: https://medium.com/wemake-services/generating-mock-data-using-elizabeth-part-i-ca5a55b8027c Part 2: https://medium.com/wemake-services/generating-mock-data-with-elizabeth-part-ii-bb16a3f3106f pytest plugin: https://github.com/lk-geimfari/pytest-elizabeth

Michael #4: What’s New In Python 3.7

Lang: More than 255 arguments can now be passed to a function, and a function can now have more than 255 parameters. Lang: bytes.fromhex() and bytearray.fromhex() now ignore all ASCII whitespace, not only spaces. Lang: Circular imports involving absolute imports with binding a submodule to a name are now supported. Module: contextlib.asynccontextmanager() has been added. Similar to contextmanager(), but creates an asynchronous context manager. This function is a decorator that can be used to define a factory function for async with statement asynchronous context managers, without needing to create a class or separate __aenter__() and __aexit__() methods. Module:The dis() function now is able to disassemble nested code objects (the code of comprehensions, generator expressions and nested functions, and the code used for building nested classes). Module: math: New remainder() function, implementing the IEEE 754-style remainder operation. Optimization: Added two new opcodes: LOAD_METHOD and CALL_METHOD to avoid instantiation of bound method objects for method calls, which results in method calls being faster up to 20%. Optimization: The os.fwalk() function has been sped up by 2 times.

Brian #5: Hypothesis Testing

Unleash the Test Army

Michael #6: Heroku switching default to v3.6.1

Effective Tuesday, June 20th, 2017, new Python applications pushed to Heroku will use the python-3.6.1 runtime by default (instead of python-2.7.13). Existing applications will not be affected by this change. “Lots of new projects start out on heroku all the time, so this is really great news for python 3 adoption.” “Python 3 is really happening. I was actually a little worried about the future of Python for a while.”

#29 Responsive Bar Charts with Bokeh, Flask, and Python 3

Jun 8, 2017 00:23:04


Python Bytes 29

Brought to you by Rollbar! http://rollbar.com/pythonbytes

Brian #1: Responsive Bar Charts with Bokeh, Flask and Python 3

by Matt Makai at fullstackpython.com A walkthrough example of putting together a flask app that uses Bokeh bar charts to visualize data. All steps included, no previous experience with Flask or Bokeh required. Nice explanation of what the code does without going into too much detail. Good jumping off point for further learning, but complete enough to be useful right away.

Michael #2: Zappa Serverless Python Web Services

Zappa makes it super easy to build and deploy all Python WSGI applications on AWS Lambda + API Gateway Think of it as "serverless" web hosting for your Python apps. That means infinite scaling, zero downtime, zero maintenance - and at a fraction of the cost of your current deployments! Better still, with Zappa you only pay for the milliseconds of server time that you use, so it's many orders of magnitude cheaper than VPS/PaaS hosts and in most cases, it's completely free. Plus, there's no need to worry about load balancing or keeping servers online ever again. Asynchronous Task Execution: from flask import Flask from zappa.async import task app = Flask(__name__) @task def make_pie(): """ This takes a long time! """ ingredients = get_ingredients() pie = bake(ingredients) deliver(pie) @app.route('/api/order/pie') def order_pie(): """ This returns immediately! """ make_pie() return "Your pie is being made!"

Brian #3: Using a local cache for pip packages

In https://pythonbytes.fm/24, Local package store, we talked about using pip to cache pypi projects to allow offline installation: $ pip download --cachedir <somePackage> $ pip install --no-index --find-links=/tmp/wheelhouse somePackage Well, Dominic does us one better by wrapping these commands in a couple of aliases. However, his version uses pip install --``download, which has been deprecated. Here’s a version with the new syntax: alias pipcache='pip download --cache-dir ${HOME}/.pip-packages' alias pipinstall='pip install --no-index --find-links=file://${HOME}/.pip-packages/'

Michael #4: Building game AI using ML: Working with TensorFlow, Keras, and the Intel MKL in Python

From the ActivePython guys a classic arcade space shooter game that features enemies powered by machine learning we decided to build a Neural Network to drive the behaviour of the enemies in the game For the game part of things, we’re using PyGame In the training mode, the enemies fire randomly, and then each shot taken by the enemy is recorded as a hit or a miss along with its initial relative position/velocity values. Every one of these shots becomes a row in the training matrix and the network is trained in “realtime” after every row is added so you can see the network build and develop as you train. LESSONS LEARNED Choosing the right data to train your network is important. “Prepping” your data is key. Experiment with network topology. Visualization is important.

Brian #5: Debug Test Failures With Pdb

by Raphael Pierzina Debugging code with pytest, using: --pdb to jump into the debugger at the point of failure -x to stop after first failure --lf to re-run all the tests that failed last time Note: Yes. All this and more is covered in Python Testing with pytest. Shameless plug for my book. Raphael is one of the technical reviewers. Thank you, Raphael!

Michael #6: Monitoring my VOIP provider with Home Assistant

Integrating it into Home Assistant: Use home-assistant.io as a home automation platform in my house. It’s written in Python, open source, and has a large community surrounding it. Unfortunately, there wasn’t anything already built for my Cisco ATA. Decided to write, an open source my first python module called pyciscsospa you can download it and use it for your own ATA as well. Receive a push notification on my phone when the phone lines go down and come back up

#28 The meaning of _ in Python

Jun 2, 2017 00:20:59


Brian #1: pep8.org : PEP 8 — the Style Guide for Python Code

"This stylized presentation of the well-established PEP 8 was created by Kenneth Reitz (for humans)." From PEP 8: "This document gives coding conventions for the Python code comprising the standard library in the main Python distribution." PEP8 is not only used for the standard library. Many if not most open source Python packages adhere to at least most of the PEP8 recommendations testing plugins can help you make sure your code meets the guidelines (for good or bad). The pep8.org presentation is easy to read, with a left side clickable table of contents. Nice color coded examples. Green for good, Red for bad. links to specific items make it easy to share with others something specific. Good advice, but don't be a pep8-bully.

Michael #2: Tokio: Asyncio event loop written in Rust language

Asyncio event loop written in Rust language It is still in alpha stage. It provides most of asyncio event loop apis, except udp. TCP api is more or less stable Aiohttp tests pass with tokio loop (~1800 tests) Mostly interesting as an example of Rust + Python Project is still in early stage of development

Brian #3: Python Boilerplate

Interactive online tool for creating script and small project boilerplate code. Just starting, with "how to help" link. Select Python 2 or 3 executable script or not argparse logging .gitignore Flask unittest or pytest tox fills in main.py, plus other files like test_sample.py, requirements.txt, tox.ini, etc.

Michael #4: Instagram switching to Python 3 on one branch

Ancient Django but still productive Ran out of 32-bit user IDs before they ran out of Django power. Added sharing support to Django Orem Turned off GC for perf Upgraded entirely to 3.6 in a few months Why? Type hints Scaling server perf asyncio Python 3 is where the future community work is happening Strategies No user impact Still shipping Testing process was interesting This is a concrete roadmap for every large company

Brian #5: The Meaning of Underscores in Python

single and double underscore meanings dunder is "double underscore" Single Leading Underscore: _var method or variable for internal use convention only doesn't apply to collection.namedtuple Single Trailing Underscore: var_ used to avoid name collision with keywords Double Leading Underscore: __var internal use by a single class level. Python will name mangle this so that subclasses don't have to avoid parent class double leading underscore names Double Leading and Trailing Underscore: __var__ no name mangling special names. dunder methods __call__ and __init__, etc. Single Underscore: _ in code : temp variable, don't care variable won't get a warning if you don't reference it again in REPL: last value

Michael #6: The future is looking bright for Python

Stack Overflow recently released a cool new tool called Trends (previously covered) Check out the Most Popular Languages trend chart Python has, by a very large margin, the greatest positive slope (future?) And Py3 vs Py2

#27 The PyCon 2017 recap and functional Python

May 25, 2017 00:19:08


All videos available: https://www.youtube.com/channel/UCrJhliKNQ8g0qoE_zvL8eVg Lessons learned: pick up swag on day one. vendors run out. take business cards with you and keep them on you Not your actual business cards unless you are representing your company. Cards that have your social media, github account, blog, or podcast or whatever on them. 3x3 stickers are too big. 2x2 plenty big enough lightening talks are awesome, because they are a lot of ranges of speaking experience will definitely do that again try to go to the talks that are important to you, but don’t over stress about it, since they are taped. However, it would be lame if all the rooms were empty, so don’t everybody ditch. lastly: everyone knows Michael.

Michael #2: How to Create Your First Python 3.6 AWS Lambda Function

Tutorial from Full Stack Python Walks you through creating an account Select your Python version (3.6, yes!) def lambda_handler(event, context): … # write this function, done! Set and read environment variables (could be connection strings and API keys)

Brian #3: How to Publish Your Package on PYPI

jetbrains article structure of the package oops. do