A very good article on building great python packages.
A 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