Unpack Python Packages 📦

Deep dive into the wheels of python packaging

Alexander Hultnér FlaskCon, 2021

@ahultner

Alexander Hultnér

Founder of Hultnér Technologies and Papero.io

 

 

@ahultner

Hultnér Technologies

  • Alexander Hultnér
  • Magnus Junghard
  • Office in Gothenburg
  • Consulting
  • In-house development
  • Looking to hire devs in Gothenburg

 

contact@hultner.se

 

@ahultner

About us

Outline

  • Why do we care?
  • What is a Python Package?
  • Distribution types
    • Source distribution
    • Eggs
    • Wheels
  • Hands on!
    • Deconstruct a package
    • Build a package from scratch
  • Modern tooling
  • More resources
  • Q&A

@ahultner

Why do we care?

  • Distribution
  • Code sharing, reusability
  • Separation of concerns
  • Understand the magic behind the curtains

@ahultner

  • Bundle
  • Distribution format
  • Python Libraries
  • Applications / dev tools
  • PyPI
  • Private Repositories

What's a Python Package?

Quick introduction


 

@ahultner

  • Source distributions
    • (sdist), .tar.gz
  • Eggs
    • .egg
  • Wheels
    • .whl

 

Formats

Python Packaging Formats


 

@ahultner

  • Source distributions
  • Usually pkg.tar.gz files
    • pkg.zip
    • pkg.tar.[bz2, xz, (Z*)]
  • Source code
  • Needs to be compiled
  • Distribute to unsupported platforms
  • Executes setup.py for dependencies

 

sdist

Python Packaging Formats


 

@ahultner

  • De-facto standard
  • .egg files
  • Compiled "binary distribution"
  • Legacy format replaced by standard

 

Egg

Python Packaging Formats


 

@ahultner

  • "New" standard format
  • Replaces eggs, can convert to whl
  • Installation format
  • .whl-files
    • Compatibility targets in file name
  • Resolve dependencies statically
  • No need for setup.py
  • Signed, RECORD checked on install
  • Versioned format

 

Wheel

Python Packaging Formats


 

@ahultner

Hands on session

Explore python packages


 

@ahultner

Conclusion

  • sdist is for source code
  • Wheels replaces eggs
  • Wheels simple zipfiles
    • Static metadata format
    • Enables faster and better tooling
  • We can now distribute binary packages natively without conda
  • Packaging is easy with modern tools

@ahultner

Questions

Contact me if you have any further

questions.

 

 

Want to learn more?

Available for training, workshops and

freelance consulting.

 

Sign up for book updates!

Papero.io/beta

Links

@ahultner

Unpack Python Packages 📦 – Deep dive into the wheels of python packaging

By Alexander Hultnér

Unpack Python Packages 📦 – Deep dive into the wheels of python packaging

Live stream: https://youtu.be/kO5Es7KKUIY This talk provides a hands-on deep-dive into the wheel file format and python packaging. First, we will slash the tire, see what's inside, and then build new wheels from scratch. You will learn about the inner workings of a crucial part of the Python packaging ecosystem and understand what your tools do behind the covers.

  • 880