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
- Semantic versioning with automated releases
- Dynamic versioning using importlib.metadata
- Automated release script (
commit.py) for easy publishing - Template ready - Use as base for your own Python packages
- Multiple classes - Greeting and Operations functionality
๐ฆ Installation
pip install publish-lib-ghp
๐ง Usage
from publish_lib_ghp import Greeting, Operations
# Create instances
greeting = Greeting()
operations = Operations()
# Basic greeting functionality
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!
# Mathematical operations
result = operations.add(5, 3)
print(result) # Output: 8
๐ ๏ธ 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
Testing
# Run all tests
poetry run pytest
# Run specific test file
poetry run pytest tests/test_greeting.py
poetry run pytest tests/test_operations.py
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
Operations Class
add(a: int, b: int) -> int
Perform addition of two integers.
Parameters:
a(int): The first numberb(int): The second number
Returns:
- int: The sum of a and b
Example:
ops = Operations()
result = ops.add(5, 3) # Returns 8
๐ Release Process
This project uses automated releases via GitHub Actions. Use the included commit.py script for easy releases!
Automated Release (Recommended)
# Use the automated script
python commit.py
The script will:
- Ask for version type (patch, minor, major)
- Ask for commit message
- Update version automatically
- Commit and create tag
- Trigger GitHub Actions to publish
Manual Release
# Update version
poetry version patch # or minor/major
# Commit and tag
git add .
git commit -m "Your commit message"
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 (3.11, 3.12, 3.13)
- Build the package
- Publish to PyPI
๐ Documentation
- Setup Guide - How to use this project as a template
- Release Process - How to create and publish releases
- Publishing Guide - Comprehensive guide for package publishing
- PyPI Setup - PyPI configuration instructions
- 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
โ โโโ __init__.py # Package initialization
โ โโโ greeting.py # Greeting functionality
โ โโโ operations.py # Mathematical operations
โโโ tests/ # Test suite
โ โโโ test_greeting.py # Tests for Greeting class
โ โโโ test_operations.py # Tests for Operations class
โโโ commit.py # Automated release script
โโโ pyproject.toml # Project configuration
โโโ README.md # This file
โโโ SETUP_GUIDE.md # Template usage guide
โโโ CHANGELOG.md # Version history
โโโ LICENSE # MIT License
๐ Security
This project follows security best practices:
- โ No hardcoded secrets or API tokens
- โ Secure publishing to PyPI via GitHub Actions
- โ Automated testing across multiple Python versions
- โ Clean and minimal dependencies
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 tests:
poetry run pytest - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
๐ฏ Using as Template
Want to create your own Python package? See SETUP_GUIDE.md for step-by-step instructions on how to use this project as a template.
๐ 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
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 publish_lib_example-1.1.1.tar.gz.
File metadata
- Download URL: publish_lib_example-1.1.1.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5dea253b40385cd4d03d67b6fc87a7122edc636a103930f882b69a2009ecfc80
|
|
| MD5 |
f9632440de9d3ebf5f7ca417c4def8fd
|
|
| BLAKE2b-256 |
8c899dd79815509652ec868e6687ad2a1415fbef6c7a76aaefe72ed9dde2aabb
|
File details
Details for the file publish_lib_example-1.1.1-py3-none-any.whl.
File metadata
- Download URL: publish_lib_example-1.1.1-py3-none-any.whl
- Upload date:
- Size: 6.2 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 |
5e809d755e8619cb680b5d742cdd911390a377a1cc2e4a0e2b1c7a7cbfb957ff
|
|
| MD5 |
2dab9c97b908344594e3e0cceb0a1eb6
|
|
| BLAKE2b-256 |
5f9daa328abf3c3a3fc6278ba3a681be8c39a49cf8e080c1974981d72f0820ce
|