Skip to main content

Plugin for twat that provides package initialization functionality

Project description

twat-hatch

(work in progress)

A powerful Python package initializer that supports both standalone packages and plugin-based architectures. Built with modern Python practices and robust configuration management.

Features

  • ๐ŸŽฏ Flexible package creation: Create standalone packages or plugin-based architectures
  • ๐Ÿ”ง Modern configuration: Type-safe configuration using Pydantic
  • ๐Ÿ“ฆ Multiple package types: Support for core packages and plugins
  • ๐ŸŽจ Templating system: Jinja2-based templating with multiple themes
  • ๐Ÿ“š Documentation support: Optional MkDocs integration
  • ๐Ÿ”„ Version control: Git integration and semantic versioning support
  • โœจ Best practices: Enforces Python packaging best practices

Why twat-hatch?

twat-hatch helps you create modern Python packages with a focus on plugin systems. It implements best practices for:

Modern python packaging

  • PEP 621-style configuration via pyproject.toml
  • src/ layout pattern for better packaging practices
  • Type hints and runtime type checking with Pydantic
  • Automated dependency management

Plugin system architecture

  • Namespace packages: Create plugin host packages that dynamically expose plugins
  • Dynamic discovery: Automatic plugin registration via entry points
  • Flexible usage: Support both direct imports and namespace-based imports
  • Clean dependencies: Proper handling of optional plugin dependencies

Best practices implementation

  • Code organization: Enforced src/ layout and modern project structure
  • Error handling: Built-in validation and error checking
  • Documentation: Automated documentation setup with MkDocs
  • Testing: Pre-configured test structure with pytest
  • Type safety: MyPy configuration and Pydantic validation

Installation

uv pip install twat-hatch

Or with pip:

pip install twat-hatch

Quick start

  1. Create a configuration file twat-hatch.toml:
[project]
packages = ["my-package"]
output_dir = "packages"

[author]
name = "Your Name"
email = "your.email@example.com"
github_username = "yourusername"

[package]
min_python = "3.8"
license = "MIT"
development_status = "4 - Beta"
  1. Run the package initializer:
twat-hatch --config twat-hatch.toml

Creating plugin-based packages

Plugin system overview

When creating a plugin-based architecture, twat-hatch generates:

  1. Plugin host package: The core package that provides plugin discovery and management
  2. Plugin packages: Individual plugins that integrate with the host package

Example configuration:

[project]
packages = ["my-plugin-a", "my-plugin-b"]
plugin_host = "my-core-package"
output_dir = "packages"

# ... other configuration ...

Plugin system usage

Once packages are created, they can be used in several ways:

# Direct import of a plugin
import my_plugin_a
instance = my_plugin_a.SomeClass()

# Via namespace package (if configured)
from my_core_package import plugin_a
instance = plugin_a.SomeClass()

Installation options:

# Install a plugin directly
pip install my-plugin-a

# Install via the host package with extras
pip install my-core-package[plugin-a]

# Install multiple plugins
pip install my-core-package[plugin-a,plugin-b]

# Install all available plugins
pip install my-core-package[all]

Configuration reference

The configuration file ( twat-hatch.toml ) supports the following sections:

Project configuration

[project]
packages = ["package-name"]        # List of packages to create
plugin_host = "host-package"       # Optional plugin host package
output_dir = "path/to/output"      # Output directory (optional)

Author information

[author]
name = "Author Name"
email = "author@example.com"
github_username = "username"

Package settings

[package]
min_python = "3.8"                 # Minimum Python version
license = "MIT"                    # Package license
development_status = "4 - Beta"    # PyPI development status

Dependencies

[dependencies]
dependencies = [                   # Regular dependencies
    "package>=1.0.0"
]
plugin_dependencies = [            # Plugin-specific dependencies
    "plugin-package>=1.0.0"
]
dev_dependencies = [               # Development dependencies
    "pytest>=7.0.0"
]

Features

[features]
mkdocs = false                     # Enable MkDocs documentation
semver = true                      # Use semantic versioning
vcs = true                        # Initialize Git repository

Generated package structure

Standalone package

my-package/
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ pyproject.toml                 # Project configuration
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ my_package/               # Package source
โ”‚       โ”œโ”€โ”€ __init__.py
โ”‚       โ””โ”€โ”€ core.py
โ””โ”€โ”€ tests/                        # Test directory
    โ”œโ”€โ”€ conftest.py
    โ””โ”€โ”€ test_my_package.py

Plugin host package

my-core-package/
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ pyproject.toml
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ my_core_package/
โ”‚       โ”œโ”€โ”€ __init__.py           # Plugin discovery logic
โ”‚       โ””โ”€โ”€ core.py               # Core functionality
โ””โ”€โ”€ tests/
    โ”œโ”€โ”€ conftest.py
    โ””โ”€โ”€ test_my_core_package.py

Plugin package

my-plugin/
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ pyproject.toml                # Includes plugin entry points
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ my_plugin/
โ”‚       โ”œโ”€โ”€ __init__.py
โ”‚       โ””โ”€โ”€ plugin.py             # Plugin implementation
โ””โ”€โ”€ tests/
    โ”œโ”€โ”€ conftest.py
    โ””โ”€โ”€ test_my_plugin.py

Development

To set up the development environment:

git clone https://github.com/twardoch/twat-hatch.git
cd twat-hatch
uv venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
uv pip install -e ".[dev]"

Run tests:

pytest

Run linting:

ruff check .
mypy src/

Technical details

Package naming convention

  • Distribution names use hyphens: my-plugin
  • Import names use underscores: my_plugin
  • Plugin host packages follow the same convention

Plugin discovery

  • Plugins register via entry points under {host}.plugins
  • Plugin host packages support both direct imports and entry point discovery
  • Dynamic loading ensures plugins are only imported when needed

Dependencies management

  • Plugin packages can depend on their host package
  • Host packages define optional dependencies via extras
  • Version compatibility is managed through dependency specifications

Building and publishing

  1. Build and publish the plugin host package first
  2. Build and publish plugin packages separately
  3. Use consistent versioning across packages

License

MIT License, see for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

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

twat_hatch-1.7.0.tar.gz (62.9 kB view details)

Uploaded Source

Built Distribution

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

twat_hatch-1.7.0-py3-none-any.whl (35.1 kB view details)

Uploaded Python 3

File details

Details for the file twat_hatch-1.7.0.tar.gz.

File metadata

  • Download URL: twat_hatch-1.7.0.tar.gz
  • Upload date:
  • Size: 62.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for twat_hatch-1.7.0.tar.gz
Algorithm Hash digest
SHA256 ad1e840381fd4d45518faa221bf7fab8f55cd311fffd60290ed73374e85cefdc
MD5 ad174ddc0fd9ceeda3511a595d1cdd70
BLAKE2b-256 bd5d1d9c87e2663f033cfe05ab28c214935376a7cfa5670b7b3a4e8e22bd2808

See more details on using hashes here.

File details

Details for the file twat_hatch-1.7.0-py3-none-any.whl.

File metadata

  • Download URL: twat_hatch-1.7.0-py3-none-any.whl
  • Upload date:
  • Size: 35.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for twat_hatch-1.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9d0919d51b114d2fffee2f1ac00a1673a4a9a1b308b3cbaaa9d8e0e838305433
MD5 d02a3d0246ab69b32b8419636f7d3690
BLAKE2b-256 e3ff9d3211c48e70c84161d06e54d9cf4aa68f4db8dd69abbf976f19a58a512d

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