Skip to main content

A sample Python package with semantic versioning for multiple environments (QA 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_qa-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_qa-0.2.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mypackage_qa-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_qa-0.2.0.tar.gz
Algorithm Hash digest
SHA256 6a7ebfa454cbf07ae638ec182b7ec6b6ebaa025bfc8e46f4f6bb8a06c49ead4f
MD5 52ff09613a82ee7d6c00bc30f49a4ac9
BLAKE2b-256 4163e4c44d8f08239fd99b567f8bd5295ebcfbfdde3764abe13125730ec467c2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mypackage_qa-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_qa-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 82a82b09d83b90c4771f3ef2e8356ff2942cd46fd9b1e5a36d8a152983af7b43
MD5 59f9c20b6fdc7ffa60f058ee9b600c67
BLAKE2b-256 c3cc3b21525ee49134dbb65defc05fba957112169643fbc7eb87dfaf44042d5d

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