Peach's Lightweight Design Pattern Library
Project description
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
TODO:
Entity
TODO:
Command
TODO:
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
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 pl_dpl-0.1.2.tar.gz.
File metadata
- Download URL: pl_dpl-0.1.2.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3f705fe751a193111aa0a8cdcb172551c297c19918739ab214976cf2fb856f69
|
|
| MD5 |
1056185b831650678098ca65e363beaa
|
|
| BLAKE2b-256 |
bfa5656bf1cad82a7311a53116a8e8eb85a445ddf06b00e66d139fb58183289a
|
File details
Details for the file pl_dpl-0.1.2-py3-none-any.whl.
File metadata
- Download URL: pl_dpl-0.1.2-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cdee1446e3703556ba065d94f8e465afe69f63a05bbd47c517a344300edaac23
|
|
| MD5 |
58295fe65fdee7856d2e7fc5c5a693eb
|
|
| BLAKE2b-256 |
2ad46798907ddc33d42d825bc4475d5eeca2cd7bc44e53f1386ef1f85687610f
|