Skip to main content

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

pl_dpl-0.2.0.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pl_dpl-0.2.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file pl_dpl-0.2.0.tar.gz.

File metadata

  • Download URL: pl_dpl-0.2.0.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

Hashes for pl_dpl-0.2.0.tar.gz
Algorithm Hash digest
SHA256 dd7ffd081e16014404540d99c90a0093200914423cd5a0be2f5d353c1ab26872
MD5 f4b47cc5ee87e9636ca5bbda2a1d8620
BLAKE2b-256 d4635ecc1646916bb92e6e417a69f0d1ae2e02fa275bc762d06675b2789f37ac

See more details on using hashes here.

File details

Details for the file pl_dpl-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pl_dpl-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for pl_dpl-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 06773a56d27ea4a2c4dd6e74cd5529b54310cfff2104643814aad280e2f612e7
MD5 48123bdffbc0dec2a93e48b2c2747ff3
BLAKE2b-256 c87a408f8ff9ac12cb679095b08fc42d836d0cc4351aa7f4c3f1c24e5ca9d41f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page