Episode #55: Flask, Flask, Flask, 3x Flask
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
- Python 3 only
- 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
- 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/