What is a Python egg?

Viewed 320210

I'm new to Python and I'm just trying to understand how its packages work. Presumably eggs are some sort of packaging mechanism, but what would be a quick overview of what role they play and may be some information on why they're useful and how to create them?

4 Answers

Note: Egg packaging has been superseded by Wheel packaging.

Same concept as a .jar file in Java, it is a .zip file with some metadata files renamed .egg, for distributing code as bundles.

Specifically: The Internal Structure of Python Eggs

A "Python egg" is a logical structure embodying the release of a specific version of a Python project, comprising its code, resources, and metadata. There are multiple formats that can be used to physically encode a Python egg, and others can be developed. However, a key principle of Python eggs is that they should be discoverable and importable. That is, it should be possible for a Python application to easily and efficiently find out what eggs are present on a system, and to ensure that the desired eggs' contents are importable.

The .egg format is well-suited to distribution and the easy uninstallation or upgrades of code, since the project is essentially self-contained within a single directory or file, unmingled with any other projects' code or resources. It also makes it possible to have multiple versions of a project simultaneously installed, such that individual programs can select the versions they wish to use.

Disclaimer: egg is an abandoned format of python package, the tools to use eggs no longer exist.

An egg is a python package. It's a zip archive containing python source files and/or compiled libraries.

The format is not well specified about what it must contain or how to make packages for different versions of python and different operating systems, that's one of the reasons it was replaced.

The format appeared around 2004 and was in-use until the mid 2010s, it's been completely replaced by wheels and pip install.

Eggs were installed by the command easy_install. The command was removed in setuptools v58.3 (year 2021). You can no longer use eggs.

If you see anything that mentions easy_install or egg, be it any stack overflow answers or tutorials, it is seriously obsolete.

Recommend this longer answer https://stackoverflow.com/a/68897551/5994461 for an in-depth history of python packaging. It's going over pip and wheels and eggs and much more.

Related