Python Bytes podcast artwork

A podcast from Michael Kennedy and Brian Okken

Python Bytes

pythonbytes.fm

26 Episodes • Released Weekly

26 Episodes • Released Weekly

A podcast from Michael Kennedy and Brian Okken

Python Bytes

Python Bytes podcast artwork npr.org/programs/invisibilia

26 Episodes • Released Weekly

Listen to this with Pocket Casts, the free podcast app

Elevate your podcast experience

Find Out More

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.

Latest Episode

27 Aug 2020 • 31 mins

Version your SQL schemas with git + automatically migrate them

Sponsored by Datadog: pythonbytes.fm/datadog Brian #1: Surviving Django (if you care about databases) Daniele VarazzoHard to summarize, but this is an interesting perspective on getting to know your database better and using database migrations and database schemas, etc. instead of relying on Django’s seemingly agnostic view of databases.Following the article is a nice civilized discussion in the comments between the author, Paolo Melchiorre, Andrew Godwin, and others.Interesting comment by Andrew: “I agree that at some point in a project/company's life, if it's big enough, SQL migrations are the way to go. … Migrations in the out-of-the-box state are mostly there to supplement rapid prototyping, and then like a lot of Django, can be removed/ignored progressively if and when you outgrow the single set of design constraints we had to choose for them.” Michael #2: Python Numbers and the Flyweight design pattern Working on allocation and other memory internals from my upcoming Python Memory Management and Tips courseFlyweight design pattern via Wikipedia Python numbers are expensive ( >= 28 bytes each)Python does not allocate more than one int in the range [-5, 256]Example code: app_flyweight.pyAlso working on a Python Design Patterns course and Flyweight is back there too. Brian #3: What Are Python Wheels and Why Should You Care? Brad SolomonSecond half is about creating wheelsI’m more interested in the first half, a discussion of wheels from the users perspective.Most package authors now all this stuff, or most of it. But this is a nice quick intro for the rest of the Python ecosystem as package users.If you pip install something that isn’t a wheel, it’s probably a tarball. pip downloads the tar.gz filebuilds a wheel, which includes calling setup.pylabels itthen installs itFor pre-wheeled packages, the build and label aren’t needed, so it’ s fasterAlso, the download size is usually smaller, so that part is also faster.Wheels are essentially zip files with specially crafted filenames that tell installers what Python versions and platforms the wheel will support: {dist}-{version}(-{build})?-{python}-{abi}-{platform}.whlex: cryptography-2.9.2-cp35-abi3-macosx_10_9_x86_64.whlWheels can have platform specific builds, like for macosx vs unix, etc.Advantages of wheels: install fastersmallercut the setup.py execution outno need for compiler as they can be os specificauto generated .pyc filesprovide consistency Michael #4: Pandas_Alive By Jake McKewPandas_Alive is intended to provide a plotting backend for animated matplotlib charts for Pandas DataFrames, similar to the already existing Visualization feature of Pandas.With Pandas_Alive, creating stunning, animated visualizations is as easy as calling df.plot_animated()Also supports: GeoSpatialData with geopandas, basemaps with contextily, writing to GIF in memory (no external dependencies), progress bars with tqdmSince release 3 weeks ago, Pandas-Alive has been downloaded over 11,000 times off PyPI which is absolutely unrealComes with visuals :) Brian #5: How To Use the Python Map Function Kathryn Hancoxmap() is so useful, but not obvious to people coming from other languages. If you don’t use it much, that’s fine, but it’s nice to review occasionally because it does more than I originally gave it credit for.This tutorial walks through: Normal map use with a lambda function applied to a list.Using user defined functions. Actually this bit is more confusing than it needs to be as it has a function returning a map object, which is kinda weird in the particular circumstance. But doesn’t detract from the rest too much.Using built in functions to map.Using functions that take more than one argument and using map across multiple iterables.Takeaways map() only applies the function one element at a time during iteration, so it’s efficient with large data sets and with sequences that won’t reach the end.Remember you can use lambdas, built in functions, and you own functions with map.You can use functions that take multiple arguments, but that requires passing in multiple iterables, one for each function argument.Comprehensions are often just as useful, especially for small data sets, but don’t forget about map. Michael #6: Version your SQL schemas with git + automatically migrate them automigrate projectAutomigrate is a command-line tool for SQL migrations. Unlike other migration tools, it uses git history to do diffs on create table statements instead of forcing you to write up/down diffs for every change.This tool doesn't make you write & manage a giant folder of up/down migrations. It uses git history to infer them instead, and to version production databases.Not as nice as alembic (even though it portrays itself otherwise). But if you are writing DDL by hand, this is much better!Speaking of which: Generate ORM definitions from SQL: Experimental sqlalchemy generator in sa_harness.py. Try it out with: python -m automig.lib.sa_harness 'test/schema/*.sql' Extras: Michael: Get notified of release for new courses at training.talkpython.fm/getnotified Excel to PythonGetting Started in Data SciencePython Memory Management and TipsGetting started with GitPython Design Patterns Jokes! “Engineers remove dead code after dropping a feature flag”, Sir Frank Bernard Dicksee, 1893, Oil on canvas “CSS without comments”, Pablo Picasso, 1912 “Experienced developer deploys hotfix on production”, Francisco Goya, Oil on canvas, circa 1788