A simple Python library demonstrating how to publish packages to PyPI
Project description
publish-lib-ghp
A professional Python library demonstrating best practices for packaging and publishing to PyPI using modern tools and automated CI/CD.
๐ Features
- Professional packaging with Poetry and pyproject.toml
- Automated CI/CD with GitHub Actions
- Comprehensive testing with pytest and coverage reporting
- Code quality enforcement with Black, isort, flake8, and mypy
- Trusted publishing to PyPI (no API tokens required)
- Semantic versioning with automated releases
- Dynamic versioning using importlib.metadata
- Security scanning with bandit
- Pre-commit hooks for code quality
๐ฆ Installation
pip install publish-lib-ghp
๐ง Usage
from publish_lib_ghp import Greeting
# Create a greeting instance
greeting = Greeting()
# Basic hello
message = greeting.say_hello("World")
print(message) # Output: Hello, World!
# Time-specific greetings
morning_msg = greeting.get_greeting_with_time("Alice", "morning")
print(morning_msg) # Output: Good morning, Alice!
# Say goodbye
goodbye_msg = greeting.say_goodbye("Bob")
print(goodbye_msg) # Output: Goodbye, Bob!
๐ ๏ธ Development
Prerequisites
- Python 3.11+
- Poetry
Setup
# Clone the repository
git clone https://github.com/ghpascon/publish_lib_ghp.git
cd publish_lib_ghp
# Install dependencies
poetry install
# Install pre-commit hooks
poetry run pre-commit install
Testing
# Run all tests
poetry run pytest
# Run tests with coverage
poetry run pytest --cov=src/publish_lib_ghp --cov-report=html
# Run specific test file
poetry run pytest tests/test_greeting.py
Code Quality
# Format code
poetry run black src tests
poetry run isort src tests
# Lint code
poetry run flake8 src tests
# Type checking
poetry run mypy src
# Run all quality checks
poetry run pre-commit run --all-files
Building
# Build the package
poetry build
# Check the build
poetry run twine check dist/*
๐ API Reference
Greeting Class
say_hello(name: str) -> str
Say hello to someone.
Parameters:
name(str): The name of the person to greet
Returns:
- str: A greeting message
Raises:
- ValueError: If name is empty or not a string
say_goodbye(name: str) -> str
Say goodbye to someone.
Parameters:
name(str): The name of the person to say goodbye to
Returns:
- str: A goodbye message
Raises:
- ValueError: If name is empty or not a string
get_greeting_with_time(name: str, time_of_day: str) -> str
Get a time-specific greeting.
Parameters:
name(str): The name of the person to greettime_of_day(str): Time of day ('morning', 'afternoon', 'evening')
Returns:
- str: A time-specific greeting message
Raises:
- ValueError: If name is invalid or time_of_day is not recognized
๐ Release Process
This project uses automated releases via GitHub Actions. See RELEASE.md for detailed instructions.
Quick Release
# Update version
poetry version patch # or minor/major
# Commit and tag
git add pyproject.toml
git commit -m "Bump version to v$(poetry version --short)"
git push origin main
git tag "v$(poetry version --short)"
git push origin "v$(poetry version --short)"
The CI/CD pipeline will automatically:
- Run tests across multiple Python versions
- Perform code quality checks
- Build the package
- Publish to PyPI
๐ Documentation
- Release Process - How to create and publish releases
- Publishing Guide - Comprehensive guide for package publishing
- Contributing - How to contribute to this project
- Security Policy - Security guidelines and reporting
- Changelog - Project history and changes
๐๏ธ Project Structure
publish_lib_ghp/
โโโ .github/
โ โโโ workflows/ # GitHub Actions CI/CD pipelines
โโโ src/
โ โโโ publish_lib_ghp/ # Main package code
โโโ tests/ # Test suite
โโโ pyproject.toml # Project configuration (single source of truth)
โโโ README.md # This file
โโโ CHANGELOG.md # Version history
โโโ RELEASE.md # Release process guide
โโโ PUBLISHING.md # Publishing guide
โโโ CONTRIBUTING.md # Contribution guidelines
โโโ SECURITY.md # Security policy
โโโ LICENSE # MIT License
๐ Security
This project follows security best practices:
- โ No hardcoded secrets or API tokens
- โ Trusted publishing to PyPI via GitHub Actions
- โ Automated security scanning with bandit
- โ Dependency vulnerability checking
- โ Code signing and verification
See our Security Policy for details.
๐ค Contributing
We welcome contributions! Please see our Contributing Guide for details.
Quick Start
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes and add tests
- Run quality checks:
poetry run pre-commit run --all-files - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- Poetry for modern Python packaging
- GitHub Actions for CI/CD
- PyPI for package distribution
- pytest for testing framework
๐ Project Status
- โ Active Development: This project is actively maintained
- โ Production Ready: Suitable for production use
- โ Well Tested: Comprehensive test coverage
- โ Documented: Complete documentation available
- โ Secure: Follows security best practices
Author: Gabriel Henrique Pascon
Email: gh.pascon@gmail.com
GitHub: @ghpascon
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
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 publish_lib_ghp-0.1.6.tar.gz.
File metadata
- Download URL: publish_lib_ghp-0.1.6.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f7770551f9d2e2fac6e31aa157f74fe4b50a5f64082a2ebdc32d2dfba7351a70
|
|
| MD5 |
35883f60eafa1299da9306fbf76a47e8
|
|
| BLAKE2b-256 |
4a24296a76ab7e35a29a6a2ad092b09eb050be6b40fb6564c3549095dda8633d
|
File details
Details for the file publish_lib_ghp-0.1.6-py3-none-any.whl.
File metadata
- Download URL: publish_lib_ghp-0.1.6-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
af35ced286282ff0a4f2232d4e9c4e7652b6cc92d72de83bf70231fba6db3e78
|
|
| MD5 |
7dcdb1258e6929e3a3e23f89bb9afb2b
|
|
| BLAKE2b-256 |
82f4571cd37dfd51038d69090a0e140d211b74805cfd6f820ab5c66d363f5fc6
|