Skip to main content

Introduction

Python Package Cookiecutter Code to help make faster libraries. The objective of this repo is to concentrate on developing source code by standardizing the ecosystem of tools for development

Summary

Writing code helps us solve a business problem. However writing good code will make it reusable. Writing good code with tests around it will help convert the code into a python library (or module or package) usable by fellow team members or to the open source community.

A developer will want to go through this process in a seamless manner. This article and repo will define a proven process and provide guidelines to write a python library.

#TODO

  • Convert library to a cookiecutter template. Helps parametrize the library name.
  • Use GitHub actions to include testing, test coverage etc.

For library guidance on a typical data science, see see for data science projects

Usage

The recommended practices for developing python libraries are given below:

https://realpython.com/pypi-publish-python-package/

Using toml file, bumpver and twine

Step Description Commands/Detailed Description Reference
1 Create python project with directory structure Follow pep8 guidelines https://www.freecodecamp.org/news/build-your-first-python-package/
2 Package compliance Ensure all directories are package modules using init.py https://www.freecodecamp.org/news/build-your-first-python-package/
3 Add .toml file and setup.py to build wheels pip install bumpver
bumpver update --patch
pip install build
python -m build
https://realpython.com/pypi-publish-python-package/
4 Create account on pypi and upload using twine package These commands will push the .whl and .tar.gz file into the pypi repository
conda install twine
twine upload dist/*
https://realpython.com/pypi-publish-python-package/

To see instructions using setup.py & twine, without Version Bump, see using setup.py

CI

More CI/CD streamlining for python packages:

  • use cookiecutter to generate a package template
  • set up travis CI for auto deployment of package to pypi

#TODO

  • Convert library to a cookiecutter template. Helps parametrize the library name.

https://github.com/audreyfeldroy/cookiecutter-pypackage https://cookiecutter-pypackage.readthedocs.io/en/latest/tutorial.html https://pypi.org/project/cookiecutter/

https://github.com/boromir674/cookiecutter-python-package https://github.com/boromir674/cookiecutter-python-package/tox.ini

https://youtu.be/ugGu8fHWFog (A data science project example folder)

Github

Helps cover testing, test coverage, etc. https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python https://hynek.me/articles/python-github-actions/

Travis CI, No Free Support?

https://jacobtomlinson.dev/posts/2021/testing-and-continuous-integration-for-python-packages-with-github-actions/

https://github.com/ksator/continuous-integration-with-python

https://medium.com/swlh/automate-python-testing-with-github-actions-7926b5d8a865

Testing a Package Locally

Using .toml file (Working)

A package can be imported locally from another code and thoroughly tested as well if required. Editable install is the best way to achieve this. The steps to do so are:

  • Change to the current working directory where the pyproject.toml file is located
  • Execute the following command to install the package locally
    • python -m pip install -e .
  • This installation uses the files in the current working directory

Using conda-build (Did not work)

Building A Package Locally

Writing Tests

References

https://www.freecodecamp.org/news/build-your-first-python-package/

https://python-packaging-tutorial.readthedocs.io/en/latest/setup_py.html

https://packaging.python.org/

Guidelines to contribute to libraries: https://pandas.pydata.org/docs/development/contributing.html#contributing

https://realpython.com/pypi-publish-python-package/

https://github.com/johnthagen/python-blueprint

Metadata

Release files for pyproject-starter 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyproject-starter 0.0.2
File Size Uploaded Provenance Actions
pyproject_starter-0.0.2.tar.gz 321.1 kB Without provenance Details for pyproject_starter-0.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyproject-starter 0.0.2
File Interpreter ABI Platform Actions
pyproject_starter-0.0.2-py3-none-any.whl Python 3 none any Details for pyproject_starter-0.0.2-py3-none-any.whl

Total release size: 327.4 kB

Release files / pyproject_starter-0.0.2.tar.gz

Download URL pyproject_starter-0.0.2.tar.gz
Size 321.1 kB
Tags Source
SHA-256 checksum
How to use checksums
2f234972e53394291c8d8aebce24eb5b0a3d93bd0a1e0f1d83ce8ce439978e5e
BLAKE2b-256 checksum
How to use checksums
b82d2b682da1f9c6e86fecaed1eb14af858c8eb90d81217469f7a295bcb6ea94
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Release files / pyproject_starter-0.0.2-py3-none-any.whl

Download URL pyproject_starter-0.0.2-py3-none-any.whl
Size 6.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3a445bb5583c623cf260346c4960c20dacf7ea35e2ae26dbae454ac1152900fe
BLAKE2b-256 checksum
How to use checksums
676ddfa46293e1b73d597ac23167fb86c03451c153f476a762dcc3ba07f73725
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Security for pyproject-starter 0.0.2

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.

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page