Skip to main content

Python Package Cookiecutter Code

Project description

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

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

pyproject_starter-0.0.2.tar.gz (321.1 kB view details)

Uploaded Source

Built Distribution

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

pyproject_starter-0.0.2-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file pyproject_starter-0.0.2.tar.gz.

File metadata

  • Download URL: pyproject_starter-0.0.2.tar.gz
  • Upload date:
  • Size: 321.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for pyproject_starter-0.0.2.tar.gz
Algorithm Hash digest
SHA256 2f234972e53394291c8d8aebce24eb5b0a3d93bd0a1e0f1d83ce8ce439978e5e
MD5 6f9df51cce6cccbf28af6144d24b5a5d
BLAKE2b-256 b82d2b682da1f9c6e86fecaed1eb14af858c8eb90d81217469f7a295bcb6ea94

See more details on using hashes here.

File details

Details for the file pyproject_starter-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for pyproject_starter-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3a445bb5583c623cf260346c4960c20dacf7ea35e2ae26dbae454ac1152900fe
MD5 2731e392b9485bb1c8f3992b3689e346
BLAKE2b-256 676ddfa46293e1b73d597ac23167fb86c03451c153f476a762dcc3ba07f73725

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