5 Simple Rules For Building Great Python Packages

A very good article on building great python packages.

Corps of Engineers

ryanlerch_Roundabout_SignA package seems simple enough to build, just a collection of modules in a directory with an __init__.py, right? As straight-forward as it may seem, with more and more modifications to your package over time, a poorly designed package will tend towards circular dependency problems, and may become non-portable and brittle.

Following these 5 simple design patterns will help you avoid these common pitfalls, and write packages that will live long and prosper.

1. __init__.py is Only for Imports

For a simple package, you might be tempted to throw utility methods, factories and exceptions into your __init__.py. Don’t.

A well-formed __init__.py serves one very important purpose: to import from sub-modules. Your __init__.py should look something like this:

# ORDER MATTERS HERE -- SOME MODULES ARE DEPENDANT ON OTHERS from exceptions import FSQError, FSQEnvError, FSQEncodeError,\ FSQTimeFmtError, FSQMalformedEntryError,\ FSQCoerceError, FSQEnqueueError, FSQConfigError,\ FSQPathError, FSQInstallError, FSQCannotLockError,\ FSQWorkItemError, FSQTTLExpiredError,\ FSQMaxTriesError, FSQScanError, FSQDownError,\ FSQDoneError, FSQFailError, FSQTriggerPullError,\ FSQHostsError, FSQReenqueueError…

View original post 1,190 more words

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s