Michael Kennedy and Brian Okken

Python Bytes

Developer headlines delivered directly to your earbuds
Python Bytes

Description

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/

Categories

Technology

Episodes

#107 Restructuring and searching data, the Python way

Dec 7, 2018 00:22:50

Description:

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)

Examples

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.

Extras:

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

Description:

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

Description:

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

Extras:

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

Description:

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

Description:

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

Description:

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

Extras:

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

Description:

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

Extras:

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

Description:

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

Extra:

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

Description:

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.

Extra:

Brian: Power Mode II

#98 Python-Electron as a Python GUI

Oct 8, 2018 00:26:58

Description:

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.

Extra:

Michael's Async course talkpython.fm/async

#97 Java goes paid

Sep 28, 2018 00:24:36

Description:

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.

Extras:

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

Description:

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.”

Example:

>>> 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.

Extras

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

Description:

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

Extras:

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

Description:

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

@joelgrus

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

Extras

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

Description:

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

Description:

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

Extras:

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

Description:

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:

Michael:

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

Description:

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

Description:

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

Extras:

Brian:

numpy 1.15.0 just released recently. Switched testing to pytest.

Michael:

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

Description:

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

Description:

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

Description:

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

Example:

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:

Example:

# 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

Description:

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

Description:

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)

Also:

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

Description:

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

Description:

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

Description:

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

Example:

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

Description:

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

Description:

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

Description:

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:

Michael:

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

Description:

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.

Extras:

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

Description:

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

Description:

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

Description:

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/

Quotes:

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

Description:

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 0.0.7.2 (with 72 releases)

Apr 5, 2018 00:22:54

Description:

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."

Extra:

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

Description:

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

Description:

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

Michael:

#100DaysOfCode in Python course: talkpython.fm/100days

#69 Digging into StackOverflow's 2018 survey results

Mar 18, 2018 00:24:00

Description:

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

Michael:

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

Brian:

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

Description:

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

Description:

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

Brian:

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

Description:

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

Brian

Productive pytest with PyCharm webinar was recorded Thursday 22nd of Feb. Will be available here: https://www.jetbrains.com/community/webinars/

Michael:

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

Description:

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

Brian:

Upcoming webinar: Productive pytest with Pycharm

Michael:

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

Description:

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

Brian:

Speaking at PyCon 2018. “PyCharm and pytest”. Speaking with Paul Everitt Upcoming webinar: Productive pytest with Pycharm Feb 22, registration open

Michael:

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

Description:

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'

test_something.py

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

Michael

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

Description:

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

Michael

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

Description:

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

Description:

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

Michael

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

Description:

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

Description:

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

Description:

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

Description:

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

Description:

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

Michael:

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

Description:

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…

Extras

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

Description:

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)

Extras

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

Description:

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

Michael:

Flash briefing? Firefox Quantum!

#51 How to make your code 80 times faster

Nov 9, 2017 00:21:33

Description:

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

Description:

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

Description:

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

Description:

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

Description:

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

Michael:

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

Description:

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

Description:

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

Description:

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

Michael:

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)

Brian:

Book is shipping: Python Testing with pytest

#43 Python string theory, v2

Sep 14, 2017 00:18:48

Description:

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

Description:

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

Description:

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 0.0.0.0/0 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

Miguel:

Blog The New and Improved Flask Mega-Tutorial

Michael:

RESTful and HTTP APIs in Pyramid

#40 Packet Manipulation with Scapy

Aug 24, 2017 00:22:59

Description:

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

Description:

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

Description:

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

Description:

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

Description:

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

Description:

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('//127.0.0.1#@evil.com/') now correctly returns the 127.0.0.1 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

Description:

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

Extra:

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

Description:

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

Description:

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

Description:

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

http://turnoff.us/geek/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

Description:

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

Description:

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

Description:

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

Description:

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. doesn't include src, see https://pythonbytes.fm/22 decent discussion of a the contents of the setup.py file (but interestingly absent is an example setup.py file) good discussion of .pypirc file and links to the test and production PyPi example of using twine to push to PyPI overall: good discussion, but you'll still need a decent example.

Michael #4: Coconut: Simple, elegant, Pythonic functional programming

Coconut is a functional programming language that compiles to Python. Since all valid Python is valid Coconut, using Coconut will only extend and enhance what you're already capable of in Python. pip install coconut Some of Coconut’s major features include built-in, syntactic support for: Pattern-matching, Algebraic data-types, Tail call optimization, Partial application, Better lambdas, Parallelization primitives, and A whole lot more, all of which can be found in Coconut’s detailed documentation. Talk Python episode coming in a week

Brian #5: Choose a licence

MIT : simple and permissive Apache 2.0 : something extra about patents. GPL v3 : this is the contagious one that requires derivitive work to also be GPL v3 Nice list with overviews of what they all mean with color coded bullet points: https://choosealicense.com/licenses/

Michael #6: Python for Scientists and Engineers

Table of contents: Beginners Start Here: Create a Word Counter in Python An introduction to Numpy and Matplotlib Introduction to Pandas with Practical Examples (New) Main Book Image and Video Processing in Python Data Analysis with Pandas Audio and Digital Signal Processing (DSP) Control Your Raspberry Pi From Your Phone / Tablet Machine Learning Section Machine Learning with an Amazon like Recommendation Engine Machine Learning For Complete Beginners: Learn how to predict how many Titanic survivors using machine learning. No previous knowledge needed! Cross Validation and Model Selection: In which we look at cross validation, and how to choose between different machine learning algorithms. Working with the Iris flower dataset and the Pima diabetes dataset. Natural Language Processing Introduction to NLP and Sentiment Analysis Natural Language Processing with NTLK Intro to NTLK, Part 2 Build a sentiment analysis program Sentiment Analysis with Twitter Analysing the Enron Email Corpus: The Enron Email corpus has half a million files spread over 2.5 GB. When looking at data this size, the question is, where do you even start? Build a Spam Filter using the Enron Corpus

In other news:

Python Testing with pytest Beta release and initial feedback is going very well.

#26 How have you automated your life, or CLI, with Python?

May 19, 2017 00:19:44

Description:

Sponsored by rollbar: rollbar.com/pythonbytes

Brian #1: Two part series on interactive terminal applications

Part 1: 4 terminal applications with great command-line UIs

For Comparison: both ok but could be better MySQL REPL Python REPL bpython adds autocompletion and other goodies also check out ptpython as a REPL replacement mycli adds context aware completion to MySQL mycli - pgcli for postgress that adds fuzzy search fish : like bash, but has better search history

Part 2: 4 Python libraries for building great cli's

prompt_toolkit - for building a REPL like interface includes command history, auto-suggestion, auto-completion click includes pager and ability to launch an editor fuzzyfinder - make suggestions article shows how to combine that with prompt_toolkit pygments - syntax highlighting

Michael #2: How have you automated your life with python?

There is something magical about writing code that interacts with the physical world. I have a script which runs every 5 minutes between 17:00 and 17:30 which scrapes the train times website and sends me desktop notifications saying whether or not my trains home are delayed / cancelled. I recently wrote a quick python script that tells me when my girlfriend comes home: It sniffs the network for DHCP traffic, when her phone joins the wifi network outside it uses the say command to let me know. Wrote a script to check if nearby ice cream shops are stocking my favourite (rare) flavour by scanning their menu page for keywords. A script to check the drive time too/from work using a route with tolls or without tolls.. to try and save some money when the times aren't too different. Using google maps API and a flask site. I have a script that generates weekly status update emails based off my git commit messages and pull requests. It also creates timesheets in Harvest based on the projects I'm assigned. I have thrown together some python that automatically controls my reverse-cycle AC system so that it makes optimal use of my solar panels on my roof.

Brian #3: Building a Simple Birthday App with Flask-SQLAlchemy

Nice simple application with a clear need. Keep track of upcoming birthdays Avoid Faceboook Build a simple Flask app Try SQLAlchemy

Sponsored by Rollbar, try them at rollbar.com/pythonbytes and don't forget to visit their booth at PyCon!

Michael #4: Spelling with Elemental Symbols

How does it work? Input: "Amputations" Output: "AmPuTaTiONS", "AmPUTaTiONS" Generating Character Groupings: 'AmPuTaTiONS' (2,2,2,2,1,1,1) 'AmPUTaTiONS' (2,1,1,2,2,1,1,1) How many are there in general for a given word? fib(n + 1)! Addressing Performance Issues: A few attempts don’t add much but Memoization: The technique of saving a function's output and returning it if the function is called again with the same inputs. A memoized function only needs to generate output once for a given input. This can be very helpful with expensive functions that are called many times with the same few inputs, but only works for pure functions. → 30% faster Algorithms: Switch to directed graphs and recursion, changes O(2^n) to O(n) and time from 16min to 10 sec. Learned a great deal along the way. This project introduced: Combinatorics Performance profiling Time complexity Memoization Recursion Graphs and trees

Brian #5: IDE's for beginners

Recent discussion on Reddit about Thonny I have mixed feelings about encouraging beginner IDE's. Mostly negative feelings. And yet there is IDLE, there is Thonny, ... Are these useful? Anti-useful? Isn't learning a decent editor part of learning to program?

Michael #6: PDF Plumber

Plumb a PDF for detailed information about each char, rectangle, line, et cetera — and easily extract text and tables. Visual debugging with .to_image() Extracting tables pdfplumber's approach to table detection borrows heavily from Anssi Nurminen's master's thesis, and is inspired by Tabula. It works like this: For any given PDF page, find the lines that are (a) explicitly defined and/or (b) implied by the alignment of words on the page. Merge overlapping, or nearly-overlapping, lines. Find the intersections of all those lines. Find the most granular set of rectangles (i.e., cells) that use these intersections as their vertices. Group contiguous cells into tables. Check out the demonstrations section.

#25 Could we have more in-database machine learning please?

May 12, 2017 00:17:53

Description:

Michael #1: Python in SQL Server 2017: enhanced in-database machine learning

in-database analytics and machine learning with Python in SQL Server. Why? Elimination of data movement: You no longer need to move data from the database to your Python application or model. Instead, you can build Python applications in the database. Easy deployment: Once you have the Python model ready, deploying it in production is now as easy as embedding it in a T-SQL script Rich extensibility: You can install and run any of the latest open source Python packages in SQL Server to build deep learning and AI applications on huge amounts of data in SQL Server. Works in express edition of SQL Server The standard open source CPython interpreter (version 3.5) and some Python packages commonly used for data science are downloaded and installed during SQL Server setup if you choose the Python option in the feature tree. Currently, a subset of packages from the popular Anaconda distribution is included along with Microsoft’s RevoScalePy package. The set of packages available for download will evolve as we move toward general availability of this feature.

Brian #2: Generating Fake Data for Python Unit Tests with Faker

Used in Content Negotiation with the Pyramid Web Framework Faker is great. From the pypi page: “Faker is a Python package that generates fake data for you. Whether you need to bootstrap your database, create good-looking XML documents, fill-in your persistence to stress test it, or anonymize data taken from a production service, Faker is for you.” The article above is a great introduction to show you what you can do with it. Faker includes localization, so you can get the output to match the proper language you want.

Brian #3: Stack Overflow Trends tool

Stack overflow introduces a trends tool starting with a graph that shows the questions using the terms Python, PHP, and Perl, plotted year vs % of total questions. https://zgab33vy595fw5zq-zippykid.netdna-ssl.com/wp-content/uploads/2017/05/languages-2-1024x621.png Python’s growth since 2012 has been fairly steady, growing from ~3.5% to over 8% Plus, the trends tool looks fun.

Sponsorship slots are available right now. Please contact us if you’re interested.

Michael #4: We asked 20,000 people who they are and how they’re learning to code

Thanks Alan Jones Who participated? More than 20,000 new coders responded to this survey. These are people who have been coding for less than 5 years. 62% of them live outside the US their average age is 28 years old 19% are women They’ve been coding for an average of 21 months 25% have already landed their first developer job 40% of them would like to either freelance or start their own business. Most of them are interested in working as web developers, but are also interested in a wide variety of developer specializations. Most new coders haven’t yet started listening to podcasts, but the ones who do listen to a wide range of them.

Brian #5 Introduction to Anomaly Detection

Anomaly Detection Techniques Simple Statistical Methods Challenges Machine Learning-Based Approaches Density-Based Anomaly Detection Clustering-Based Anomaly Detection Support Vector Machine-Based Anomaly Detection Building a Simple Detection Solution Using a Low-Pass Filter Moving Average Using Discrete Linear Convolution

Michael #6: Beeware: A request for your help

What is Beeware? Started 4 years ago. Since then, the BeeWare project has grown to encompass support for mobile platforms, two alternate Python implementations, and a cross platform widget set - as well as the developer tools that started the project originally. Lots of work done over the last 6 months: Extensive improvements to Batavia and VOC; An Android backend for Toga; A Django backend for Toga, enabling Toga apps to be deployed as web apps; A Winforms backend for Toga, enabling Toga apps to run on Windows with a modern appearance; Unfortunately, my contract with Jambon is coming to a close - which means my contributions to BeeWare will go back to being what my spare time allows. So - this is an appeal to you - the Python community. If you are excited by the prospect of having access to Python on mobile platforms, or you would like to write applications in Python that have completely native user interfaces - I need your help for just US$10 a month - you can join the BeeWare project as a member,

Other news

pycascades.com is a regional PyCon for the Pacific Northwest.

#24 I have a local PyPI server and so do you!

May 3, 2017 00:19:29

Description:

Welcome to Python bytes. Episode 24, recorded May 2, 2017. This episode is sponsored by rollbar: https://rollbar.com/pythonbytes

Brian #1: Learning Python Series by Doug Farrell, published on dbader.org

Doug Ferrell wrote for Robotics and Beyond , a STEM educational space This is part 1: Let’s Program with Python: Statements, Variables, and Loops

