Skip to main content

A minimal Python project demonstrating best practices for testing, documentation, and CI/CD. It implements a mini calculator as a minimal example.

Project description

CI Docs PyPI Version TestPyPI Version Python License: MIT

python-project-template — showcasing good software practices

python-project-template is a small python project to showcase good programming and software practices such as testing, documentation, CI/CD.

This project implements a small dependence-free Calculator API (Operation, OperationRegistry, Calculator) that can register and compose simple mathematical operations.

Table of contents

Features Highlights

  • Type-annotated API with runtime argument validation.
  • Custom exceptions for clear error reporting.
  • Comprehensive unit tests using pytest.
  • Google-style documentation auto-generated with Sphinx.
  • Pre-commit checks and code formatting tools.
  • CI/CD pipelines for testing and docs via GitHub Actions.

See the Documentation for a detailed list of features.

Installation

To install the latest release from TestPyPI, use:

pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple python-project-template-AS

Alternatively, you can clone the repository and install dependencies and an editable installation of python-project-template-AS with:

git clone <https://github.com/andreascaglioni/python-project-template-AS>
cd python-project-template
pip install -e ".[dev]"

Usage and Testing

The following is a quick example for the Calculator API.

from python_project_template_AS import default_calculator, Operation

# Create a default calculator (pre-populated with common operations)
calc = default_calculator()

# Apply an addition operation
print(calc.apply('add', 2, 3))  # -> 5

# Compose unary operations into a Callable
f = calc.compose(['neg', 'sqr'])
print(f(-3))  # -> 9

# Register a custom operation
def inc(x):
    return x + 1

calc.register(Operation('inc', inc, arity=1), replace=True)
print(calc.apply('inc', 4))  # -> 5

Find more examples in examples/.

To run the tests:

pytest tests/
pytest -v tests/  # verbose output
pytest --cov=python_project_template_AS tests/  # show test coverage

Documentation

For detailed documentation, please visit our GitHub Pages.

Contributing

Contributions are welcome. Typical workflow:

git checkout -b feat/your-feature
# make changes
pytest  # run tests locally
git add -A && git commit -m "Add feature"
git push --set-upstream origin feat/your-feature
# open a PR

Run pip install -e .[dev] to get development tools (pre-commit, black, ruff, mypy, pytest, ...). Run the pre-commit routine with pre-commit run --all-files before committing.

License

This project is licensed under the MIT License — see the LICENSE file.

Questions

If you have questions or want help extending the project (docs, CI, or examples), open an issue or drop a message in the repository.

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_project_template_as-0.1.1.tar.gz (14.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_project_template_as-0.1.1-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file python_project_template_as-0.1.1.tar.gz.

File metadata

File hashes

Hashes for python_project_template_as-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7216a09b710d0b8cd74d71019226023ec59129d56a8f5395758e59b77295b9ff
MD5 998bd5a5b83b92eeaa4697f0964e7291
BLAKE2b-256 0b325e9711e2578e859d5782b6105b442b670a45d351e9a4bf7ff7309eedf336

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_project_template_as-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 881148249a4742a73343b950ca9e8ac94c167fe30ccdf1b3e4b54d7b14a608e2
MD5 fd9f44d1ed1108ca90ec0962acce8775
BLAKE2b-256 203a638752b1346eb4da458de5d620d5315d8031c5bc6a9e74073c2c85b80947

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