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.

  • Functions should do one thing and one thing only.

  • 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.

Classes vs. functions

  • Do not overuse classes.

  • Prefer immutable data structures.

  • Prefer pure functions.

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.

  • Alternatively, consider using http://pipenv.readthedocs.io.

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

Code style

Type checking

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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rolete-1.2.3-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file rolete-1.2.3-py3-none-any.whl.

File metadata

  • Download URL: rolete-1.2.3-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/49.1.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.3

File hashes

Hashes for rolete-1.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2bad77e1bd05610f33c86e524ac23b00e75bd0d64606809c677934c5e7c0f772
MD5 0b89579010542f958c3bbf5b027cd4b8
BLAKE2b-256 55e7d38ee0095a315542ddb66811289759b0ccb9e7a9f032e676ae720c5042c8

See more details on using hashes here.

Supported by

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