Michael #2: Geeking out in your older years

Over 500 respondents on http://pythontutor.com/ Age group: 60-85 Opportunities: Help older adults become software dev proficient to Connect with their grand children Fill the growing tech / teacher gap Mentor others Keep mentally active Pursue their hobbies Used MOOCs, online courses, books, and more to learn Felt somewhat isolated and disconnected How could we all help? Or help them help themselves as a group?

Brian #3: Local package store

Not a story, just something I used for the plane trip that didn’t know worked before. Stops my quest for a easy to use local pypi server.

Download without installing

$ cd /tmp/wheelhouse $ python3.6 -m pip download <somePackage>

Then, later, probably within a virtual env

$ python3.6 -m pip install --no-index --find-links=/tmp/wheelhouse somePackage

Does it work with requirements files? Yes!

pip3 download -r /full_path_to/requirements.txt

Sponsored by rollbar https://rollbar.com/pythonbytes

Adding the Rollbar Python SDK is as easy as pip install rollbar. Make sure to check out Rollbar at Pycon. Grab swag and get a product demo. Visit https://rollbar.com/pythonbytes and get the get the Bootstrap Plan free for free 100,000 rollbar events / mo, 180 days retention

Michael #4: Modifying the Python language in 6 minutes

Anthony Shaw I’m writing my findings on how CPython works and show you how easy it is to modify the Python syntax. I’m going to show you how to add a new feature to the Python syntax. Level 1: PEPs Level 2: Grammar The Grammar file is simple text file describing all the elements of the Python language. This is used by not just CPython, but other implementations like PyPy to keep consistency and agree on the types of language semantics. New statements incr_stmt: '++' decr_stmt: '--' Level 3 : Lexer: There are four steps that Python takes when you hit return: lexing, parsing, compiling, and interpreting. Lexing is breaking the line of code you just typed into tokens. Level 4 : Parser: The parser takes those tokens and generates a structure that shows their relationship to each other. For Python and many other languages, this is the Abstract Syntax Tree (or AST). Level 5: Compiler: The compiler then takes the syntax tree and ‘visits’ each branch, the CPython compiler has a method for visiting a statement, called compile_visit_stmt which is just a big switch statement looking at the statement kind. https://github.com/tonybaloney/cpython/commit/fd7c20c3a3a02b4f2dae8ec7a90448627aa0d757

Brian #5: colorful

“Terminal string styling done right, in Python” Add color to terminal applications with a pretty easy to read syntax

Michael #6: Five steps to add the _bling_ factor your Python package **

by Tjelvar Olsson Step 1: Host the documentation on readthedocs Step 2: Set up continuous integration testing on Travis Ci Step 3: Calculate your code coverage using Codecov Step 4: Upload your Package to PyPi Step 5: Add badges to your project’s README file

#23 Can you grok the GIL?

Apr 26, 2017 00:19:34

Description:

Sponsored by ADVANCE DIGITAL. Find your Python web job at http://python.advance.net/

Brian #1: Grok the GIL - How to write fast and thread-safe Python

A. Jesse Jiryu Davis teaches us about the GIL, and how to use that knowledge to decide between threads and processes for parallelism. From the article: The GIL's effect on the threads in your program is simple enough that you can write the principle on the back of your hand: "One thread runs Python, while N others sleep or await I/O." Discusses and Cooperative multitasking and Preemptive multitasking When can a Python process be interrupted? (between bytecodes) When do you need to use thread protection? (less than you think) A. Jesse Jiryu Davis will be speaking at PyCon 2017, which will be held May 17-25 in Portland, Oregon. Catch his talk, Grok the GIL: Write Fast and Thread-Safe Python, on Friday, May 19.

Michael #2: The New NBA by Mark Cuban

Introduction to machine learning in Python & Jupyter notebooks Mark Cuban using Python and ML to play with his NBA team “We have a team at the Mavs but I need to know it to help define strategy and make decisions”

Brian #3: Ian Cordasco gets a Community Service Award from PSF

Ian was on Test & Code, episode 13, talking about Betamax From the announcement: Ian Cordasco has been the PSF’s Election Administrator since 2015, volunteering his efforts for this important role. Cordasco frequently mentors newer coders and supports their Python endeavors. The Python Software Foundation award the 2017 Q1 Community Service Award to Ian Cordasco for his contributions to PSF elections and active mentoring of women in Python community. Cordasco has a history of going out of his way to support and encourage female developers. When Carol Willing, a developer for the Jupyter project, wanted to work on the Requests library, she got in touch with Cordasco. “We worked together on the project and my first commit to the Requests library got accepted!” Cordasco later wrote a fantastic post about it on his blog.

Sponsored by ADVANCE DIGITAL

They have a small team of developers who work in an agile/devops environment– you will make an impact with your work quickly They are mostly a python shop, but there is an opportunity to introduce and run other technologies at scale They fund employee development and conference attendance They are located in beautiful Jersey City, one stop from Manhattan on the PATH They are one of the 10 largest news sites by traffic in the US Apply at http://python.advance.net/

Michael #4: Release of IPython 6.0

by Matthias Bussonnier IPython goes Python 3 only Our personal experience writing Python3-only source code. The size of the IPython codebase has decreased by about 1500 lines of Python code relative to the last release. Of course, that’s not solely due to the removal of Python 2 support, but a non-negligible amount is. even more remarkable in light of completely new features that required adding hundreds of lines of code This change eases the burden on contributors to IPython. Contributors can can spend less time thinking “what about Python 2”, or rewriting a pull request because the Python 2 test suite fails. At the same time, our tests now complete more quickly on continuous integration services because they need to run on fewer versions of Python. From a developer point of view we are extremely pleased with having the possibility to write Python3-only code, and are looking forward to even more improvements like pathlib. We hope you will enjoy this release. It will be the base for some awesome features, like async/await REPL.

Brian #5: Testing & Packaging

Hynek Schlawack describes why he was convinced to use a src directory in package distributions he works on. Just use a src dir (of course it doesn’t have to be exactly “src” but that’s the convention and it should be different than your package name), it will make your life easier. Without it, it is easy to think you are testing an installed package, but you’re really testing the modules before install. These can be different. Better to test as close to how your users will see the package as possible, and using a src dir helps that.

Michael #6: AWS Lambda adds Python 3.6 support

AWS Lambda is a compute service that lets you run code without provisioning or managing servers. AWS Lambda executes your code only when needed and scales automatically, from a few requests per day to thousands per second. You pay only for the compute time you consume - there is no charge when your code is not running. You can also build serverless applications composed of functions that are triggered by events and automatically deploy them using AWS CodePipeline and AWS CodeBuild. Already good things cometh: Zappa has Python 3 support.

#22 PYTHONPATH considered harmful

Apr 18, 2017 00:15:50

Description:

Sponsored by ADVANCE DIGITAL. Find your rewarding Python job at http://python.advance.net/

#1 Brian: PYTHONPATH considered harmful

Don’t do it. You might not regret it today. But later you will. Mucks up distribution searches, etc. “For one, most directories are poorly suited to be on the Python search path. Consider, for example, the root directory of a typical Python project: it contains setup.py -- and so, if it were added to the current search path, import setup would become possible. (This is one reason to have src/ directories.) Often, directories added unwisely to the Python search path cause files to be imported from paths they do not expect to, and surprisingly conflict.”

#2 Michael: keon/algorithms

Minimal examples of data structures and algorithms in Python Topics include Array circular_counter flatten garage merge_intervals graphs clone_graph find_path traversal trees etc.

#3 Brian: Glyph on attrs

We talked about attrs in episode 11, and pointed to the project and the docs. I came across good article introducing why you should use attrs, by glyph, from 2016. The one Python library everyone needs: https://glyph.twistedmatrix.com/2016/08/attrs.html Discusses problems with using lists and tuples as data structures. creating your own classes properly. possible problems with namedtuple (-ish. I still love namedtuple).

Sponsored by ADVANCE DIGITAL

A small team of developers who work in an agile/devops environment– you will make an impact with your work quickly Are mostly a python shop, but there is an opportunity to introduce and run other technologies at scale Fund employee development and conference attendance Are located in beautiful Jersey City, one stop from Manhattan on the PATH Are one of the 10 largest news sites by traffic in the US Apply at http://python.advance.net/

#4 Michael: Curio for Python 3.5+ concurrency

Curio is a library for performing concurrent I/O and common system programming tasks such as launching subprocesses and farming work out to thread and process pools. Curio is solely concerned with the execution of coroutines. A coroutine is a function defined using async def. It uses Python coroutines and the explicit async/await syntax introduced in Python 3.5. Its programming model is based on cooperative multitasking and existing programming abstractions such as threads, sockets, files, subprocesses, locks, and queues. All sorts of cool constructs: AsyncThreads, UniversalQueues, async file I/O, Tasks, and more.

#5 Brian: Python Package src-ery

"Use the src, Luke" "To src, or not to src, that is the question"

Answering a listener question about Python packaging. In episode 15: Digging into Python Packaging, we mentioned to articles about getting started with packaging. In the comments, Kristof Claes noted that these references were in conflict with a couple of other references:

pytest “Good Integration Practices”, https://docs.pytest.org/en/latest/goodpractices.html ionel’s “Packaging a Python library”, https://blog.ionelmc.ro/2014/05/25/python-packaging/

Both of these strongly encourage the use of a “src” directory when setting up a package for distribution. There seems to be good reasons to use “src”. Many of the reasons are around the idea that during testing, you should be testing an installed version of the code. I have no reason to disagree with Ionel’s arguments and the pytest documentation recommendation.

However:

The pypa doesn’t bring this up when discussing distribution: https://packaging.python.org/distributing/ The pypa sample project doesn’t use “src”: https://github.com/pypa/sampleproject Many popular packages don’t: requests: https://github.com/kennethreitz/requests pytest itself: https://github.com/pytest-dev/pytest

Why not?

The pytest recommendation is subtle. It recommends using “src” if you need to include a dunder init file in the tests directory. Otherwise, the local code will be tested instead of the installed code, in part to test the installation and to test a library from the perspective of a user. pytest also recommends against having a top level dunder init in the tests directory. And this is a stronger recommendation. But Ionel’s points are not just around the use of pytest. So this is still really an open question to the Python community. If it’s great to use “src” instead of top level packages, why aren’t more projects doing this? Why doesn’t the PyPA mention it?

# 6 Michael: Intel Pulls Funding from OpenStack Effort It Founded With Rackspace

Intel and Rackspace were collaborating on a project called OpenStack Innovation Center Launched in July 2015. A source close to the effort said initial funding was supposed to last through 2018, but Intel pulled it early. A Rackspace spokeswoman said “OSIC’s objective was to create the world’s largest OpenStack developer cloud and develop enterprise capabilities within OpenStack. It quickly accomplished the first goal, and has made great progress toward the second.” Some 30 Rackspace employees who had been working at the innovation center have been given two weeks to find new jobs at the San Antonio-based company. Story here is we all need to think about funding projects and diversification.

Our news:

Michael: Hurry up and register for EuroPython: https://ep2017.europython.eu/en/ Earlybird sold out.

#21 Python has a new star framework for RESTful APIs

Apr 13, 2017 00:20:57

Description:

This episode has been sponsored by Rollbar. Get a special offer via http://rollbar.com/pythonbytes

#1 Brian: profile and pstats — Performance Analysis

Doug Hellman is working on the Python 3 MOTW series that was so successful for Python 2. Recent edition is profile and pstats, for profiling parts of your code you may have concerns with and finding out where the slow bits are.

#2 Michael: API Star by Tom Christie

A smart Web API framework, designed for Python 3. A few things to try right away: $ pip3 install apistar $ apistar new --template minimal $ apistar run $ apistar test API Star allows you to dynamically inject various information about the incoming request into your views using type annotation. e.g. def show_query_params(query_params: http.QueryParams): return { 'params': dict(query_params) } You can instead set the status code or headers by annotating the view as returning a Response def create_project() -> Response: ... Parameters are automatically passed into views from routes (annotations!): def echo_username(user_id: int): return {'message': f'Welcome, user {user_id}!'} Performance: Faster than sanic!

#3 Brian: Yes, Python is Slow, and I Don’t Care

Optimize for your most expensive resource. That’s YOU, not the computer. Choose a language/framework/architecture that helps you develop quickly (such as Python). Do not choose technologies simply because they are fast. When you do have performance issues: find your bottleneck Your bottleneck is most likely not CPU or Python itself. If Python is your bottleneck (you’ve already optimized algorithms/etc.), then move the hot-spot to Cython/C Go back to enjoying getting things done quickly

#4 Michael: A Quick Introduction: Hashing

Article by Gerald Nash Hashing is a method of determining the equivalence of two chunks of data. A cryptographic hash function is an irreversible function that generates a unique string for any set of data. Example import hashlib as hash sha = hash.sha256() # Insert the string we want to hash sha.update('Hello World!') # Print the hexadecimal format of the binary hash we just created print(sha.hexdigest()) # 4d3cf15aa67c88742e63918825f3c80f203f2bd59f399c81be4705a095c9fa0e Know when to choose “weak” hashes vs. strong ones Straight hashes are not enough for security (e.g. passwords). Use passlib and be done.

#5 Brian: Wedding at Scale: How I Used Twilio, Python and Google to Automate My Wedding

gspread to access a google spreadsheet of guests and phone numbers SMS guests with twilio replies handled by a flask app gathered accept/decline/didn't reply statistics reminder texts food selections and replies and reminders, all handled by Python

# 6 Michael: python-alexa: A Python framework for Alexa Development

