Skip to main content

Show how to structure a Python project.

Project description

https://travis-ci.org/bast/somepackage.svg?branch=master https://img.shields.io/badge/license-%20MPL--v2.0-blue.svg

Somepackage

Show how to structure a Python project.

Inspired by https://github.com/kennethreitz/samplemod.

Recommendations

Python 2 or 3?

  • Develop your code under Python 3, test it for both Python 2 and Python 3 but consider Python 3 to be the default today.

Split your code into packages, modules, and functions

  • All code should be inside some function (except perhaps if __name__ == '__main__':).

  • Split long functions into smaller functions.

  • If you need to scroll through a function over several screens, it is probably too long.

  • Hide internals with underscores.

  • Organize related functions into modules.

  • If modules grow too large, split them.

  • Import from other modules under somepackage/ using from .somemodule import something.

  • Do file I/O on the “outside” of your code, not deep inside.

Naming

  • Give the subdirectory the same name as your package.

  • Before you name your package, check that the name is not taken on https://pypi.org (you may want to upload your package to PyPI one day).

Interfaces

  • In somepackage/__init__.py define what should be visible to the outside.

  • Use https://semver.org.

Testing

Dependency management

  • Package dependencies for developers should be listed in requirements.txt.

  • Package dependencies for users of your code (who will probably install via pip) should be listed in setup.py.

Code style

Share your package

Documentation

Suggestions? Corrections? Pull requests?

Yes please!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

somepackage-1.2.3.tar.gz (8.6 kB view details)

Uploaded Source

File details

Details for the file somepackage-1.2.3.tar.gz.

File metadata

File hashes

Hashes for somepackage-1.2.3.tar.gz
Algorithm Hash digest
SHA256 274f83dcf6110c8ecd21e7b8c9b2907274a1170830875738fda167e611143077
MD5 144abedb77bcd7d9a010fe105bb3bf7f
BLAKE2b-256 81f6cdc617199548a495fd034a4128bb33b35857d2ddb97ddf25c4f29302569e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page