python-package-boilerplate
Current version: 0.1.1
Boilerplate for a Python Package
Package
Basic structure of package is
├── README.md
├── package
│ ├── __init__.py
│ ├── package.py
│ └── version.py
├── pytest.ini
├── requirements.txt
├── setup.py
└── tests
├── __init__.py
├── helpers
│ ├── __init__.py
│ └── my_helper.py
├── tests_helper.py
└── unit
├── __init__.py
├── test_example.py
└── test_version.py
Requirements
Package requirements are handled using pip. To install them do
pip install -r requirements.txt
Setup
To set up your package, ensure you have the necessary files and directories as shown in the package structure above. Specifically, you'll need:
README.md: This file.package/: Directory containing your package's main code.tests/: Directory containing your tests.
Setup Commands
-
Install the package:
pip install . -
Install the package in editable mode (for development):
pip install -e . -
Upload to PyPI:
python setup.py sdist twine upload dist/*
Tests
Testing is set up using pytest and coverage is handled with the pytest-cov plugin.
Running Tests
Run your tests with:
pytest
in the root directory.
Coverage
Coverage is run by default and is set in the pytest.ini file. To see an HTML output of coverage, open htmlcov/index.html after running the tests.
Continuous Integration
GitHub Actions (Optional)
If you prefer GitHub Actions for CI, you can set it up with a .github/workflows/ci.yml file. Here’s a basic example:
name: Deploy Python Package
on:
push:
branches: [ "master" ]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
pip install bump2version twine wheel
- name: Bump version
id: bumpversion
run: |
source venv/bin/activate
git config --global user.email "dev@runners.im"
git config --global user.name "Runners"
bump2version patch --allow-dirty
git push --follow-tags
- name: Build package
run: |
source venv/bin/activate
python setup.py sdist bdist_wheel
- name: Deploy package
run: |
source venv/bin/activate
twine upload --verbose dist/*
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
This will set up CI for multiple Python versions and upload the coverage report to Codecov.
License
Specify your package's license. For example:
MIT License
Contribution Guidelines
If you want others to contribute to your package, add contribution guidelines. For example:
- Fork the repository.
- Create a new branch (
git checkout -b feature-foo). - Commit your changes (
git commit -am 'Add feature foo'). - Push to the branch (
git push origin feature-foo). - Create a new Pull Request.
Feel free to customize this boilerplate according to your specific needs.
Metadata
Release files for python-package-boilerplate 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| python-package-boilerplate-0.1.1.tar.gz | 4.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| python_package_boilerplate-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.1 kB
Release files / python-package-boilerplate-0.1.1.tar.gz
| Download URL | python-package-boilerplate-0.1.1.tar.gz |
|---|---|
| Size | 4.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
019b36e16bb1b15b4696d42445848b263b9821dc53794f12b47c4979055356ae
|
|
BLAKE2b-256 checksum How to use checksums |
c247f6fe35f2ee482da2d40bccd41bddaa4213afbd8638be5340e8396a60a18c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.8.18
|
Release files / python_package_boilerplate-0.1.1-py3-none-any.whl
| Download URL | python_package_boilerplate-0.1.1-py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7c9021c1049886f18d35804e5ea76475aa1bbc3beab44f8061bc58a2b78127d1
|
|
BLAKE2b-256 checksum How to use checksums |
83240587f2e826d61ee4ce72d6c4facd1e19d6195d7e8b330989876299451b6f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.8.18
|