by Neil Stewart Ordered an amazon assistant. Before it arrived, I had challenged myself to develop something for it Project: VoiceOps, interact with an AWS account, such as telling me how many running and stopped instances there is or what RDS databases are in an account Wanted a framework that would make Alexa development super easy. Decided a new framework was needed: python-alexa python-alexa on github echo shim for testing without hardware

Our news:

Michael: Just added full text search (including within videos) to Talk Python courses.

Brian: Netflix chaos engineering interview on Test & Code

#20 Finding similar but not identical images in 128 bits via Python

Apr 5, 2017 00:23:48

Description:

Sponsored by Rollbar, thank you! rollbar.com/pythonbytes

#1 Brian: Duplicate image detection with perceptual hashing in Python

Ben Hoyt From Jetsetter.com, Invitation-Only Travel Community We use a perceptual image hash called dHash (“difference hash”), which was developed by Neal Krawetz in his work on photo forensics. It’s a very simple but surprisingly effective algorithm that involves the following steps (to produce a 128-bit hash value) Convert the image to grayscale Downsize to a 9x9 square of gray values (or 17x17 for a larger, 512-bit hash) Calculate the “row hash”: for each row, move from left to right, and output a 1 bit if the next gray value is greater than or equal to the previous one, or a 0 bit if it’s less (each 9-pixel row produces 8 bits of output) Calculate the “column hash”: same as above, but for each column, move top to bottom Concatenate the two 64-bit values together to get the final 128-bit hash Fast: Python is not very fast at bit twiddling, but all the hard work of converting to grayscale and downsizing is done by a C library: ImageMagick+wand or PIL. Available via github: https://github.com/Jetsetter/pybktree

#2 Michael: Google Open Source/Python

subprocess32: A reliable subprocess module for Python 2 Grumpy: A Python to Go transcompiler and runtime Python Fire: Automatically turns any Python object or module into a command line interface (CLI) Python Client for Google Maps Services: Python client library for Google Maps API Web services Hyou: Pythonic Interface to manipulate Google Spreadsheet oauth2l: A simple CLI tool to get an OAuth token mock_maps_apis: Small AppEngine application that can mock some of the Google Maps APIs TensorFlow: TensorFlow is a fast, flexible, and scalable open source machine learning library

#3 Brian: How to Handle Missing Data with Python

Jason Brownlee Real-world data often has missing values. Data can have missing values for a number of reasons such as observations that were not recorded and data corruption. Handling missing data is important as many machine learning algorithms do not support data with missing values.

#4 Michael: hug REST framework

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 (locally, over HTTP, or through the command line) hug is the fastest and most modern way to create APIs on Python3 hug has been built from the ground up with performance in mind. It is built to consume resources only when necessary compiled with Cython to achieve amazing performance Built in version management Automatic documentation Annotation powered validation Write once. Use everywhere (CLI, Python package, Web API)

#5 Brian CLI with Click

I needed a cli interface that apparently fell into the “complex” category, because of subcommands, go figure. argparse ticked me off, so I tried click. It’s a joy to work with. http://click.pocoo.org/ https://realpython.com/blog/python/comparing-python-command-line-parsing-libraries-argparse-docopt-click/ - Just enough click tutorial to do exactly what I wanted. From 2015, realpython blog. (But argparse tutorial is a bit broken. in 3.5/3.6 😞 )

#6 Michael: Python's Instance, Class, and Static Methods Demystified

From realpython.com, guest post from Dan Bader demystify what’s behind class methods, static methods, and regular instance methods Python 3 by default class MyClass: def method(self): return 'instance method called', self @classmethod def classmethod(cls): return 'class method called', cls @staticmethod def staticmethod(): return 'static method called' Instances is clear but static and class are not so much static and class methods are also available on instances choice between class vs static method (do you want inheritance?) instance methods can also access the class itself through the self.__class__ attribute

Follow ups

David Bieber from Google and Python Fire sent us this note: The program noted that Fire has one "heavy" dependency, IPython. Just wanted to chime in with this: we have a game plan to remove IPython as a required dependency, but we're not there yet. (Contributions are welcome!)

pdir2 now supports color, https://github.com/laike9m/pdir2/wiki/User-Configuration. With the example given, I’ve added a .pdir2config file and changed doc-color to magenta, and I can see the doc lines in both a white and black terminal.

News from us

Brian

Python Testing with pytest book page has been spotted in the wild by Jakob Jarosz, https://twitter.com/qba73/status/848189279587229696. That was unexpected and cool to see.

Michael

Launched / launching two new courses at Talk Python Training Managing Python Dependencies with pip and Virtual Environments Using and Mastering Cookiecutter Course bundles now available: https://training.talkpython.fm/courses/all

#19 Put your Python dictionaries in a box and apparently Python is really wanted

Mar 27, 2017 00:19:37

Description:

#1 Brian: Better Exceptions and Python 3

reddit https://www.reddit.com/r/Python/comments/60scld/i_made_python_exceptions_a_little_better/ Qix (Josh), author of better_exceptions, https://github.com/Qix-/better-exceptions paradoxxxzero (Josh & Florian), author of https://github.com/Kozea/wdb also added a startup hook for better_exceptions, https://github.com/paradoxxxzero/better-exceptions-hook

#2 Michael: Stack Overflow 2017 Developer Survey Results

Python is #5 total usage Python is #1 most wanted Many excellent graphs, be sure to scroll through

#3 Brian: Box : Python dictionaries with recursive dot notation access

#4 Michael: Python 3.6.1 is released - Many small improvements and bug fixes.

#5 Brian: Essential Statistics for Data Science

#6 Michael: Hy: A wonderful dialect of Lisp that's embedded in Python

Since Hy transforms its Lisp code into the Python Abstract Syntax Tree, you have the whole beautiful world of Python at your fingertips, in Lisp form! Listener recommended: http://docs.hylang.org/en/latest/ You must try: https://try-hy.appspot.com/ This is pretty cool because it means Hy is several things: A Lisp that feels very Pythonic For Lispers, a great way to use Lisp’s crazy powers but in the wide world of Python’s libraries (why yes, you now can write a Django application in Lisp!) For Pythonistas, a great way to start exploring Lisp, from the comfort of Python! For everyone: a pleasant language that has a lot of neat ideas!

Follow up: Removal of beer from readme, pdir2 now looks great at default pypi

#18 Python 3 has some amazing types and you can now constructively insult your shell!

Mar 21, 2017 00:18:27

Description:

#1 Brian: pdir2

Nice use of animated gif to showcase what it does. It’s a replacement for dir() to use interactively. pip install pdir2 , but import pdir . pdir(something) gives you all that dir() does, but splits things into categories like exceptions, functions, attributes, … each item on one line, and includes the first line of the docstring for the item. Also, uses colors nicely. (Except I need to run it in a shell with non-black background on my mac or I can’t see the docstring output. ) Hugely useful if you use dir() interactively. 😞 Readme is in markdown, pypi still can’t handle that well. Maybe a listener can do a pull request on it to spiff up the pypi page: https://pypi.python.org/pypi/pdir2 Consider pairing this with ptpython

#2 Michael: How to recover lost Python source code if it's still resident in-memory

Ooops: I screwed up using git ("git checkout --" on the wrong file) and managed to delete the code I had just written, but it was still running in memory. Uses http://pyrasite.com/ Tools for injecting code into running Python processes https://github.com/rocky/python-uncompyle6/ A Python cross-version decompiler Main take-away: Really cool to attach pyrasite and explore a running Python process for many reasons.

#3 Brian: New Interesting Data Types in Python 3

types.MappingProxyType - acts like a dictionary, but it’s read only. Convenient for exposing a mutable data structure through an API and making it less convenient for the client code to modify things they aren’t supposed to. types.SimpleNamespace- kind of a general purpose class with attributes defined by the constructor parameters you pass in. May be useful in places where you would use collections.namedtuple . typ``ing.NamedTuple - You define a class derived from NamedTuple, and define attributes with types and optionally a default value. Constructor automatically assigns the attributes in order. These types help you to create quick small classes/types allow concise and readable code.

#4 Michael: howdoi

Instant coding and shell answers via the command line Examples howdoi print stack trace python howdoi connect sqlalchemy howdoi python save dict howdoi debug python howdoi install ohmyzsh howdoi change path macos Notable related https://github.com/nvbn/thefuck

#5 Brian: A python project from a listener of the show converts to asyncio and speeds up by 150x

Project is a Python interface to a commercial cloud based CRM called Emarsys. But the specifics are kinda beside the point. Comment from episode 17: http://disq.us/p/1h43lc0 From Diego Mora Cespedes

_Another awesome episode, thanks Michael and Brian!_

_About asyncio being awesome, I had my own experience. I had to send information about hundreds of thousands of users to a CRM through their public API daily. Without asyncio, it would have taken 50 hours daily, which we all know is just not possible! After developing a sync (using requests) and async (using aiohttp) client for their API, I managed to send the information about the users to the CRM asynchronously, and it takes... ... ... wait for it... ... ... 20 minutes!_

_So that's 150 times faster than without asyncio!_

_Anyway, if you wanna take a look at the client I open sourced, here is the link: https://github.com/transcovo/pymarsys_

_Oh yeah, fun fact: the first time I implemented the async functionality, I made too many API calls at the same time, my mac crashed and I think I DDoSed the CRM. Now I use semaphores, which allow you to limit the number of tasks you launch at the same time. So much Python awesomeness!_

However, I can’t find where in this code he uses semaphores, so here’s an example that does use semaphores to limit how many connections to make at a time. Making 1 million requests with python-aiohttp

#6 Michael: cookiecutter-pyramid-talk-python-starter

An opinionated Cookiecutter template for creating Pyramid web applications starting way further down the development chain. This cookiecutter template will create a new Pyramid web application with email, sqlalchemy, rollbar, and way more integrated.

Factored and organized: This code was generalized out of a large, professional web application Master layout template: Comes pre-configured with a master layout template. Navigation, CSS, JS, etc is factored into a single template file and is reused across all views Chameleon language: This template uses the chameleon template language (the cleanest template language for Python - we did say opinionated right?) Pyramid Handlers: Code is factored into handler / controller classes. You have the full power of object-oriented programming immediately available Secure user management: The app comes with full user management. Users can register, log in and out, and reset passwords. We use the passlib package for secure user storage using best practices SQLAlchemy data access: Comes with SQLAlchemy ORM preconfigured using sqlite Bootstrap and modern design: As you can see from the screenshot below, the app comes with bootstrap and fontawesome. It uses a free, open-source theme and images used under CC-Attribution. Logging with LogBook: A logging system for Python that replaces the standard library’s logging module. It was designed with both complex and simple applications in mind and the idea to make logging fun Runtime error monitoring with Rollbar: Rollbar adds runtime notifications and detailed error tracking and it comes pre-configured in this template Mailing list integration: Comes with Mailchimp integration. Just enter your API key and list ID to start collecting and managing users for your mailing list Outbound email with templates: The app has a set of static HTML files with placeholders that are loaded by the outbound email system and populated with user data Bower static resource management: Most templates are based on out-of-date files (css templates, js, etc.). This template is uses bower for it's static files. This means a single CLI command will get you the latest everything. Fast pages that are never stale: Every static resource is referenced with our own cache busting system. This means you can use extremely aggressive caching for performance on static files yet they immediately invalidate upon changes Comes with an entire online course: This template is built from the final project in Python for Entrepreneurs, a 20 hour course on building professional web apps in Python and Pyramid from Talk Python Training

#17 Google's Python is on fire and Simon says you have CPU load Pythonically

Mar 18, 2017 00:19:31

Description:

#1 Brian: python-fire

Suggested by several listeners Under the Google repo set on github but not a Google product. “Python Fire is a library for automatically generating command line interfaces (CLIs) from absolutely any Python object.”

Some Benefits as listed on the project page

a simple way to create a CLI in Python. a tool for exploring and debugging Python code. exploring existing code by turning other people's code into a CLI. makes transitioning between Bash and Python easier.

My take:

Enough documentation right in the github repo for me to try it out. Concise but thorough documentation, as well. I wouldn’t ship a CLI with this, as it’s too heavy. depends on ipython and six It would be useful to very quickly throw together a CLI to try out some Python code from bash. For internal development and debugging tools. I think this week I’m going to try to build a few CLI tools for directly sending and receiving commands to some test instruments.

#2 Michael: Simon: Simple macOS menubar system monitor, written in Python 3.6 + pyobjc

Shows how simple a menubar app can be Nice example of a platform-native Python app (we need more of these) Could use it as a starter app for your ideas on macOS

#3 Brian: Free Food A couple of amusing Reddit posts about free food.

Finding Free Food with Python Notification when friends order pizza

#4 Michael: HTTPie

Pronounced aitch-tee-tee-pie A command line HTTP client with an intuitive UI, JSON support, syntax highlighting, wget-like downloads, plugins, and more. A picture is worth many words, have a look: https://httpie.org/ Excellent support for JSON, XML, HTTP response headers, etc I spoke before about Postman as an API test client, this is the CLI version.

#5 Brian: pipdeptree

Sometimes when doing pip list I see way more packages than I remember installing. That’s due to dependent installs. pipdeptree is a simple command line tool that shows you your installed packages in an ascii tree structure so you can see who depends on. Example. arrow ? I don’t remember installing that. Ah. arrow is a dependency of jinja2-time ,which is a dependency of cookiecutter , that I do remember installing.

#6 Michael: Not Your Father’s Python: Amazing Powerful Frameworks

