PL-DPL
Peach's Lightweight Design Pattern Library
Low code, low dependency, simple implementation of commonly used design patterns.
Quick Start
Install library
pip install pl-dpl
Factory
Lazy Loading Self-Registering Factory Design Pattern.
Create a subclass of BaseFactory, specify the directory where concrete implementations exist, define abstract functions.
**NOTE: Only include one implementation per file in the plugin directory, registration is done by module name, not class name. This makes it more readable for developers so when they look at the config and see "s3" they can immediately see the file "s3.py" and know where the implementation is.
Usage
Create packages for implementations:
src/
|-- storage/
| |-- s3.py
|-- storage_factory.py
|-- main.py
./main.py
from storage_factory import StorageFactory
data = b'123'
StorageFactory("s3").save(data)
./storage_factory
from patterns import BaseFactory
# Create Factory
class StorageFactory(BaseFactory):
plugin_dir = "storage"
_registry = {}
# Define Abstract Functions
def save(self, data: bytes):
raise NotImplementedError
./storage/s3.py
from storage_factory import StorageFactory
# Create implementation
class S3(StorageFactory):
def save(self, data: bytes):
...
Chain
Lazy Loading Self-Registering Chain of Responsibility.
Create a subclass of BaseHandler (a BaseFactory), specify the directory where concrete handlers exist, implement handle() on each link.
**NOTE: Only include one handler per file in the plugin directory, registration is done by module name, not class name.
Usage
Create packages for handlers:
src/
|-- middleware/
| |-- handlers/
| | |-- ping_pong.py
|-- middleware.py
|-- main.py
./main.py
from patterns import ChainManager
from middleware import MiddlewareHandler
config = [
{"name": "ping_pong", "config": {"prefix": "ping"}},
{"name": "ping_pong", "config": {"prefix": "pong"}},
]
chain = ChainManager(MiddlewareHandler, config)
result = chain.execute("ping")
./middleware.py
from patterns import BaseHandler
# Logic group for the chain
class MiddlewareHandler(BaseHandler):
plugin_dir = ".handlers"
_registry = {}
./middleware/handlers/ping_pong.py
from middleware import MiddlewareHandler
# A chain link. handle() returns (should_continue, result):
# True passes to the next link, False breaks the chain.
class PingPong(MiddlewareHandler):
def handle(self, request):
should_continue = request.lower().startswith(self._config["prefix"])
if not should_continue:
return not should_continue, request
return should_continue, f"I accept your {self._config['prefix']}"
Entity
TODO:
Command
TODO:
Metadata
Release files for pl-dpl 0.3.0
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 |
|---|---|---|---|---|
| pl_dpl-0.3.0.tar.gz | 10.0 kB | Without provenance | Details for pl_dpl-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pl_dpl-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for pl_dpl-0.3.0-py3-none-any.whl |
Total release size: 18.4 kB
Release files / pl_dpl-0.3.0.tar.gz
| Download URL | pl_dpl-0.3.0.tar.gz |
|---|---|
| Size | 10.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8d9a54bf83cef487e68167269864d1e0059f2ed90396adb71a266391abd1d691
|
|
BLAKE2b-256 checksum How to use checksums |
323b11b026426445f599e5e578f6c934c3e4c30beb206a19479b4786777f65b7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.14
|
Release files / pl_dpl-0.3.0-py3-none-any.whl
| Download URL | pl_dpl-0.3.0-py3-none-any.whl |
|---|---|
| Size | 8.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e646b4122fca0d6ed015e07761d626103a116c0cf1d826c59c2b19cc2054e2e8
|
|
BLAKE2b-256 checksum How to use checksums |
b689b27018a75bf358203ee0ba7bf13e1ea78245279a5443d699a21f335cc51a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.14
|
Security for pl-dpl 0.3.0
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.