A framework for writing extensible Python components
Project description
Plugable: A Python Plugin Framework
Badges:
This package exposes a framework for writing extensible applications.
Specifically, it allows consumers to mark an abstract class as "Plugable", using standard inheritance semantics and ABC decorators:
from abc import abstractmethod
from plugable import Plugable
class AbstractInterface(Plugable):
@abstractmethod
def example(self):
pass
Following this, you can create subclasses for differing implementations, and register them with the AbstractInterface
registry, like so:
class ExampleOne(AbstractInterface, register="one"): # Integrated registration
def example(self):
print("You ran ExampleOne!")
class ExampleTwo(AbstractInterface):
def example(self):
print("You ran ExampleTwo!")
AbstractInterface.registry.register("two", ExampleTwo) # Explicit registration
Finally, you can access and consume the registered implementations, like so:
AbstractInterface.get("one").example() # You ran ExampleOne!
AbstractInterface.get("two").example() # You ran ExampleTwo!
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
plugable-1.2.2.tar.gz
(3.9 kB
view details)
Built Distribution
File details
Details for the file plugable-1.2.2.tar.gz
.
File metadata
- Download URL: plugable-1.2.2.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc0782c11255f206f606595c3065a397571e5dc91b08b2b0126ed462ef3b8cc4 |
|
MD5 | caf81c8692c694c5181f2460b086b6b0 |
|
BLAKE2b-256 | f811b89c680a1e19640f36fc70497418b4312c7f74a7aeb1a39ddfa7343c0118 |
File details
Details for the file plugable-1.2.2-py3-none-any.whl
.
File metadata
- Download URL: plugable-1.2.2-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97412801790acfdedf936e4255d9a467095d2cb708ff701ba37b14a751117abd |
|
MD5 | 71d77d170022208d0f74a67b1d4442d9 |
|
BLAKE2b-256 | 087e3d016cf756cfebc371138bd7f25bcf5719211ccb5532d7636cd9293e873c |