When we were getting SignifAI off the ground, one of the biggest decisions we had to make right at the beginning was what our stack would be. We know Python but… But it’s important to note that our product and infrastructure must support hundreds of thousands of events per second. So we were happy to see that, with the recent widespread adoption of Python 3 and the introduction of tasks and coroutines as first-class citizens in the language, Python has recently stepped up its game. Python 3 has continued evolving into a new wave of libraries that disrupt and change old assumptions about Python performance for web applications. Python’s GIL, is it a true roadblock? UVLoop is the first ultra-fast asynchronous framework, which is a drop-in replacement for Python 3.5’s built-in asyncio event loop. Both Japronto and Sanic which are reviewed in this post are also based on UVLoop. The future of Python is here: Overall, it looks like fast, asynchronous Python might be here to stay. Now that asyncio appears to be a default in Python and the async/await syntax has found favor among developers, the GIL doesn’t seem like such a roadblock anymore and speed doesn’t need to be a sacrifice. Comment: https://blog.signifai.io/not-your-fathers-python-amazing-powerful-frameworks/#comment-3193753282 Sasha Cuerda‏’s tweet: https://twitter.com/sashacuerda/status/839839014836453377 @mkennedy @brianokken Just used the aiohttp example you talked about to refactor a CLI scraper...went from > 8' to < 45". Blown away.

#16 Postmodern Python and Open-source Financial Awards

Mar 7, 2017 00:19:15

Description:

This is Python Bytes, Python headlines and news delivered directly to your earbuds: episode 16, recorded on March 6th, 2017.

This episode was brought to you by Rollbar: they help you take the pain out of errors.

#1 Brian: Postmodern Error Handling in Python 3.6

On "Journal Panic" An amusing look at error prevention Enum class usage NamedTuple class usage type hints mypy Bonus, another recent pretty darn good mypy walkthrough: Python Type Annotations

#2 Michael: Mozilla Awards $585,000 to Nine Open Source Projects in Q2 2016

One of the new tracks is “Mission Partners”, which supports any open source project which meaningfully advances the Mozilla mission. We had a large number of applications in the initial round, of which we have already funded eight (for a total of $385,000) and are still considering several more. Applications for “Mission Partners” remain open on an ongoing basis. The second is our “Secure Open Source” track, which works on improving the security of open source software by providing manual source code audits for important and widely-used pieces of free software. Our initial track, “Foundational Technology”, which supports projects that Mozilla already uses, integrates or deploys in our infrastructure, was launched late last year and remained open during this quarter. We made one additional award – to PyPy, the Python JIT compiler, for $200,000. Applications for a “Foundational Technology” award remain open.

#3 Brian: Intel Distribution for Python 2017 Update 2 accelerates five key areas for impressive performance gains

“Benchmarks for all these accelerations will be published soon. “ "..widespread optimizations for NumPy and SciPy FFT." "..performance may improve up to 60x over Update 1 and is now close to native C/Intel MKL." "Arithmetic and transcendental expressions" from NumPy can now useumath primitives which enables support for all available cores. Memory management optimizations Faster Machine Learning with Scikit-learn Looks like there is a free standalone version and a paid version. Supports Python 2.7 and 3.5. (When’s 3.6 coming, folks?) Supports Windows, Linux, OSX

#4 Michael: Async HTTP benchmarks on PyPy3

Thanks for the heads up Guy Fighel, @guyfig Since Mozilla announced funding, we've been working quite hard on delivering you a working Python 3.5. We are almost ready to release an alpha version of PyPy 3.5 Pyston faded and PyPy is surging. To show that the heart of Python 3 (asyncio) is already working we have prepared some benchmarks. HTTP workload on several asynchronous IO libraries, namely the relatively new asyncio and curio libraries and the battle-tested tornado, gevent and Twisted libraries The purpose of the presented benchmarks is showing that the upcoming PyPy release is already working with unmodified code that runs on CPython 3.5 Summary: 5-10x improvement across the board

#5 Brian: A tale of two exceptions, part 1, and part2

Ned Batchelder tried to get the coverage.py test suite to run on Jython. Jython doesn't have whatever coverage needs for the reporting part of coverage, so Ned went through some attempts to get the exceptions working ok and try to skip tests that required reporting. Headaches start and raise lots of design questions with a normal set of pragmatic decisions that have to be made. And following Ned's thought process is a cool look at problem solving. The first post ends with a solution that includes production code raising test exceptions. The second post replaces that with a solution that uses a metaclass to apply a decorator to each test function at object instantiation. The decorator looks for a custom exception and raises SkipTest.

#6 Michael: Asynchronous HTTP Requests in Python

If you’re familiar with the popular Python library requests you can consider aiohttp as the asynchronous version of requests. Usage is very similar to requests but the potential performance benefits are, in some cases, absolutely insane. Requests: It’s a fairly straightforward program and takes around 12 minutes of total time. aiohttp's ClientSession.get() and aiofiles: execution time is about 22 seconds, which in my opinion is a ridiculous performance boost (that’s 33x faster).

#15 Digging into Python packaging

Feb 28, 2017 00:16:04

Description:

This is Python Bytes, Python headlines and news delivered directly to your earbuds: episode 15, recorded on February 27, 2017.

#1 Brian: Packaging A Simple Guide for Python Packaging *by *Jie Feng, @flyfengjie

very simple bare bones example and tutorial When you create a ‘.py’ file, that is a module. One or more modules in a folder with add a __init__.py file is a package (named via the folder)

How To Package Your Python Code **by Scott Torborg, @storborg

The example from the previous article comes from this. The best mid level explanation I’ve run across so far to describe packaging and distribution. Read the whole thing in a very short time.

#2 Michael: elasticpypi by Kyle Hornberg

A mostly functional simple pypi service running on AWS. Runs over Elastic Search and AWS Lambda Compare to pypiserver: https://pypiserver.readthedocs.io/en/latest/ devpi: http://doc.devpi.net/latest/ pypiserver: https://pypi.python.org/pypi/pypiserver

#3 Brian: How to get Python new*s (our process)*

PythonBytes.fm, of course Twitter: Brian: https://twitter.com/brianokken Michael: https://twitter.com/mkennedy Talk Python: https://twitter.com/TalkPython Python Bytes: https://twitter.com/PythonBytes http://planetpython.org/, check out the titles only link, as well as reading this feed with Feedly or some other feed reader Newsletters: Awesome Python: https://python.libhunt.com/newsletter Python Weekly: http://www.PythonWeekly.com Pycoders Weekly: http://www.pycoders.com Import Python: http://importpython.com/newsletter/ Reddit: https://www.reddit.com/r/Python/ Python Trending on GitHub: https://github.com/trending?l=python

#4 Michael: Curio - The coroutine concurrency library, by David Beazley, @dabeaz

Curio is a library for performing concurrent I/O and common system programming tasks such as launching subprocesses and farming work out to thread and process pools. It uses Python coroutines and the explicit async/await syntax introduced in Python 3.5. Based on cooperative multitasking and existing programming abstractions such as threads, sockets, files, subprocesses, locks, and queues. Only works on POSIX systems The Big Question: Why? Python 3.4 and 3.5 have added major new paradigms for async programming.Curio takes full advantage of these features and is not encumbered by issues of backwards compatibility with legacy Python code written 15 years ago. Curio is a ground-up implementation that takes a different approach to the problem while relying upon known programming techniques involving sockets and files. The implementation of Curio aims to be simple. The API for using Curio aims to be intuitive.

#5 Brian: Pandas switching to use pytest as testing framework

Interesting look at the challenges and discussion of moving a large, highly visible project

#6 Michael: Talk Python #100: Python past, present, and future with Guido van Rossum

Excellent look back and forward with Guido Conversation on reddit Conversation on hackernews We touch on How he got started Early influences on Python Why Python succeeded How are we doing with: Diversity and moving to Python 3? His favorite features of Python 3 Converting legacy code via mypy: http://mypy-lang.org/

In other news (as in our news)

Test & Code 27 is out, a great talk with Mahmoud Hashemi on different levels of testing, the role of testing in SW development, TDD, and what he’s been up to lately. Test & Code migrating to testandcode.com, to separate writing and podcast into two sites. When it gets cleaned up a little, I’ll forward podcast related links from pythontesting to testandcode.

The pytest book got sent out to a few reviewers, and we have a title and some cover art options. It’s getting exciting. The rest of the reviewers will get the book when all chapters have gone through at least one editor iteration.

#14 Lots of Python style and Python 3000 is 3000 days old

Feb 22, 2017 00:15:39

Description:

Brian #1: Tiny Python 3.6 Notebook - Matt Harrison

README : https://github.com/mattharrison/Tiny-Python-3.6-Notebook/blob/master/README.md Full Book on GitHub : https://github.com/mattharrison/Tiny-Python-3.6-Notebook/blob/master/python.rst “This is not so much an instructional manual, but rather notes, tables, and examples for Python syntax.” Physical book is 134 pages, but looks like about 90 pages of content.

Michael #2: Oh no! This package is Python 2 only - Anthony Shaw

You’re head down, working on a new project and one of your dependencies still doesn’t support Python 3 - argh! Here’s a quick guide on how to solve that problem, step by step. Step 0: Check that nobody else has solved this Step 1: Fork it Step 2: Print statements Step 3: Tests Static Analysis: modernize Step 4: Update setup.py Step 5: Install it into your original project Step 6: Raise a pull request Step 7: 3 months later?

Brian #3: Elements of Python Style - Andrew Montalenti

More than PEP8, and opinionated. I admire the effort, and I may at some point fork it to remove/fix the few things I disagree with and to be able to use it as a style guide for my team. Great: most of it. Use parens for continuation Use with for files and locks May need tweaking Avoid custom exceptions I’d prefer, “Add one custom base exception, and build specific exceptions off of that”. This may be a controversial point, or I may be just confused about conventional practice here As with any style guide, more detail brings more controversy. Michael: I like this guidance: You can also choose to use CamelCase for things that are class-like but not quite classes -- the main benefit of CamelCase is calling attention to something as a "global noun", rather than a local label or a verb. Notice that Python names True, False, and None use CamelCase even though they are not classes.

Michael #4: Python 3 was exactly 3000 days old this past Sunday

Reddit post about my tweet (wow) 537 upvotes, 71 comments Test it yourself: background = “Python 3 was released December 3, 2008 ” + \ “Its original working name was Python 3000” release = datetime.date(year=2008, month=12, day=3) today = datetime.date(year=2017, month=2, day=19) (today - release).days # → 3000 Via @cclauss Christian Clauss

Brian #5: From beginner to pro: Python books, videos and resources

Bob Belderbos and Julian Sequeira Reddit thread: https://redd.it/5sjt3l Post: http://pybit.es/python-resources.html “a list of useful Python resources to boost up your skills” Some very nice podcasts listed in “other resources”

Michael #6: mongoaudit

mongoaudit is a CLI tool for auditing MongoDB servers, detecting poor security settings and performing automated penetration testing. pip install mongoaudit Tests things like: MongoDB listens on a port different to default one Server only accepts connections from whitelisted hosts / networks MongoDB HTTP status interface is not accessible on port 28017 MongoDB is not exposing its version number MongoDB version is newer than 2.4 TLS/SSL encryption is enabled Authentication is enabled SCRAM-SHA-1 authentication method is enabled Server-side Javascript is forbidden Roles granted to the user only permit CRUD operations The user has permissions over a single database Various security vulnerabilities From Michael: MongoDB is awesome. But please make sure at least one of the following is true. You only listen on local loopback (127.0.0.1) and run mongo on the web server You run mongodb with authentication enabled (it’s off by default) You run mongodb with SSL enabled (may be off by default too)

What else? Launched my course at https://bit.ly/python-rest-course

#13 Python making the move to GitHub and Dropbox is stepping back from Pyston

Feb 14, 2017 00:18:06

Description:

This is Python Bytes, Python headlines and news deliver directly to your earbuds: episode 13, recorded on February 13, 2017. In this episode we discuss Python making the move to GitHub and Dropbox stepping back from Pyston.

This episode was brought to you by Metis: The Data Science Bootcamp company.

#1 Brian:Pyston no longer sponsored by Dropbox

Personal follow up post by Kevin Modzelewski http://blog.kevmod.com/2017/02/personal-thoughts-about-pystons-outcome/

Pyston (pronounced piston) is a Python JIT implementation started at Dropbox It was based on CPython and supported a bunch of 2.7, but wasn’t complete. Bottom line: It’s open source, and the repo will be left for whoever wants to work on it. But the core developers from Dropbox won’t be working on it, and Dropbox won’t be spending any more time/money on it.

#2 Michael: CPython is coming to GitHub

Mailing list announcment: https://mail.python.org/pipermail/python-dev/2017-February/147341.html Reddit discussion https://www.reddit.com/r/Python/comments/5ssx9w/cpython_moves_to_github_this_friday/

Brett Cannon’s excellent background story: https://snarky.ca/the-history-behind-the-decision-to-move-python-to-github/

