Skip to main content

python-providerkit

ProviderKit is a generic provider management library for Python. It provides a standardized way to manage, discover, and interact with multiple service providers in a unified manner.

Installation

pip install providerkit

For development:

pip install -e .
pip install -e ".[dev,lint,quality,security,test]"

Usage

ProviderKit provides a mixin-based architecture for creating and managing providers.

Basic Usage

from providerkit import ProviderBase, get_providers

# Load providers from various sources
providers = get_providers(json="providers.json")
# or
providers = get_providers(dir_path="path/to/providers")
# or
providers = get_providers(config=[{"class": "mypackage.providers.MyProvider", "config": {...}}])

# Use providers
for name, provider in providers.items():
    print(f"{provider.display_name}: {provider.name}")

Creating a Provider

Create a provider by inheriting from ProviderBase:

from providerkit import ProviderBase

class EmailProvider(ProviderBase):
    name = "email"
    display_name = "Email Provider"
    description = "Sends emails via SMTP"
    
    def __init__(self, **kwargs):
        super().__init__(
            name="email",
            display_name="Email Provider",
            description="Sends emails via SMTP",
            **kwargs
        )

Provider Discovery

ProviderKit can automatically discover providers from directories:

from providerkit import autodiscover_providers

# Discover providers from a directory
providers = autodiscover_providers("path/to/providers", base_module="mypackage.providers")

Loading from JSON

Create a JSON file with provider configurations:

{
  "providers": [
    {
      "class": "mypackage.providers.EmailProvider",
      "config": {
        "smtp_host": "smtp.example.com",
        "smtp_port": 587
      }
    }
  ]
}

Load it:

from providerkit import load_providers_from_json

providers = load_providers_from_json("providers.json")

Loading from Configuration

from providerkit import load_providers_from_config

config = [
    {
        "class": "mypackage.providers.EmailProvider",
        "config": {"smtp_host": "smtp.example.com"},
        "kwargs": {}
    }
]

providers = load_providers_from_config(config)

Provider Mixins

ProviderKit uses a mixin-based architecture. All mixins are automatically included in ProviderBase:

  • PackageMixin: Package dependency management and validation
  • ConfigMixin: Configuration management and validation
  • ServiceMixin: Business logic implementation and service methods
  • UrlsMixin: URL routing and endpoint management (if applicable)

Architecture

ProviderKit uses a mixin-based architecture:

  • Each provider inherits from ProviderBase which combines all mixins
  • Mixins are organized in dedicated files for clear separation of concerns
  • Providers can be discovered, queried, and used programmatically
  • The system validates dependencies and configuration before allowing provider usage

Project Structure

python-providerkit/
├── src/providerkit/          # Main package
│   ├── kit/                  # Core provider infrastructure
│   │   ├── __init__.py       # ProviderBase class
│   │   ├── package.py        # PackageMixin
│   │   ├── config.py         # ConfigMixin
│   │   ├── service.py        # ServiceMixin
│   │   └── urls.py           # UrlsMixin
│   ├── providers/            # Provider implementations
│   ├── helpers/              # Utility functions
│   └── cli.py                # CLI interface
├── tests/                    # Test suite
└── docs/                     # Documentation

CLI System

ProviderKit includes a flexible CLI system that discovers commands from:

  1. commands/ directory: A directory next to cli.py containing command modules
  2. .commands.json configuration file: A JSON file that can specify:
    • packages: List of packages to discover commands from
    • directories: List of directories to scan for commands
    • commands: Direct command definitions

Creating Commands

Commands can be created in two ways:

Method 1: Using the Command class

Create a file in the commands/ directory (e.g., commands/mycommand.py):

from .base import Command

def _mycommand_command(args: list[str]) -> bool:
    """Description of what this command does."""
    # Command implementation
    print("Hello from mycommand!")
    return True

mycommand_command = Command(_mycommand_command, "Description of what this command does")

Method 2: Using functions ending with _command

def mycommand_command(args: list[str]) -> bool:
    """Description of what this command does."""
    # Command implementation
    print("Hello from mycommand!")
    return True

Command Structure

Commands receive a list of string arguments and return a boolean indicating success:

def mycommand_command(args: list[str]) -> bool:
    """Command description for help text."""
    if not args:
        print("Usage: mycommand <arg1> <arg2>")
        return False
    
    # Process arguments
    arg1 = args[0]
    # ... command logic ...
    
    return True  # Success

Environment Variables

ENVFILE_PATH

The ENVFILE_PATH environment variable allows you to automatically specify the path to a .env file to load when starting services.

Usage:

# Absolute path
ENVFILE_PATH=/path/to/.env ./service.py dev install-dev

# Relative path (relative to project root)
ENVFILE_PATH=.env.local ./service.py quality lint

Behavior:

  • If the path is relative, it is resolved relative to the project root
  • The .env file is automatically loaded before command execution
  • Uses python-dotenv to parse the file (installed automatically if needed)
  • Works with dev and cli services

ENSURE_VIRTUALENV

The ENSURE_VIRTUALENV environment variable allows you to automatically activate the .venv virtual environment if it exists, before executing commands.

Usage:

ENSURE_VIRTUALENV=1 ./service.py dev help
ENSURE_VIRTUALENV=1 ./service.py quality lint

Behavior:

  • Must be set to 1 to be active
  • Automatically activates the .venv virtual environment at the project root
  • Modifies sys.executable, PATH, and sys.path to use the venv's Python
  • Only works if the .venv directory exists
  • Compatible with Windows and Unix

Note: The ensure_virtualenv() function is also automatically called by the main service, but ENSURE_VIRTUALENV allows you to force activation even in contexts where it might not be automatic.

Use Cases

  • Multi-provider integrations (email, SMS, payment, etc.)
  • Provider fallback mechanisms
  • Provider discovery and selection
  • Configuration validation across multiple providers
  • Unified interface for heterogeneous services

Development

ProviderKit uses clicommands for the CLI. See docs/ for project rules and guidelines.

Metadata

Release files for providerkit 1.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for providerkit 1.1.2
File Size Uploaded Provenance
providerkit-1.1.2.tar.gz 24.6 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for providerkit 1.1.2
File Interpreter ABI Platform
providerkit-1.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 52.0 kB

Release files / providerkit-1.1.2.tar.gz

Download URL providerkit-1.1.2.tar.gz
Size 24.6 kB
Tags Source
SHA-256 checksum
How to use checksums
2b104e75145fd33b5e3443945aaf513495af2b8b22c74f159cb4c705202ea69e
BLAKE2b-256 checksum
How to use checksums
52b2d5998e82852a408c4efc70ff3d44d0d3f947b07bac5d99513f8a7ad3448e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 27, 2026.

Transparency log

Release files / providerkit-1.1.2-py3-none-any.whl

Download URL providerkit-1.1.2-py3-none-any.whl
Size 27.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f99c9cd136a7bffaa124293c9729c43b950f637358666d4e41882ffd29e549ed
BLAKE2b-256 checksum
How to use checksums
2b9db8db2f22b860b169d6a14f3aa9b5e0285d4fa535f977ee8edb5cc027e41a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 27, 2026.

Transparency log

Security for providerkit 1.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for providerkit-1.1.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 27, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page