Skip to main content

A simple Python library demonstrating how to publish packages to PyPI

Project description

publish-lib-ghp

PyPI version Python versions Tests License: MIT

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

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 greet
  • time_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 number
  • b (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:

  1. Ask for version type (patch, minor, major)
  2. Ask for commit message
  3. Update version automatically
  4. Commit and create tag
  5. 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:

  1. Run tests across multiple Python versions (3.11, 3.12, 3.13)
  2. Build the package
  3. Publish to PyPI

๐Ÿ“ Documentation

๐Ÿ—๏ธ 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

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make your changes and add tests
  4. Run tests: poetry run pytest
  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

๐ŸŽฏ 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

๐Ÿ“Š 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

publish_lib_ghp-0.2.8.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

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

publish_lib_ghp-0.2.8-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file publish_lib_ghp-0.2.8.tar.gz.

File metadata

  • Download URL: publish_lib_ghp-0.2.8.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

Hashes for publish_lib_ghp-0.2.8.tar.gz
Algorithm Hash digest
SHA256 46ac549758fd09b8df192a65b8b8836ae1a4d5a68b25409d93cc60eecdc17d5c
MD5 1a301383050d429b03116152e3c2dd33
BLAKE2b-256 c98608d6c8cb80e69d55ba474ecdad1b5ae982b300e447142b42d2c2adbbe1bd

See more details on using hashes here.

File details

Details for the file publish_lib_ghp-0.2.8-py3-none-any.whl.

File metadata

File hashes

Hashes for publish_lib_ghp-0.2.8-py3-none-any.whl
Algorithm Hash digest
SHA256 73cea13c9170bd62400c88c8514e3b89853e5386ecc0a876b506051c4a371058
MD5 9dc92c05bbf7bb8ca5c749ff4174254e
BLAKE2b-256 720fb92d0f899b64533e1e0c914b08e70f15aa68d1cc5617ce9c51f7726c6b39

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