Skip to main content

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.

CI/CD PyPI version Python versions License: MIT

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

  1. Clone the repository:
git clone https://github.com/yourusername/mypackage.git
cd mypackage
  1. Install dependencies using Poetry:
poetry install
  1. 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.toml
  • src/mypackage/__init__.py
  • Git tag will be created

Publishing to PyPI

Prerequisites

  1. Create a PyPI account at https://pypi.org
  2. Generate an API token from your PyPI account settings
  3. Configure Poetry with your token:
poetry config pypi-token.pypi <your-token>

Publishing Process

  1. Validate your package:
python scripts/validate.py
  1. Bump the version (if needed):
python scripts/bump_version.py [major|minor|patch]
  1. 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
  1. 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-dev version 0.1.0
  • mypackage-qa version 0.1.0
  • mypackage version 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 numbers
  • subtract(a, b) - Subtract b from a
  • multiply(a, b) - Multiply two numbers
  • divide(a, b) - Divide a by b (raises ValueError if b is zero)

Text Utils Module

  • capitalize_words(text) - Capitalize first letter of each word
  • reverse_string(text) - Reverse a string
  • count_words(text) - Count words in a string

Data Processor Module

  • filter_even(numbers) - Filter even numbers from a list
  • sum_list(numbers) - Calculate sum of numbers
  • get_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

Documentation

Comprehensive guides are available for all aspects of this project:

Getting Started

Development Workflow

Deployment & Publishing

Architecture & Design

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Run tests and validation (python scripts/validate.py)
  5. Commit your changes (git commit -m 'Add amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. 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:

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mypackage_prod-0.2.0.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

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

mypackage_prod-0.2.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file mypackage_prod-0.2.0.tar.gz.

File metadata

  • Download URL: mypackage_prod-0.2.0.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for mypackage_prod-0.2.0.tar.gz
Algorithm Hash digest
SHA256 19db90b1fcfcd46f2d91ba14c343def90ecc607709119d1c980b44402c978ae7
MD5 8aa7267d2286f6c36b17ce5ecbbb8e9d
BLAKE2b-256 cc584f1ef8f69bed1eb49a70025539ba61bd6da56967dc512a3aa70b2d02d543

See more details on using hashes here.

File details

Details for the file mypackage_prod-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: mypackage_prod-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for mypackage_prod-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 93f25c3bbd0eff2c81f2084ba761ea85d32b97e350d98555ffdf6b67739f1c79
MD5 77a9265621b0ce8dcbbddad352fce8c4
BLAKE2b-256 e37d7a9e6c4b3df52be7e2fcab5f524538f5e9c34d98b56fe962b39de99a2844

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