PyProtoLoader
PyProtoLoader is a utility for dynamically loading Python modules from specified directories and retrieving classes that implement a given protocol (PEP 544). It is especially useful for plugin systems, dynamic class discovery, and protocol-based architectures.
Features
- Dynamically load Python modules from one or more directories
- Retrieve classes that implement a specified protocol (including runtime-checkable protocols)
- Reload modules on demand
- Simple API for integration into larger projects
Installation
PyProtoLoader is a pure Python package. Install from PyPI.
pip install pyprotoloader
Usage
1. Basic Example
from pyprotoloader import PyProtoLoader
from typing import Protocol, runtime_checkable
@runtime_checkable
class MyProtocol(Protocol):
def foo(self): ...
# Initialize loader with a list of directories to search
loader = PyProtoLoader(["/path/to/plugins"])
# Load a module by name (without .py extension)
module = loader.load_module("plugin_module")
# Retrieve the class implementing the protocol
cls = loader.get_protocol_class(module, MyProtocol)
# Instantiate and use
instance = cls()
instance.foo()
2. With Class Name
cls = loader.get_protocol_class(module, MyProtocol, class_name="MyClass")
API
PyProtoLoader(paths: List[str])
Initializes the loader with a list of directory paths to search for .py files.
load_module(module_name: str, reload: bool = False)
Loads a module by name. Optionally reloads if already loaded.
get_protocol_class(module, protocol, class_name=None)
Retrieves the first class in the module that implements the given protocol. Optionally specify a class name.
Testing
Unit tests are provided in the tests/ directory. To run tests:
python3 -m unittest discover -s tests
License
This project is licensed under the terms of the MIT license. See the LICENSE file for details.
Metadata
Release files for pyprotoloader 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyprotoloader-1.0.1.tar.gz | 2.5 kB | Without provenance | Details for pyprotoloader-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyprotoloader-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for pyprotoloader-1.0.1-py3-none-any.whl |
Total release size: 6.0 kB
Release files / pyprotoloader-1.0.1.tar.gz
| Download URL | pyprotoloader-1.0.1.tar.gz |
|---|---|
| Size | 2.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3a54893e36a9a0757c384de74ba4e76d4ac2b68e8e1cb4e92bbdd8405929c77b
|
|
BLAKE2b-256 checksum How to use checksums |
3313bcc5172c46a02b3ea9b6515b076457327d9b6114b28e7ef7e4cf4a67e6d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / pyprotoloader-1.0.1-py3-none-any.whl
| Download URL | pyprotoloader-1.0.1-py3-none-any.whl |
|---|---|
| Size | 3.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3c864698c4c25b20e2039de00fff45bdb927641bb3753dfc79eb3d3f7e675226
|
|
BLAKE2b-256 checksum How to use checksums |
6ee080fe306a1e2884f1111457e8b93105275437d0ad41b1bc3462b6e8f5c943
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for pyprotoloader 1.0.1
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.