Add your description here
Project description
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.
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 pyprotoloader-1.0.1.tar.gz.
File metadata
- Download URL: pyprotoloader-1.0.1.tar.gz
- Upload date:
- Size: 2.5 kB
- Tags: Source
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a54893e36a9a0757c384de74ba4e76d4ac2b68e8e1cb4e92bbdd8405929c77b
|
|
| MD5 |
8564b23e25053795d7a3773106b2b903
|
|
| BLAKE2b-256 |
3313bcc5172c46a02b3ea9b6515b076457327d9b6114b28e7ef7e4cf4a67e6d5
|
File details
Details for the file pyprotoloader-1.0.1-py3-none-any.whl.
File metadata
- Download URL: pyprotoloader-1.0.1-py3-none-any.whl
- Upload date:
- Size: 3.5 kB
- Tags: Python 3
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c864698c4c25b20e2039de00fff45bdb927641bb3753dfc79eb3d3f7e675226
|
|
| MD5 |
ab6eb51efd6fb33374e41bd54b820f61
|
|
| BLAKE2b-256 |
6ee080fe306a1e2884f1111457e8b93105275437d0ad41b1bc3462b6e8f5c943
|