A sample Python package with semantic versioning for multiple environments (Production Environment)
Project description
MyPackage
A production-ready Python package demonstrating best practices for packaging, semantic versioning, and multi-environment publishing to PyPI.
Features
This package includes:
- ๐งฎ Calculator: Basic arithmetic operations (add, subtract, multiply, divide)
- ๐ Text Utils: String manipulation functions (capitalize, reverse, count words)
- ๐ Data Processor: List and number processing utilities (filter, sum, statistics)
Multi-Environment Strategy
This package supports three environments with the same version number across all:
| Environment | Package Name | Purpose |
|---|---|---|
| Production | mypackage |
Stable releases for production use |
| QA | mypackage-qa |
Testing and quality assurance |
| Development | mypackage-dev |
Latest development features |
Installation
Production Environment
pip install mypackage
QA Environment
pip install mypackage-qa
Development Environment
pip install mypackage-dev
Quick Start
from mypackage import add, subtract, capitalize_words, filter_even, get_statistics
# Calculator functions
result = add(10, 5) # 15
result = multiply(3, 4) # 12
# Text utilities
text = capitalize_words("hello world") # "Hello World"
reversed_text = reverse_string("Python") # "nohtyP"
# Data processing
evens = filter_even([1, 2, 3, 4, 5]) # [2, 4]
stats = get_statistics([1, 2, 3, 4, 5])
# {'min': 1, 'max': 5, 'mean': 3.0, 'sum': 15, 'count': 5}
Development Setup
Prerequisites
- Python 3.8 or higher
- Poetry (for dependency management)
Installation
- Clone the repository:
git clone https://github.com/yourusername/mypackage.git
cd mypackage
- Install dependencies using Poetry:
poetry install
- Activate the virtual environment:
poetry shell
Running Tests
Run all tests with coverage:
poetry run pytest
Run specific test file:
poetry run pytest tests/test_calculator.py
Code Quality
Format code:
poetry run black src tests scripts
poetry run isort src tests scripts
Run linting:
poetry run flake8 src tests
Type checking:
poetry run mypy src
Run all validations:
python scripts/validate.py
Semantic Versioning
This package follows Semantic Versioning (SemVer):
- MAJOR version for incompatible API changes
- MINOR version for backward-compatible functionality additions
- PATCH version for backward-compatible bug fixes
Bumping Version
Use the provided script to bump versions:
# Bump patch version (0.1.0 -> 0.1.1)
python scripts/bump_version.py patch
# Bump minor version (0.1.0 -> 0.2.0)
python scripts/bump_version.py minor
# Bump major version (0.1.0 -> 1.0.0)
python scripts/bump_version.py major
The version will be automatically updated in:
pyproject.tomlsrc/mypackage/__init__.py- Git tag will be created
Publishing to PyPI
Prerequisites
- Create a PyPI account at https://pypi.org
- Generate an API token from your PyPI account settings
- Configure Poetry with your token:
poetry config pypi-token.pypi <your-token>
Publishing Process
- Validate your package:
python scripts/validate.py
- Bump the version (if needed):
python scripts/bump_version.py [major|minor|patch]
- Publish to specific environment:
# Publish to dev
python scripts/publish.py dev
# Publish to qa
python scripts/publish.py qa
# Publish to prod
python scripts/publish.py prod
# Publish to all environments
python scripts/publish.py all
- Dry run (test without publishing):
python scripts/publish.py all --dry-run
Version Consistency
The same version number is maintained across all three environments (dev, qa, prod). Only the package name differs:
mypackage-devversion 0.1.0mypackage-qaversion 0.1.0mypackageversion 0.1.0
Project Structure
first_python_package/
โโโ src/
โ โโโ mypackage/
โ โโโ __init__.py
โ โโโ calculator.py
โ โโโ text_utils.py
โ โโโ data_processor.py
โโโ tests/
โ โโโ __init__.py
โ โโโ test_calculator.py
โ โโโ test_text_utils.py
โ โโโ test_data_processor.py
โโโ scripts/
โ โโโ bump_version.py
โ โโโ publish.py
โ โโโ validate.py
โโโ .github/
โ โโโ workflows/
โ โโโ ci.yml
โโโ pyproject.toml
โโโ .bumpversion.cfg
โโโ .gitignore
โโโ .pre-commit-config.yaml
โโโ LICENSE
โโโ README.md
API Documentation
Calculator Module
add(a, b)- Add two numberssubtract(a, b)- Subtract b from amultiply(a, b)- Multiply two numbersdivide(a, b)- Divide a by b (raises ValueError if b is zero)
Text Utils Module
capitalize_words(text)- Capitalize first letter of each wordreverse_string(text)- Reverse a stringcount_words(text)- Count words in a string
Data Processor Module
filter_even(numbers)- Filter even numbers from a listsum_list(numbers)- Calculate sum of numbersget_statistics(numbers)- Get min, max, mean, sum, and count
CI/CD Pipeline
The project includes a GitHub Actions workflow that:
- Runs on Python 3.8, 3.9, 3.10, 3.11, and 3.12
- Executes linting and type checking
- Runs all tests with coverage reporting
- Validates the package build
- (Optional) Automatically publishes on version tags
Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run tests and validation (
python scripts/validate.py) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Best Practices Implemented
โ
Poetry for modern dependency management
โ
Semantic Versioning with automated version bumping
โ
Multi-environment support (dev, qa, prod)
โ
Type hints throughout the codebase
โ
Comprehensive test suite with pytest
โ
Code quality tools (black, isort, flake8, mypy)
โ
Pre-commit hooks for automated checks
โ
CI/CD pipeline with GitHub Actions
โ
Detailed documentation with examples
โ
Proper package structure following Python standards
License
This project is licensed under the MIT License - see the LICENSE file for details.
Changelog
See CHANGELOG.md for version history and changes.
Support
For issues and questions:
- ๐ Report bugs
- ๐ก Request features
- ๐ง Email: your.email@example.com
Acknowledgments
This package was created as a demonstration of Python packaging best practices, including:
- Multi-environment deployment strategy
- Semantic versioning
- Modern tooling with Poetry
- Comprehensive testing and validation
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mypackage_prod-0.1.1.tar.gz.
File metadata
- Download URL: mypackage_prod-0.1.1.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b7bc9fcb14d9a51361a13827d6e4994db4837c359a3c6bcdff558713ec93137
|
|
| MD5 |
670864e42f9c7d2ccdec37a54eadea7f
|
|
| BLAKE2b-256 |
f04dfea2a697187c26bd01543f3e4f26e749c1e28984fba00739eba935f6c363
|
File details
Details for the file mypackage_prod-0.1.1-py3-none-any.whl.
File metadata
- Download URL: mypackage_prod-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36acefdcfe8466e11e198a1a321edb4ee45881d6e67482c1921da01f0bd84dc8
|
|
| MD5 |
4209cb57c01d81c35bc2a7a21c9dd992
|
|
| BLAKE2b-256 |
14dfdcae9bd9928e87e7dd07d2088b8d0082b642f5feef163dfb84b8bf717e88
|