A Python library for implementing design patterns
Project description
python-design-patterns
python-design-patterns is a Python library that provides implementations of various design patterns. Currently, it includes an implementation of the Pipeline pattern, which allows for the processing of data through a series of steps.
Table of Contents
Installation
To use this library, you need Python 3.9 or later installed on your machine. You can install the library using pip.
pip install python-design-patterns
Usage
Pipeline Pattern
The Pipeline pattern allows you to pass data through multiple processing steps. Each step can take inputs, perform operations, and pass results to the next step.
Examples
Here is a simple example of how to use the pipeline:
from pdp.pipeline import Pipeline, Step
# Define your processing functions
def add(x, y):
return x + y
def compute(step1, x, z):
return step1 + x - z
# Create a pipeline and add steps
steps = [
Step(name="step1", func=add),
Step(name="step2", func=compute),
]
pipeline = Pipeline(steps)
# Run the pipeline
result = pipeline.run(x=1, y=2, z=3)
print(result) # Output: {'x': 1, 'y': 2, 'z': 3, 'step1': 3, 'step2': 1}
Here are some additional examples to demonstrate the capabilities of the Pipeline pattern:
def multiply(x, y):
return x * y
def subtract(step1, z):
return step1 - z
# Create a new pipeline
pipeline = Pipeline()
pipeline.add_step(Step(name="step1", func=multiply))
pipeline.add_step(Step(name="step2", func=subtract))
# Run the pipeline
result = pipeline.run(x=2, y=3, z=1)
print(result) # Output: {'x': 2, 'y': 3, 'z': 1, 'step1': 6, 'step2': 5}
Project details
Release history Release notifications | RSS feed
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 python_design_patterns-0.1.1a2.tar.gz.
File metadata
- Download URL: python_design_patterns-0.1.1a2.tar.gz
- Upload date:
- Size: 2.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.9.20 Linux/6.5.0-1025-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c8fd5ce1cc8a7967edd25b3d4f0c18969e69f3a333034628ef4d04d724ae8f06
|
|
| MD5 |
df902a3445cfe33a6d5d59aa9230f111
|
|
| BLAKE2b-256 |
e1cac9b088a231a3a7d33e8cfaf4d3d45dacf84878147152628a40cbf4515dbd
|
File details
Details for the file python_design_patterns-0.1.1a2-py3-none-any.whl.
File metadata
- Download URL: python_design_patterns-0.1.1a2-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.9.20 Linux/6.5.0-1025-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
97036ca1171a53650c740b0900cc802dc5c4411891230439a5789a5fa0e6f7d9
|
|
| MD5 |
6a5c369e8dcc3124aee7679787182be5
|
|
| BLAKE2b-256 |
d8aceb8a7bbec52da51ad32b55a8b0775b9b3209d0fbce1636f05dff0ccfc89b
|