Somepackage
Show how to structure a Python project.
Inspired by https://github.com/kennethreitz/samplemod.
Great resources
Recommendations
Please browse this blog post for a good summary of recommendatios and templates: https://medium.com/@jonas.r.kemper/understanding-best-practice-python-tooling-by-comparing-popular-project-templates-6eba49229106
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
Test all non-trivial code. I recommend to use https://pytest.org.
Use Travis CI: https://docs.travis-ci.com/user/languages/python/.
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
Follow PEP8: https://www.python.org/dev/peps/pep-0008/
Use pycodestyle to automatically check for PEP8.
Type checking
Consider using type hints: https://docs.python.org/3/library/typing.html
Consider using http://mypy-lang.org.
Consider verifying type annotations at runtime: https://github.com/RussBaz/enforce
Documentation
I used to recommend reStructuredText for READMEs in contrast to Markdown but PyPI no longer requires reStructuredText. You can use Markdown as noted on https://pypi.org/help/ under “How can I upload a project description in a different format?”.
Example shown here: https://packaging.python.org/tutorials/packaging-projects/#creating-setup-py
Suggestions? Corrections? Pull requests?
Yes please!
Metadata
Release files for cchmtest 1.2.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cchmtest-1.2.4.tar.gz | 9.3 kB | Without provenance | Details for cchmtest-1.2.4.tar.gz |
Release files / cchmtest-1.2.4.tar.gz
| Download URL | cchmtest-1.2.4.tar.gz |
|---|---|
| Size | 9.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
81eb64479c1cceee5ce1e0b9786b1620d89b43486f7da1b2bd41acc3eb9c899a
|
|
BLAKE2b-256 checksum How to use checksums |
395b8c5bba6c344af7c321cfde33bbfccf104051d8766811f01585e7df8a1e5e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6
|
Security for cchmtest 1.2.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.