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.1.1.tar.gz (7.2 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.1.1-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pl_dpl-0.1.1.tar.gz
  • Upload date:
  • Size: 7.2 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.1.1.tar.gz
Algorithm Hash digest
SHA256 35f20a065db5b65d7d6b96bb4f2a4ac5a7c7288dd1b1843608129e6bb8f28fd0
MD5 a724666ec3d3d516da027679aa74f5d1
BLAKE2b-256 e14fae8b0d407660c102d4b6ea73bb1ed07805e762c0b8b230cacc74a9be2a18

See more details on using hashes here.

File details

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

File metadata

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

Hashes for pl_dpl-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1f2ae8a59d80aaf594db1914b5691e2a5b02745aa0f61943de2caa59484f3392
MD5 ddab8dccd5889751f5108963b0ae1916
BLAKE2b-256 274150ce2411b244a5bc691b9780333324d7bc700bd66be2f451408da8a0d550

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