Skip to main content

A boilerplate Python package for easy project setup

Project description

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

  1. Install the package:

    pip install .
    
  2. Install the package in editable mode (for development):

    pip install -e .
    
  3. 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.

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

python-package-boilerplate-0.1.1.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

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

python_package_boilerplate-0.1.1-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file python-package-boilerplate-0.1.1.tar.gz.

File metadata

File hashes

Hashes for python-package-boilerplate-0.1.1.tar.gz
Algorithm Hash digest
SHA256 019b36e16bb1b15b4696d42445848b263b9821dc53794f12b47c4979055356ae
MD5 30a716c88a51763a80b7ed4d2480a26f
BLAKE2b-256 c247f6fe35f2ee482da2d40bccd41bddaa4213afbd8638be5340e8396a60a18c

See more details on using hashes here.

File details

Details for the file python_package_boilerplate-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for python_package_boilerplate-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7c9021c1049886f18d35804e5ea76475aa1bbc3beab44f8061bc58a2b78127d1
MD5 189c52ade7519626b069c383f6146c9f
BLAKE2b-256 83240587f2e826d61ee4ce72d6c4facd1e19d6195d7e8b330989876299451b6f

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