Interesting that some people (voiced via reddit) sadness about leaving Hg… 2006: Python moves to SVN 2011: Python moves to Hg 2017: Python moves to GitHub By 2014 it had become obvious to some of us that the Python development process had in fact become a burden. The rate at which patches were being submitted was much greater than the rate at which they were being reviewed. This was leading to external contributors getting frustrated because they would put in the effort to write a patch but would occasionally end up with waiting years for a review from a core developer. I wanted was the ability to review an external contribution -- from submission to commit -- all on a tablet while at a beach with WiFi (which I actually have in Vancouver so this wasn't entirely a silly request). My thinking was that if we got the process to be that simple, core developers could do a review at lunch time while at work, or when they had some down time at home without having to be on some special machine that had their SSH keys installed on it.

#3 Brian: Using functional programming in Python like a boss: Generators, Iterators and Decorators

I’m liking the trend of more Jupiter notebook based articles. This one is a pretty gentle introduction into functions, generators, iterators, decorators, containers, and how they all work together to make your code more expressive.

#4 Michael: It's metaclasses all the way down

What is metaprogramming? Metaprogramming is a technique of writing computer programs that can treat themselves as data, so you can introspect, generate, and/or modify them while running Metaclasses are deeper magic than 99% of users should ever worry about. If you wonder whether you need them, you don’t (Tim Peters) However: The potential uses for metaclasses are boundless. Some ideas that have been explored include logging, interface checking, automatic delegation, automatic property creation, proxies, frameworks, and automatic resource locking/synchronization. Nice examples: Django ORM models Abstract vehicle class

#5 Brian: Lambda Functions in Python: What Are They Good For?

Lambdas are part of the language, and if used sparingly and in the right context, can make your code more readable. It’s super important for intermediate and experienced Python folks to understand lambdas and not be afraid of them. This article is a good tutorial on them. When you finally grok them, you might be tempted to use them all over the place. Dan presents a couple of places where using lambdas is a bad choice: creating class methods. Definitions are definitely preferred over assigning lambdas to attributes. generating a list with list(fliter(<lambda expression>, <iterable>)) . I agree with Dan that comprehensions are way easier to read.

#6 Michael: Multi-threaded SQLite without the OperationalErrors

Unless you are very diligent about keeping your write transactions as short as possible, you can easily wind up with one thread accidentally holding a write transaction open for an unnecessarily long time. I've had success using a very simple approach: I eliminate the possibility of lock contention by dedicating one thread to the task of issuing all writes for the application. The entire source listing can be found here, if you're curious: https://github.com/coleifer/peewee/blob/master/playhouse/sqliteq.py

Followup: Japronto not production ready: “Japronto author here: As stated in the README you should not build anything serious with Japronto now because it's gonna probably eat your laundry. Remember it's hand coded in C and this needs a lot of testing. On the top of that I plan to do several iterations of API changes in a largely incompatible ways. I hope though it's gonna make a serious player in the field one day.

If you wanna a decent async framework then go with aiohttp or Sanic. If you are gonna do typical REST app frontend to a database go with Flask or Pyramid. If you need a scaffolded admin go with Django.”

#12 Expanding your Python mental model and serving millions of requests per second with Python

Feb 7, 2017 00:19:04

Description:

This is Python Bytes, Python headlines and news deliver directly to your earbuds: episode 12, recorded on February 6th, 2017. In this episode we discuss expanding your Python mental model and serving millions of requests per second with Python.

This episode was brought to you by Rollbar: they help you take the pain out of errors.

BO 1: A couple of mental model articles

Python Functions aren’t what you think. http://powerfulpython.com/blog/python-functions-arent-what-you-think/ Functions are objects. The name of a function is just a variable name referring to the object. The Tao of Python http://nbviewer.jupyter.org/github/akittas/presentations/blob/master/pythess/tao_mro/tao_of_python.ipynb Jupiter notebook discussion of the relationship between objects, classes, and metaclasses.

Michael #2: Why Learn Python? Here Are 8 Data-Driven Reasons by Dan Bader

Is Python worth learning? We’ve interviewed experts and surveyed the job market to identify the key reasons why you should learn Python today. Python is also one of the hottest skills to have according to research by Dice The 2nd most popular programming language in the world based on the PYPL Popularity of Programming Language Index. You Can Use Python for Pretty Much Anything Python Is Widely Used in Data Science Python Pays Well: Indeed’s salary calculator gives an even larger figure—a whopping $116,000 per year. (second only to ruby according to gooroo but has 3 times the job openings) Demand for Python Developers Is High (And Growing) Python Saves Time Python Is Beginner Friendly All the Big Names Use Python Python could be your way into major tech companies: YouTube, IBM, Yahoo, Dropbox, Quora, Mozilla, Instagram, and many others Python Has an Amazing Ecosystem Segments from: Michael Kennedy, Ankur Gupta (Curator at ImportPython), and Sebastian Vetter (Python Engineer at Eventbase)

B*rian #*3: Testing Python Applications with Pytest - Kevin Ndung’u How could I resist? Do a decent job explaining something about pytest, and I’m happy. What I liked:

good really fast intro to pytest extreme basics Refactoring test code with fixtures. Pulling out common starting state into a fixture. Paramterizing tests to send multiple data sets into the same test function Using both fixtures and paratmerization in the same test function

There’s so much power and functionality in pytest. But just starting to use it as a better test framework for Python is a good thing. This article is a good kick in the pants for someone new to pytest. Easy intro, plus a couple of cool goodies.

Michael #4: A million requests per second with Python

Screaming-fast Python 3.5+ web micro-framework integrated with pipelining HTTP server based on uvloop and picohttpparser. We spoke about sanic recently. Apparently this is much faster. https://github.com/squeaky-pl/japronto 2.6k stars Is it possible to hit a million requests per second with Python? Probably not until recently. Covers perf improvements found in 3.6 and coming in 3.7. It lets you do both synchronous and asynchronous programming thanks to asyncio. And it’s shamelessly fast. Even faster than NodeJS and Go. Japronto tries hard to delay creation of Python counterparts of its internal structures until asked explicitly. For example, a headers dictionary won’t be created until it’s requested in a view.

Brian#5: RethinkDB is alive and well

RethinkDB joins The Linux Foundation https://rethinkdb.com/blog/rethinkdb-joins-linux-foundation/ The liberation of RethinkDB https://www.joyent.com/blog/the-liberation-of-rethinkdb Company behind RethinkDB shut down Sept 2016 Announced today that Cloud Native Computing Foundation purchased the rights to source code and contributed it to the Linux Foundation under Apache license ASLv2. Website, GitHub org, social media accounts will continue to operate. They can take donations, and stripe has ponied up 25k in donation matching.

Michael #6: Python Top 10 Articles for the Past Year (v.2017)

The Hitchhiker’s Guide to Python: Best practices guidebook written for Humans. Scipy Lecture Notes — Learn numerics, science, and data with Python. 30 Essential Python Tips and Tricks for Programmers. Computational and Inferential Thinking for Data Science. Courtesy of UC Berkeley Welcome to Python cheatsheet. Data Mining in Python: A Guide. Python FAQ: Why should I use Python 3? (by eevee) An Introduction to Stock Market Data Analysis with Python NumPy Tutorial: Data analysis with Python. Build Your First Python and Django Application

Michael: Follow up on RHL: Red Hat Software Collections Thank you Chip Warden

The latest, stable updates of development technologies for Red Hat Enterprise Linux Add latest for: Node Perl PHP Python [YES! Python 3] Ruby

#11 Django 2.0 is dropping Python 2 entirely, pipenv for profile functionality, and Pythonic home automation

Jan 31, 2017 00:20:55

Description:

This is Python Bytes, Python headlines and news deliver directly to your earbuds: episode 11, recorded on January 30th, 2017.

#1 (Brian) pipenv - Pipfile, pip, and virtualenv

announcement from Kenneth Reitz reddit thread Features Automatically finds your project home, recursively, by looking for a Pipfile. Automatically generates a Pipfile, if one doesn't exist. Automatically generates a Pipfile.lock, if one doesn't exist. Automatically creates a virtualenv in a standard location (project/.venv). Automatically adds packages to a Pipfile when they are installed. Automatically removes packages from a Pipfile when they are un-installed. Also automatically updates pip.

#2 (Michael): Django 2.0 is dropping support for legacy Python

Django changing docs to default to Python 3 The next release, Django 1.11, will be a long-term support release, and the one after that, Django 2.0, will no longer support Python 2.

#3 (Brian) attrs

Hynek Schlawack pypi: https://pypi.python.org/pypi/attrs readthedocs: https://attrs.readthedocs.io/en/stable/overview.html I know this has been around for a while. But I’ve just stumbled across it while reading a blog post about requests, which was good, but we’ve covered requests a lot lately, so I’m gonna skip that article today. pip install attrs, with an s, even though you import without the s Does all of the grunt work of writing dunder functions for you so you can write classes with a small amount of code that behave like classes and objects should. Especially if you come from a C++ background, this makes writing classes more intuitive.

#4 (Michael): Go faster Python

This blog post gives an introduction to some techniques for benchmarking, profiling and optimising Python code. If you have a Python program that’s running slowly, what are your options? Benchmarking and profiling Our intuition is often wrong Benchmarking: %time, %timeit, timeit Function profiling: %prun, cProfile Line profiling: %lprun, line_profiler (requires line_profiler) Cython

#5 (Brian): Getting Python 3 into distributions

Not an article but a couple of pleas. Many OS distributions, including Red Hat, ship with Python 2.7. Many developers don’t have the authority to install Python 3.x for projects. Two pleas: distributions: ship with both if you have to, but let 3.6 be an option for people. companies: install Python 3.6 and let some projects use that We can’t just encourage users to switch to Python 3 if it’s not their choice.

#6 (Michael) Home Assistant

Home Assistant is an open-source home automation platform running on Python 3. Track and control all devices at home and automate control Installation in less than a minute. Observe: Track the state of all the devices in your home, so you don't have to. Control: All your devices from a single, mobile-friendly, interface. Automate: Setup advanced rules to control devices and bring your home alive. have the lights turn on when the sun sets and you are home? have the lights turn on when anyone comes home and it is dark? dim the lights when you start watching a movie on your Chromecast? receive a message when the lights turn on while you are not at home? Demo: https://home-assistant.io/demo/ aiohttp: Asynchronous HTTP Client/Server

#10 Dismissing Python's Garbage Collection, PyPI Name Reservations, and Hackers Exfiltrate US Government Data to Save Itself

Jan 23, 2017 00:25:45

Description:

This is Python Bytes, Python headlines and news deliver directly to your earbuds: episode 10, recorded on Monday, January 23rd, 2016.

#1 (Brian): Advanced Time Series Plots in Python from blackarbs.com

matplotlib 2.0 official release on Jan 17 mentioned it was coming in episode 7 matplotlib.org A tutorial for using pandas, numpy, matplotlib, and seaborn for collecting, analyzing, and plotting time series plots. start with an empty xy chart grab some yahoo finance data, do some manipulation, and plot it. add shaded areas, in the example, recession times chart titles axis labels legend styling horizontal line, at the 0 value, in this example formatting x and y tick labels controlling the font turning on data points by specifying a marker shape add some chart annotations with arrows pointing to specific data points add a logo and watermark over the top of everything seaborn is a statistical data visualization tool for use with matplotlib See the seaborn site has tutorials for: Style functions, Color palettes, Distribution plots, Regression plots, Categorical plots, and Axis grid objects.

#2 (Michael): Dismissing Python Garbage Collection at Instagram

By dismissing the Python garbage collection (GC) mechanism, which reclaims memory by collecting and freeing unused data, Instagram can run 10% more efficiently. How We Run Our Web Server: Instagram’s web server runs on Django in a multi-process mode with a master process that forks itself to create dozens of worker processes that take incoming user requests. For the application server, we use uWSGI with pre-fork mode to leverage memory sharing between master and worker processes. Attempt 1: Disable reference count on code objects (no effect) Attempt 2: Let’s try disabling GC With that, we successfully raised the shared memory of each worker process from 140MB to 225MB, and the total memory usage on the host dropped by 8GB per machine. This saved 25% RAM for the whole Django fleet. With such big head room, we're capable of running a lot more processes or running with a much higher RSS memory threshold. In effect, this improves the throughput of Django tier by more than 10%. Attempt 3: Completely shutdown GC takes churns (bad) Attempt 4: Final step for shutting down GC: No cleanup (success)

#3 (Brian): My experience with type hints and mypy

Brett Cannon on his blog snarky.ca

Here's an example including the pull request of changes, of a project adding static types and static analysis of those types. Trying to use type hints to increase code quality and readability for a project. The project is CLA enforcement bot for the PSF, to make sure that all pull requests contributions to a python project is done by someone who has signed a PSF Contributor Licence Agreement. Process Run mypy against your code with no types, then slowly add types, one object at a time. mypy is a static analysis tool to make sure your typehints are correct. Issues: supports Python 3.5, but not new types in Python 3.6, specifically typying. Collection. Workaround was to use typing.AbstractSet f-strings not supported yet, but coming Skipped type hinting for test suite. It wouldn't occur to me to even try to add static types to tests. Most linters would have caught the problems as well as mypy. Benefit The act of adding static types increased the readability of the code. Did not detract from readability. “What mypy really got me was better documentation. While I was adding the type hints there were a couple of times where I had to examine the code to realize what the appropriate type was. Now that I have the functions and methods all hinted I don't have to guess anymore. That should make long-term maintenance a bit easier” Conclusion "…would I bother typing new Python 3 code? … yes once mypy supports f-strings. “When I design an API I already have to think about what type of objects would be acceptable, so quickly writing down my assumptions doesn't hurt anything, it's relatively quick, and it benefits anyone having to work with my code. But I also wouldn't contort my code to fit within the confines of type hints (i.e. if type hints forces me to write cleaner code then that's great, but if something is so dynamic that it can't have type hints then that's fine and I'll happily use typing.Any as an escape hatch). “ “In the end I view type hints as enhanced documentation that has tooling to help verify that the documentation about types is accurate. And for that use-case I see type hints worth doing and not at all a burden.”

#4 (Michael): Understanding the underscore( _ ) of Python

The underscore (_) is special in Python. If you are python programmer, for _ in range(10) , __init__(self) like syntax may be familiar. There are 5 cases for using the underscore in Python. For storing the value of last expression in interpreter. For ignoring the specific values. (so-called “I don’t care”) To give special meanings and functions to name of vartiables or functions. _protected-ish, __private-ish, conflicting: in_, __magic__ To use as ‘Internationalization(i18n)’ or ‘Localization(l10n)’ functions. To separate the digits of number literal value.

#5: (Brian): PEP 541 -- Package Index Name Retention Draft status currently; was just submitted on the 12th by Donald Stufft. “ Abstract: This PEP proposes an extension to the Terms of Use of the Package Index, clarifying expectations of package owners regarding ownership of a package name on the Package Index, specifically with regards to conflict resolution.

Existing package repositories such as CPAN , NPM , and GitHub will be investigated as prior art in this field.

Rationale Given that package names on the Index are sharing a single flat namespace, a unique name is a finite resource. The growing age of the Package Index causes a constant rise of situations of conflict between the current use of the name and a different suggested use of the same name.

This document aims to provide general guidelines for solving the most typical cases of such conflicts.”

#6 (Michael): Hackers downloaded US government climate data and stored it on European servers as Trump was being inaugurated

As Donald Trump was sworn into office as the new president of the US on Jan. 20, a group of around 60 programmers and scientists were gathered in the Department of Information Studies building at the University of California-Los Angeles, harvesting government data. A spreadsheet detailed their targets: Webpages dedicated to the Department of Energy’s solar power initiative Energy Information Administration data sets that compared fossil fuels to renewable energy sources fuel cell research from the National Renewable Energy Laboratory, to name a few out of hundreds. Volunteer “data rescue” events in Toronto, Philadelphia, Chicago, Indianapolis, and Michigan over the last few weeks have managed to scrape hundreds of thousands of pages off of EPA.gov, NASA.gov, DOE.gov, and whitehouse.gov, uploading them to the Internet Archive. Another is planned for early February at New York University. Suddenly, at exactly noon on Friday as Trump was sworn in, and just as the UCLA event kicked off, some of their fears began to come true: The climate change-related pages on whitehouse.gov disappeared. There will, thanks to Michael Riedyk, CEO of the Canadian data-archiving company Page Freezer, also be a copy stored outside the US.

#9 Walking with async coroutines, diving deep into requests, and a universe of options (for AIs)

Jan 17, 2017 00:23:39

Description:

This is Python Bytes, Python headlines and news deliver directly to your earbuds: episode 9, recorded on Tuesday, January 17th. In this episode we discuss walking with async coroutines, diving deep into requests, and a universe of options (for AIs).

#1 (Brian): Python Asynchronous I/O Walkthrough

In July, there was an open source book published called 500 Lines or Less. One of the chapters was called A Web Crawler With asyncio Coroutines, written by A. Jesse Jiryu Davis and Guido van Rossum. It explains async networking, showing how non-blocking sockets work and how Python 3’s coroutines improve asynchronous network programs. As mentioned recently on A. Jesse Jiryu Davis’s blog emptysqua.re, the chapter may be difficult for a novice or intermediate developer to follow. This month, Philip Guo, an Assistant Professor at UC San Diego, has released an 8 part video series, 90 minutes total, so on the order of 10 minutes each, that walks through the article, including some coding examples that he walks through. Since async is something that takes a while to get your head around, I appreciate the multi-sensory education experience. Listening to Philip talk about it, watching him walk through the code and talk about the article, and having the article as a reference, is super helpful. Talk Python #22: CPython Internals and Learning Python with pythontutor.com Talk Python #69: Write an Excellent Programming Blog

#2 (Michael): 4 likely future twists for Python by Serdar Yegulalp

Python 2.x may live on

Python 2.x might also get a continued lease on life if independent developers decide to keep the branch going on their own. At least one such effort exists -- Naftali Harris's "Python 2.8" project, which backports improvements and bug fixes from Python 3 into the Python 2.x branch. it makes sense to make the 3.x leap, but it's likely we'll see a lot of keep-the-2.x-flame-alive efforts

Requirements.txt may be replaced with something better

Pipfile has been proposed as a possible replacement by the folks at the Python Packaging Authority, which is "the working group that maintains many of the relevant projects in Python packaging." Pipfile will be superior to requirements.txt file in a number of ways: 1. TOML syntax for declaring all types of Python dependencies. 2. One Pipfile (as opposed to multiple requirements.txt files). 3. Existing requirements files tend to proliferate into multiple files - e.g. dev-requirements.txt, test-requirements.txt, etc. - but a Pipfile will allow seamlessly specifying groups of dependencies in one place. 4. This will be surfaced as only two built-in groups (default & development). (see note below) 5. Fully specified (and deterministic) environments in the form of Pipfile.freeze. A deployed application can then be completely redeployed with the same exact versions of all recursive dependencies, by referencing the Pipfile.freeze file.

Example pipfile:

[[source]] url = 'https://pypi.org/' verify_ssl = true

[requires] python_version = '2.7'

[packages] requests = { extras = ['socks'] } Django = '>1.10' pinax = { git = 'git://github.com/pinax/pinax.git', ref = '1.4', editable = true }

[dev-packages] nose = '*'

Python could get more enterprise editions

As the language has gained traction across the board, it's also appearing in versions aimed specifically at solving enterprise-grade problems. Intel, for instance, elected to repackage the Anaconda science-and-math distribution of Python after outfitting it with extensions that give it a speed boost, albeit only on Intel processors. Anaconda is itself produced by Continuum Analytics, no stranger to enterprise data-analysis needs. Python's new software repository system could lead to enterprise-friendly Python package management One possibility being floated in this vein is the concept of an enterprise-grade package index for Python, as discussed by Cristian Medina of Nimble Storage: Businesses always have a need for an on-premises, secure, encrypted and highly available distribution mechanism of compiled binaries. Together with setuptools providing various install capabilities that can cover non-Python code just as well, it seems like we could put together a decent product. Something like a Docker Trusted Registry. I’m working on something here too that come out of the discussion of Talk Python #84

#3 (Brian) From Python to Numpy

Nicolas P. Rougier - labri.fr “Nicolas P. Rougier is a full-time research scientist at Inria which is the French national institute for research in computer science and control.” Creative commons book for people who are intermediate level Python developers and want to use numpy for science or engineering.

#4 (Michael): openai/universe

Universe: a software platform for measuring and training an AI's general intelligence across the world's supply of games, websites and other applications. https://universe.openai.com Universe allows anyone to train and evaluate AI agents on an extremely wide range of real-time, complex environments. Universe makes it possible for any existing program to become an OpenAI Gym environment, without needing special access to the program's internals, source code, or APIs. It does this by packaging the program into a Docker container presenting the AI with the same interface a human uses: sending keyboard mouse events receiving screen pixels Our initial release contains over 1,000 environments in which an AI agent can take actions and gather observations.

#5: (Brian): Python requests deep dive

Anthony Shaw - on medium.com Converted a large project from httplib to requests Apache Libcloud needed to provide a set of base classes that would handle HTTP and HTTPS REST/JSON, REST/XML and various other bizarre HTTP APIs. Libcloud has over 80 client libraries for every major cloud service out there. single Connection class that handles encoding and decoding of JSON, XML or Raw data. Anthony walks through the types of changes made, including authentication, session handling, testing, prepared requests, streams, … uses requests-mock very cool API

#6 (Michael): What's the community favorite for developing OSX desktop applications with Python?

bangeron: I've been using PyQt for all my projects with a GUI: - It has a native look and feel - It's cross-platform (I do everything on macOS) - It's a whole framework, including modules for plotting charts, networking, SQL, etc. - It has excellent documentation. - It has a GUI editor (Qt Creator) that is pretty good, once you figure it out. Omnius: Same but using pyside to avoid license fees. spinwizard69: Use TK for simple apps! It is included with Python and avoids dependency hell. EssaAlshammri: Take a look at Toga its idea is great. Ruditorres: Kivy hands down, it is pythonic, easy, and beautiful bangeron: Kivy is anything but beautiful. At least, not without spending some time creating your own theme. Personally, I want py_electron (modeled after electronjs). Notable mention, related: cx_Freeze released (Version 5.0.1 (January 2017))

#8 Python gets Grumpy, avoiding burnout, Postman for API testing and more

Jan 10, 2017 00:20:48

Description:

This is Python Bytes, Python headlines and news deliver directly to your earbuds: episode 8, recorded on January 10th, 2017. In this episode we discuss Python is Grumpy, avoiding burnout, Postman for API testing and more.

#1 (Brian): Jessica McKellar, "Breaking The Rules", PyBay2016

Jessica was directory of PSF for several years, was involved with Boston Python UG, is diversity chair for PyCon, is an engineering director at dropbox Powerful keynote Her extra work with Python is not about Python, it’s about studying systems. “Learning how to program changes the way you think about, debug, and interact with the world” “You learn a set of rules to build software, … then you learn that you can change the rules.” “Programmers master a system they know they can change.” “This comes from the tenets of free software.” “We take for granted that changing something to make it better is just a thing you do when you need to.” This can and should carry over to the rest of your life. Jessica takes this idea and applies it to politics, voting, and polling stations, and ran a polling station herself. That’s pretty incredible. About half the time is Q&A with some great questions. Listen to this talk and apply it to every part of your work and life.

#2 (Michael): Grumpy is a Python to Go

By Dylan Trotter from YouTube Grumpy is a Python to Go source code transcompiler and runtime. intended to be a near drop in replacement for CPython 2.7 The key difference is that it compiles Python source code to Go source code which is then compiled to native code, rather than to bytecode. This means that Grumpy has no VM. 6,000 stars on Github in 3 weeks Look for him on Talk Python To Me (episode 95?)

#3 (Brian): Finding dead code with Vulture - Dougal Mathews

pip install vulture , then vulture some/directory/of/code Reports unused code. vs coverage.py. You can get similar information from coverage if your test suite or the code you run during the coverage inspection is fairly complete. However, what if a unit test is the only thing calling some function? vulture allows you to exclude your test code when looking for unused code. vs static analyzers like flake8. With some of my own code that I have in progress, vulture found the same stuff that flake8 did. However, if you are only looking for dead code, it’s easier to find with vulture if you have other flake8 violations. Also some folks don’t like style checkers. I’d like to hear what other people think. But I like the idea of having a focused dead code tool. And vulture is a great name for such a tool.

#4 (Michael): Postman: Developing APIs is hard. Postman makes it easy

A powerful GUI platform to make your API development faster & easier, from building API requests through testing, documentation and sharing. Cross platform and free A simple and effective way to share details about your public-facing API Testing Run Postman Collections directly from the command line integrating with continuous integration servers and builds Monitor uptime, performance and correctness of your APIs. Notable mention goes to paw.cloud (macOS only)

#5 (Brian): The Reality of Developer Burnout by Kenneth Reitz

Author of Requests and of Maya (datetime for humans), covered in the last episode. This is an article about getting overwhelmed as a maintainer of an open source project. But applies to anyone supporting a tool, even for your coworkers. And really applicable to all sorts of developer burnout. Advice: Keep producing, but stop consuming so much on social networks. twitter, reddit, etc. Delegate more. Have hobbies other than coding side note: On the maya github page, I noticed a link saythanks.io, a Kenneth project where you can set up a way for people to just send you a thank-you note. I think this is cool. I wrote about the power of “thank you” a few years ago. It’s really important in open source, and really all the time.

#6 (Michael): Jinja 2.9 Released by Armin Ronacher

From Hugh Blandford (thanks!) New release, 2.9 codename "Derivation" of the Jinja template engine for Python is out While Jinja2 supported Python 3 for years now it never really embraced functionality that the language provides on 3.x that it does not do on 2.x However 3.6 now added async generators which permits Jinja2 to fully support the async and await keywords on 3.6 and later. In particular it means that you can now return coroutines from functions passed to Jinja2 templates and the template engine will automatically await them. Likewise all filters were updated to work with iterators as well as async iterators alike.

#7 Python 3.6 is out, Sanic is a blazing web framework, and are failing our open source infrastructure?

Jan 4, 2017 00:21:13

Description:

This is Python Bytes, Python headlines and news deliver directly to your earbuds: episode 7, recorded on Wednesday, January 4th.

In this episode we discuss Python 3.6 being release, a blazing Python web framework called Sanic, how we are failing our open source infrastructure, and more.

This episode was brought to you by Rollbar: they help you take the pain out of errors.

#1 (Brian): Python 3.6 is officially released

Dec 23 Announcement on blog.python.org: http://blog.python.org/2016/12/python-360-is-now-available.html What’s new article on docs.python.org: https://docs.python.org/3.6/whatsnew/3.6.html

Here’s a few more articles:

Python 3.6 is packed with goodness - Serdar Yegulalp - InfoWorld http://www.infoworld.com/article/3149782/application-development/python-36-is-packed-with-goodness.html A list of cool things in Python 3.6 async/await in more places Improved memory usage and speed frame evaluation API to provide better support for JITs, tracers, debuggers secrets module for common security-related functions such as generating tokens One thing that could stop a team from switching to Python 3 would be that they looked into it once, and a package they needed was not ported yet. That’s different now, most are ported, or have been replaced with some other way. Adopt Python 3 - Dibya Chakravorty - on Medium https://medium.com/broken-window/python-3-support-for-third-party-libraries-dcd7a156e5bd A discussion of packages that support Python 2 and 3, those that are 2 only, those that are 3 only. Two lists of most downloaded packages and their py3 readiness: Wall of superpowers: http://python3wos.appspot.com/, 187/200 = 93.5% Python 3 readiness: http://py3readiness.org/, 341/360 = 94.7% Go further: all pypi packages that are stable and active (at least one release in 2016), about 6000 packages total python 3 coverage is 72% 14% are Python 3 only 28% are Python 2 only of the 28%, author estimates only 25% of the remaining packages would be difficult to port, based on their size, and included that list. Also entire code for this article is in an iPython notebook:https://github.com/gutfeeling/pypi_explorer/blob/master/pypi_database/analysis.ipynb

#2 (Michael) Roads and Bridges: The Unseen Labor Behind Our Digital Infrastructure by Nadia Eghbal http://www.fordfoundation.org/library/reports-and-studies/roads-and-bridges-the-unseen-labor-behind-our-digital-infrastructure

From The Ford Foundation, 14 JULY 2016 Features Eric Holscher from Read the Docs & Donald Stufft from PyPI Discussed on Talk Python episode #84: Are we failing to fund Python's core infrastructure? Some highlights from the 149 page report: Our modern society—everything from hospitals to stock markets to newspapers to social media—runs on software. But take a closer look, and you’ll find that the tools we use to build software are buckling under demand. (roads-and-bridges-the-unseen-labor-behind-our-digital-infrastructure, p.4) No individual company or organization is incentivized to address the problem alone, because open source code is a public good. (roads-and-bridges-the-unseen-labor-behind-our-digital-infrastructure, p.9) By 2014, two-thirds of all Web servers were using OpenSSL, enabling websites to securely pass credit card and other sensitive information over the Internet. (roads-and-bridges-the-unseen-labor-behind-our-digital-infrastructure, p.11) Institutional efforts to support digital infrastructure: There are some institutional efforts to collectively organize and help support open source projects. Some are independent software foundations; other sources of support come from software companies themselves. Administrative support and fiscal sponsorship Several foundations provide organizational support, such as fiscal sponsorship, to open source projects: in other words, taking care of the non-coding tasks that many developers would prefer not to do (roads-and-bridges-the-unseen-labor-behind-our-digital-infrastructure, p.109) Of Heartbleed, Marquess wrote, “The mystery is not that a few over-worked volunteers missed this bug; the mystery is why it hasn’t happened more often.” (roads-and-bridges-the-unseen-labor-behind-our-digital-infrastructure, p.13) Heartbleed, had been included in a 2011 update. It had gone unnoticed for years. Heartbleed could allow any sophisticated hacker to capture secure information being passed to vulnerable web servers, including passwords, credit card information, and other sensitive data (roads-and-bridges-the-unseen-labor-behind-our-digital-infrastructure, p.13) People expressed their support by sending donations to the foundation. Although Marquess was grateful for their enthusiasm, the first round of donations came out to roughly $9,000: not nearly enough to sustain a team. (roads-and-bridges-the-unseen-labor-behind-our-digital-infrastructure, p.13) After Heartbleed, OpenSSL finally got more of the funding it needed—at least for now. They currently have enough money to pay four full-time employees for three years. But a year and a half into that funding, Marquess isn’t sure what will come next. (roads-and-bridges-the-unseen-labor-behind-our-digital-infrastructure, p.14) Free software makes it exponentially cheaper and easier to build software (roads-and-bridges-the-unseen-labor-behind-our-digital-infrastructure, p.23) Free software is directly responsible for today’s current startup renaissance (roads-and-bridges-the-unseen-labor-behind-our-digital-infrastructure, p.24) Software not getting the necessary maintenance it needs Building digital infrastructure in a haphazard fashion means that all software gets built more slowly and inefficiently. One example of this can be found in the history of Python infrastructure. An important infrastructure project for Python developers is called setuptools. (roads-and-bridges-the-unseen-labor-behind-our-digital-infrastructure, p.80)

#3 (Brian): Matplotlib 2.0.0 rc2 was released by Thomas Caswell

install instructions: http://matplotlib.org/style_changes.html List of top level changes in release history on github -https://github.com/matplotlib/matplotlib/releases Changes to the default style - matplotlib.org http://matplotlib.org/2.0.0rc2/users/dflt_style_changes.html Post visually shows all of the new changes. What’s new in matplotlib 2.0 - also on http://matplotlib.org http://matplotlib.org/2.0.0rc2/users/whats_new.html

#4 (Michael) Introduction to MongoDB and Python https://realpython.com/blog/python/introduction-to-mongodb-and-python/

SQL vs NoSQL PyMongo Inserting and querying data MongoEngine Classes Constraints OOP Michael’s 1.5 hour presentation at Software Architect conference in London: Applied NoSQL with MongoDB and Python

#5: (Brian): Introducing Maya: Datetimes for Humans https://www.kennethreitz.org/essays/introducing-maya-datetimes-for-humans - Working with dates is harder than it should be. Kenneth has proven that he understands how to make reasonable interfaces to hide complicated things.

From "why is this useful?" section

All timezone algebra will behave identically on all machines, regardless of system locale. Complete symmetric import and export of both ISO 8601 and RFC 2822 datetime stamps. Fantastic parsing of both dates written for/by humans and machines (maya.when() vs. maya.parse()). Support for human slang, both import and export (e.g. 'an hour ago'). Datetimes can very easily be generated, with our without timezone information attached (naive). This library is based around epoch time, but dates before Jan 1 1970 are indeed supported, via negative integers.

#6 (Michael): Sanic: Python 3.5+ web server that's written to go fast https://github.com/channelcat/sanic

Sanic is a Flask-like Python 3.5+ web server that's written to go fast. It's based on the work done by the amazing folks at magicstack, and was inspired by this article: https://magic.io/blog/uvloop-blazing-fast-python-networking/. On top of being Flask-like, Sanic supports async request handlers. This means you can use the new shiny async/await syntax from Python 3.5, making your code non-blocking and speedy.

A basic action method

@app.route("/") async def test(request): # async def !!! return json({ "hello": "world" })

Performance numbers

Server Implementation Requests/sec Avg Latency Sanic Python 3.5 + uvloop 33,342 2.96ms Bottle gunicorn + meinheld 13,596 7.36ms Flask gunicorn + meinheld 4,988 20.08ms Aiohttp Python 3.5 + uvloop 2,979 33.42ms Tornado Python 3.5 2,138 46.66ms

#6 Python 3.6 is going to be awesome, Kite: your friendly co-developing AI

Dec 12, 2016 00:19:33

Description:

This is Python Bytes, Python headlines and news deliver directly to your earbuds: episode 6, recorded on Monday, December 12th. In this episode we discuss why Python 3.6 is going to be awesome, kite: your friendly co-developing AI, and more!

This episode was brought to you by Rollbar: they help you take the pain out of errors.

This is the last episode of 2016. Thank you everyone for a great launch. We’ll be back early January. 😉 Be sure to check out Talk Python and Test and Code if you want more Pythonic listening over the break.

News items

#1 Make your Python code more readable with custom exception classes

This is a 5 min video + text. Good introduction into why you should define your own exceptions instead of using the built in ones, and how to do it.
It makes errors from your code more readable. Better communication between your code and the person using your code. It allows you to give more context of the error to the caller of the function. Remember to derive from Exception or from another builtin exception. Do people create enough fine-grained exception types? I would say probably not. This advice is good because it encourages EAFP (easier to ask for forgiveness than permission) style of programming which is generally Pythonic. Allows for multiple except statements for different errors in one try block Dan also featured our show in The ultimate list of Python Podcasts (thanks Dan!) If you have a package that defines it’s own exceptions, please read another article. The definitive guide to Python exceptions Julien Danjou https://julien.danjou.info/blog/2016/python-exceptions-guide Covers having a common base exception for your package, organization within a package, and some examples of packages that organize their exceptions well, including requests

#2 Kite

Kite augments your coding environment with all the internet’s programming knowledge. Is an AI pair programmer, or mentor really. Contextual info for language packages e.g. “import r” → shows list of popular packages then detailed docs, examples, etc. autocompletions… by global popularity BYOE even works on your code be sure to watch the video kite.com is implemented mostly in Go according to the founder Adam Smith. Thanks Gilberto Diaz for sending this one to us.

#3 Tidy Data in Python (by Jean-Nicholas Hould)

This article caught my attention because of the notion that the data as you receive it might not be in a form that is ideal to use it. This I am used to. But the article give some attributes of what problems to look for in data sets, and how to transform the data into a more usable structure using pandas. Great example of someone taking a good idea from someone else, summarizing it, and showing how to use it in Python. Based on a paper named Tidy Data by Hadley Wickham In this post, I will summarize some tidying examples Wickham uses in his paper Will demonstrate how to do so using the Python pandas library Tidy data has the following attributes: Each variable forms a column and contains values Each observation forms a row Each type of observational unit forms a table A few definitions: Variable: A measurement or an attribute. Height, weight, sex, etc. Value: The actual measurement or attribute. 152 cm, 80 kg, female, etc. Observation: All values measure on the same unit. Each person.

#4 What's new in Python 3.6

By Brett Cannon Works at Microsoft Azure Data Science team Python core developer 16 PEPs in Py3.6 - more than any other release than Py 3.0 PEP 498 Formatted string literals You learn about internals That this is actually faster than str.format() because optimizations that can be done on the string itself (f””) PEP 524: On Py 3.5 would fall back to unsecure. On Py 3.6 os.urandom() now blocks os.urandom() for cryptographically strong random numbers or os.getrandom() raises error if not enough randomness. Usually not a problem, but with things like containers and IoT, it has become one! Fix: use new secrets module. There are also other interesting things that aren’t PEPs Python 3.6 is generally significantly faster (than Py3.5 and legacy Python) Python 3.6.0 release candidate is now available, final expected end of the week Something that hasn’t been as highly publicized is the deprecation of pyvenv. https://docs.python.org/3.6/library/venv.html “The pyvenv script has been deprecated as of Python 3.6 in favor of using python3 -m venv to help prevent any potential confusion as to which Python interpreter a virtual environment will be based on.” This is important for me and you and anyone who teaches people to use Python. We often recommend virtual environments, and it’s good to recommend -m venv to make sure people know which Python interpreter they are tying to their virtual environment.

#5: Who Tests What

I had Ned Batchelder on Test&Code to discuss coverage. Episode 12. Ned is planning a new feature for coverage.py, which would tell you not just which code has run, but which test (or something else) caused that code to run. Discusses the stages of coverage, measurement/storing data/combining/reporting. Discusses the issue of how to decide who is calling the code in question. His current model is based on coverage having a plugin hook for someone to tell coverage a string that defines the “what” that is causing the code to be run. He also discusses some decisions about storage concerns and what coverage does now. He has questions remaining that he wants help with: Today coverage.py keeps everything in memory until the end of the process, then writes it all to disk. Q: Will we need something more sophisticated? Can we punt on that problem until later? Q: Is it important to try to conserve memory? Today, the .coverage data files are basically JSON. This much data might need a different format. Q: Is it time for a SQLite data file? Q: How would you use the data? And a couple more questions regarding reporting. I like the direction this is going and I encourage everyone who has some nonstandard usage of coverage to take a look at this and give Ned some feedback.

#6 Threaded Asynchronous Magic and How to Wield It (by Cristian Medina)

This is your async programming in Python 3.5+ via async / await article Covers: Tasks Scheduling tasks Scatter / gather example Moving the asyncio loop to a background thread Examples: Real World Example #1 — Sending Notifications (email) Real World Example #2 — Parallel Web Requests via aiohttp: HTTP client/server for asyncio (PEP 3156)

Update: From episode 3: pynini https://en.m.wikipedia.org/wiki/Pāṇini

#5 Legacy Python vs Python and why words matter and Request's 5 Whys retrospective

Dec 5, 2016 00:18:30

Description:

This is Python Bytes, Python headlines and news deliver directly to your earbuds: episode 5, recorded on December 5, 2016. In this episode we discuss Legacy Python vs Python and why words matter and Request's 5 Whys retrospective.

This episode was brought to you by Rollbar: they help you take the pain out of errors.

News items

#1 The Five Why’s of Requests 2.12 https://lukasa.co.uk/2016/11/Five_Whys_Requests_212/

Some decision we made breaks a whole bunch of people’s code, and then each fix we attempt to make produces new, unforseen problems. These releases can be very dispiriting for project maintainers, because they make it seem like every time we try to improve something we get stuck on the mistakes our past selves made. Requests has had a few of these in the past, and right now we appear to be in the middle of another one. So far the 2.12 release series has caused problems for a number of users Problem: The current release of Requests, v2.12.2, breaks anyone who uses a URL with a scheme that isn’t “http” or “https” and who passes the params keyword to a Requests URL. Ultimately, our current issue comes from the fact that we have been inconsistent on our stance regarding URLs with weird schemes

#2 Planning an Early Death for Python 2 https://carreau.github.io/posts/planning-an-early-death-for-python-2.html via https://twitter.com/mbussonn

From Data Structure for Data Science workshop gathered at UC Berkeley's BIDS [Berkeley Institute for Data Science] Out of the discussion arose a topic that has long plagued the python community at large: code that requires legacy Python 2.7 is holding back the development of data-science toolsets and – by extension – the progress of data science as a whole. Python 2.7 was an important part of the history of scientific computing, but now it should be left as part of that history. Thus, we convened a small working group to plan an early death for Legacy Python. So what are the step we can do to push the transition forward? Choose your words: Assume that Python 3 is just Python, and refer to Python 2 as legacy python. Refer to Legacy Python in the past tense (reinforce the old and deprecated state of Legacy Python) Make your examples/documentation Python 3 only Sprinkle with function annotation, and async/await keyword can help with communicating your example are Python 3 only… Ask user to reproduce but on up-to-date Python version Testing: Make sure that all the project you care about have continuous integration on Python 3

#3 Simplifying complex business logic with Python's Kanren https://jeffersonheard.github.io/2016/11/simplifying-complex-business-logic-with-pythons-kanren/

#4 If Reddit were written from scratch today, which Python web framework would it use and why? https://www.reddit.com/r/Python/comments/5gdckn/if_reddit_were_written_from_scratch_today_which/

Today (from SQLAlchemy's page): Reddit is one of the biggest social news aggregators on the internet. Reddit is built using Pylons, Mako templates, and a custom, non-ORM database abstraction layer built on SQLAlchemy Core. Ergo14: I would say that the most sane option would be Pyramid. It is faster than Django in tests and it doesn't repeat mistakes with threadlocals that flask or pylons did in past. I did some both small and medium-big (20+ million user applications) and it just feels right. It doesn't try to get in your way and give you magic solutions to your problems. Wting: I'm assuming you're talking about reddit at its current scale. Not Flask. Too many global variables and it's not thread safe (for async). Not Django. It's too opinionated and everything is in-housed for scaling reasons. My guess is Pyramid (the successor to Pylons). In fact, that's what reddit's current and future services are built with. So, Python web frameworks tend to cause a very strong, very subjective split in opinion.

#5: Two testing related articles

Getting started with pytest https://jacobian.org/writing/getting-started-with-pytest/ Anything that promotes pytest without presenting wrong information is good

The Best New Feature in unittest You Didn’t Know You Need https://hackernoon.com/the-best-new-feature-in-unittest-you-didnt-know-you-need-e0d26c213dce

First article I’ve seen explaining subtest Subtest was added in Python 3.4

#6 PyTone https://www.luga.de/pytone/ PyTone is a music jukebox written in Python with a curses based GUI. While providing advanced features like crossfading and multiple players, special emphasis is put on ease of use, turning PyTone into an ideal jukebox system for use at parties.

Thx @kidpixo: https://twitter.com/kidpixo/status/803345072414740480

#4 Python 3 is just fine for beginners thank you, q is awesome for debugging, and more

Nov 29, 2016 00:21:08

Description:

This is Python Bytes, Python headlines and news deliver directly to your earbuds: episode 4: recorded on November 28, 2016. In this episode we cover the case for Python 3, asyncio, pyston, pydoc.io, and q.

This episode was brought to you by Rollbar: they help you take the pain out of errors.

News items

The Case FOR Python 3

>> "It's as simple as that. If you learn Python 2, then you can still work with all the legacy Python 2 code in existence **until Python dies or you (hopefully) move on**. But if you learn Python 3 then your future is very uncertain. You could really be learning a dead language and end up having to learn Python 2 anyway." -- Zed S. This is harmful to the Python community. Let's stop recommending this book and stop elevating this guy's work "Arguments" from Zed: Not In Your Best Interests: "The Python project’s efforts to convince you to start with Python 3 are not in your best interest, but, rather, are only in the best interests of the Python project." You Should Be Able to Run 2 and 3 (in the same process). The fact that no one has (yet) written a Python 3 interpreter that can simultaneously run Python 2 in the same process means Python 3 is not Turing complete Difficult To Use Strings: "The strings in Python 3 are very difficult to use for beginners. In an attempt to make their strings more “international” they turned them into difficult to use types with poor error messages." Final analysis: You can’t add b"hello" to "hello". Too many formatting choices for strings Bytes aren't automatically decoded to strings Therefore: All newbies should avoid Python 3 like the plague - it will curse your career and cloud your judgement. Excellent rebuttal article: Rebuttal for Python 3

Reddit discussion of a Feb article on "AsyncIO for the Working Python Developer" - Article: AsyncIO for the Working Python Developer

Article is a nice introduction, but uses Python 3.4 syntax Interesting to note that no one in the reddit comments suggests a better 3.5 tutorial. Is async/await just too confusing for a 3.5 intro article? Or is it so simple that no one has thought it needs a tutorial. 23 page article / tutorial on Python 3.4's asyncio Not covering Python 3.5's async / await, but great gateway article Here’s a call for action. Someone write a similar article but with 3.5+ syntax. Also could we show examples without sleep calls. Sleep is such a lame way to show “do some actual work”. Maybe use a producer/consumer or reader/writer example or something.

Pyston 0.6 released

Pyston is an open source Python implementation that aims to be both highly compatible and high-performance. It uses modern JIT techniques and natively supports many CPython C extension modules. Pyston is sponsored by Dropbox, and is pronounced "piston". main goal was to reduce the overall memory footprint. It also contains a lot of additional smaller changes for improving compatibility and fixing bugs. We also spent time on making it easier to replace CPython with Pyston, such as by more closely matching its directory structure following its ‘dict’ ordering. We can now, for example, run pip and virtualenv unmodified, without requiring any upstream patches like other implementations do. Unclear how much of a research project vs an actual project this is at the moment

Announcing pydoc.io

Automatic API documentation from pypi repositories. Pydoc.io will eventually auto-generate API reference documentation for every package on PyPI.

What one thing took your Python to the next level

Mastering generators Understanding how iteration really works in Python opens up many possibilities for elegant, high performance code. Use iPython. Learn that for does tuple unpacking; play with zip, enumerate, all, any; take a look at the itertools module Unit tests! Pytest in particular! Gives you a whole new perspective on your code and dammit, it's so satisfying to get all those green OKs! list comprehensions For me, all the work of David Beazley, in particular http://www.dabeaz.com/coroutines/

q : Quick-and-dirty debugging output for tired programmers

Learned about it from a tweet from Luciano Ramalho. https://twitter.com/ramalhoorg/status/802673217081065472 5 min lightning talk: https://youtu.be/OL3De8BAhME?t=25m20s q on pypi: https://pypi.python.org/pypi/q Our personal news Michael Follow up: https://www.python.org/dev/peps/pep-0494/ Python 3.6 Release Schedule Final date: 2016-12-16 Brian Hard at work on pytest book that is a followup to current Python Testing book.

#3 Python 3.6 is coming, and it's awesome plus superior text processing with Pynini

Nov 23, 2016 00:29:41

Description:

Welcome to Python Bytes. Python headlines delivered directly to your earbuds. In this episode we cover the new features in Python 3.6, text processing with Pynini, Python is 2nd most popular language on GitHub and more.

This episode was brought to you by Rollbar: they help you take the pain out of errors.

News items

How to get superior text processing with Pynini

how to change your thinking from regular expression matching to FSAs (finite-state acceptor), then FSTs. Example using cheese names (love the Python tradition with that). library developed at Google called pynini for easily using FSTs

Python 3.6 b4 Is out! (beta!!!)

PEP 498, formatted string literals. PEP 515, underscores in numeric literals. PEP 525, asynchronous generators. PEP 530: asynchronous comprehensions. The dict type has been reimplemented to use a faster, more compact representation similar to the PyPy dict implementation. This resulted in dictionaries using 20% to 25% less memory when compared to Python 3.5. The class attribute definition order is now preserved. Security: The new secrets module has been added to simplify the generation of cryptographically strong pseudo-random numbers suitable for managing secrets such as account authentication, tokens, and similar. Windows: python.exe and pythonw.exe have been marked as long-path aware, which means that when the 260 character path limit may no longer apply. See removing the MAX_PATH limitation for details.

Create an Excellent Python Dev Env

pyenv, like virtualenv, I think, but independent of Python. pyenv-virtualenv instead of virtualenvwrapper pipsi - a tool to let you install python based CLI utilities in their own virtualenv easily. Tools he installs with pipsi: tox - testing multiple environments mkdocs - documentation static site generator git-review - gerrit integration with git. flake8 - static analysis He also mentions a shell called fish, which I hadn’t heard of before.

GitHub language statistics, Python is 2nd most popular language

An active repository should meet this requirements: created or updated during the evaluated period, at least one star at least one fork a size larger than 10 Kb JavaScript is likely over counted

Handling Unicode Strings in Python

Text Representation in Python and the differences between 2.7 and 3.4+ Converting between unicode strings and bytes IO boundary issues with databases, file system, or network services Logging JSON encoding Redis A pointer to a 2012 article from Ned Batchelder called Pragmatic Unicode.

Python extensions for VS Code for Mac / PC / Linux

Linting (Prospector, Pylint, pycodestyle/Pep8, Flake8, pylama, pydocstyle with config files and plugins) Intellisense (autocompletion with support for PEP-0484) Scientific tools (Jupyter/IPython) Auto indenting Code formatting (autopep8, yapf, with config files) Code refactoring (Rename, Extract Variable, Extract Method, Sort Imports) Viewing references, code navigation, view signature Excellent debugging support (remote debugging over SSH, mutliple threads, django, flask) Unit testing, including debugging (unittest, pytest, nosetests, with config files) Execute file or code in a python terminal Local help file (offline documentation) Snippets Our personal news Brian Lot’s of writing. My target is to get the book in print by PyCon US 2017 in May. But that’s an aggressive schedule with the rest of my projects. Still working on getting #25 out the door. Interview with Dave Hunt from Mozilla about Selenium, Mozilla, pytest, tox, CI, and much more. Should go out within the next couple of days. Next interview scheduled is with David Hussman from DevJam. This will be a higher level discussion about software development practices. Look for that this month also. Michael Shipped: Episode #85: Parsing horrible things with Python Quick correction: github's awesome-python isn't the newsletter, that's https://python.libhunt.com

#2 PyCon, awesome python, python developer job prospects, and more

Nov 14, 2016 00:17:38

Description:

Welcome to Python Bytes. Python headlines delivered directly to your earbuds. In this second episode we cover a couple of key python package releases, pycon, awesome python, python developer job prospects, and more!

News items

Celery 4.0

A task queue and scheduling subsystem Supposedly a massive release with over 2 years of changes Will be the last major release with Python 2.x support, already dropping 2.6

Psutil 5.0.0

Used for process monitoring, system utilization, and other cross platform os things. We use it with some tools and it can be the bottleneck, so a speedup is very welcome.

Pytest 3.0.4

Mostly a bug fix release. Check out the change log to see if you care about anything they fixed. Report teardown output on test failure. Already did report setup output.

Registration is open for PyCon 2017!

Don't wait! Take advantage of the early bird discount We are having a booth!

PyCon Tutorial proposals due on November 30

Tutorial proposals are due on 2017 November 30 Talk proposals will be due on 2017 January 3 Poster proposals will be due on 2017 January 3 We'll be hosting a Podcast open session

Github awesome-python

A curated list of awesome Python frameworks, libraries, software and resources A sampling of the topic areas: Authentication Data Validation Date and Time Debugging Tools Machine Learning Search

Timing Tests in Python for Fun and Profit

Fun example of how and why you'd ever want to customize a test runner. Final solution is pretty cool. However, I'm not sure if it includes setup/teardown time. BTW, pytest has this built in, pytest --durations=0 time every setup, teardown, and test method. pytest --durations=3 shows the slowest 3, etc. As well as shows the time of each. Also works on unittest code.

What's the Average Python Developer Salary in the US, and Why Is Python So Popular, Anyway?

2015 and 2016 have been big years for Python. According to the 2016 Developer Survey by StackOverflow, Python ranks as the world's sixth most popular programming language for the second year in a row, and is also rated the fourth most wanted technology of the year. Python is also one of the hottest tech skills to have, according to research by Dice, with demand slightly outstripping supply. Python is one of the highest-paying programming languages in the USA. In fact, at $103,492 per year or by Indeed - $116,129 Why? The world's tech giants love it. With the rise of data science, Python's popularity as a scientific language has soared It's perfect for beginners It might just be the only language you need Our personal news Brian T&C #24: Raphael Pierzina, on cookie cutter, pytest 3.0, and contributing to both: http://pythontesting.net/podcast/24-pytest-raphael-pierzina/ T&C #25: Dave Hunt, recorded. Hope to get that out this week. We talk about his work on Selenium, pytest-selenium, pytest-html, tox, and how Mozilla does some of it's testing with these tools. Looking for more people to interview. A few in the pipeline, including David Hussman from http://devjam.com/, but I'd love suggestions. Doesn't have to be testing. I'll be talking to David about Dude's Law, his view of modern agile practices, and other high level topics. Michael Python: An Amazing Second Language for .NET Developers on PyVideo Mutation Testing in Python with Cosmic Ray on PyVideo New content in my Python for Entrepreneurs course Talk Python To Me #85 is coming this week

#1 Intro to the show and pip 9 is out!

Nov 7, 2016 00:16:38

Description:

Welcome to Python Bytes. Python headlines delivered directly to your earbuds. In this first episode we cover PyData videos, safety-db project, and more!

News items

PyData DC 2016 videos are out

64 videos (30 hours) Some standout videos ElasticSearch and Redis How and When to Use Them Renee Teate | Becoming a Data Scientist Advice From My Podcast Guests (becoming a data scientist podcast) Visual diagnostics for more informed machine learning You got your engineering in my Data Science: Addressing the reproducibility crisis

easyargs

A python module to make handling command line arguments easy There are many ways to create a command line parser in python: argparse, docopt, click. These are all great options, but require quite a lot of configuration and sometimes you just need a function to be called. Enter easyargs. Define the function that you want to be called, decorate it and let easyargs work out the command line.

safety-db via github

A curated database of insecure Python packages What is this? This is an effort to collect all known security vulnerabilities in Python packages and make them available to consume for humans and automated tools. What is this not? This is not a hall of shame, or a list of packages to avoid. The package maintainers show a great responsibility by documenting and fixing security issues in such a way that they can be listed here. That's extremely valuable when considering using a package in production.

fast-style-transfer

Since A-Ha's take on me video, I've loved the idea of short video done in stylized art format. Uses Tenserflow, which I've never used before. No practical use I can think of, but would be fun.

pip 9.0 is out!

New: Add a pip check command to check installed packages dependencies pip show is less verbose by default. Add --not-required option to pip list, which lists packages that are not dependencies of other packages. Many more, including fixes 9.0.1 (4 days later with 5 fixes)

What does Reddit think about the new MBP?

I'd never even heard of sentiment analysis before. This is cool that it's topical, interesting, and short. Our personal news Brian Episode 24 Test and Code Podcast: Raphael Pierzina (cookie cutter, pytest 3.0, pytest sprint, …) will be out the week of Nov 7. Some upcoming interviews I'm really excited about. Video from PNSQC 2016 conference now up. https://t.co/rg4BENfeGQ Pietist book still in progress. When there is more info to know, I will share with this podcast, as well as people who follow me through the pythontesting.net slack community, patreon supporters, email subscribers. And I'm going do my best to get $5 off for everyone who has purchased the current eBook and left me their email. Michael New Talk Python To Me podcast episodes Are we failing to fund Python's core infrastructure? Parsing horrible things with Python - Erik Rose Python at StackOverflow - Martijn Pieters