What are the advantages of packaging your python library/application as an .egg file?
Asked Answered
F

6

28

I've read some about .egg files and I've noticed them in my lib directory but what are the advantages/disadvantages of using then as a developer?

Ferricyanide answered 6/9, 2008 at 23:35 Comment(0)
M
32

From the Python Enterprise Application Kit community:

"Eggs are to Pythons as Jars are to Java..."

Python eggs are a way of bundling additional information with a Python project, that allows the project's dependencies to be checked and satisfied at runtime, as well as allowing projects to provide plugins for other projects. There are several binary formats that embody eggs, but the most common is '.egg' zipfile format, because it's a convenient one for distributing projects. All of the formats support including package-specific data, project-wide metadata, C extensions, and Python code.

The primary benefits of Python Eggs are:

  • They enable tools like the "Easy Install" Python package manager

  • .egg files are a "zero installation" format for a Python package; no build or install step is required, just put them on PYTHONPATH or sys.path and use them (may require the runtime installed if C extensions or data files are used)

  • They can include package metadata, such as the other eggs they depend on

  • They allow "namespace packages" (packages that just contain other packages) to be split into separate distributions (e.g. zope., twisted., peak.* packages can be distributed as separate eggs, unlike normal packages which must always be placed under the same parent directory. This allows what are now huge monolithic packages to be distributed as separate components.)

  • They allow applications or libraries to specify the needed version of a library, so that you can e.g. require("Twisted-Internet>=2.0") before doing an import twisted.internet.

  • They're a great format for distributing extensions or plugins to extensible applications and frameworks (such as Trac, which uses eggs for plugins as of 0.9b1), because the egg runtime provides simple APIs to locate eggs and find their advertised entry points (similar to Eclipse's "extension point" concept).

  • There are also other benefits that may come from having a standardized format, similar to the benefits of Java's "jar" format.

-Adam

Mcginty answered 6/9, 2008 at 23:39 Comment(1)
But what if dependent Python packages do not have binary eggs uploaded to PyPi?Clothesline
P
5

One egg by itself is not better than a proper source release. The good part is the dependency handling. Like debian or rpm packages, you can say you depend on other eggs and they'll be installed automatically (through pypi.python.org).

A second comment: the egg format itself is a binary packaged format. Normal python packages that consist of just python code are best distributed as "source releases", so "python setup.py sdist" which result in a .tar.gz. These are also commonly called "eggs" when uploaded to pypi.

Where you need binary eggs: when you're bundling some C code extension. You'll need several binary eggs (a 32bit unix one, a windows one, etc.) then.

Parturifacient answered 13/10, 2008 at 14:40 Comment(3)
But what if dependent Python packages do not have binary eggs uploaded to PyPi?Clothesline
They you simply keep the have-to-have-a-compiler problem. There's no magic solution: you either have pre-compiled packages/eggs or not.Parturifacient
Yes, I have my precompiled package/egg, but what about dependencies? Is there a way to say that if egg is not available on PyPi, please use this and this repository?Clothesline
S
4

Eggs are a pretty good way to distribute python apps. Think of it as a platform independent .deb file that will install all dependencies and whatnot. The advantage is that it's easy to use for the end user. The disadvantage are that it can be cumbersome to package your app up as a .egg file.

You should also offer an alternative means of installation in addition to .eggs. There are some people who don't like using eggs because they don't like the idea of a software program installing whatever software it wants. These usually tend to be sysadmin types.

Stasny answered 6/9, 2008 at 23:43 Comment(0)
T
3

.egg files are basically a nice way to deploy your python application. You can think of it as something like .jar files for Java.

More info here.

Terpineol answered 6/9, 2008 at 23:39 Comment(0)
M
1

Whatever you do, do not stop distributing your application, also, as a tarball, as that is the easiest packagable format for operating systems with a package sysetem.

Millrace answered 26/9, 2008 at 5:26 Comment(0)
S
1

For simple Python programs, you probably don't need to use eggs. Distributing the raw .py files should suffice; it's like distributing source files for GNU/Linux. You can also use the various OS "packagers" (like py2exe or py2app) to create .exe, .dmg, or other files for different operating systems.

More complex programs, e.g. Django, pretty much require eggs due to the various modules and dependencies required.

Stardom answered 26/9, 2008 at 7:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.