Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_design_patterns-0.1.1.tar.gz (2.6 kB view details)

Uploaded Source

Built Distribution

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

python_design_patterns-0.1.1-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

Hashes for python_design_patterns-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8b906d324436829508b5715e06713da7979a8004bc1344921849c430430b85a9
MD5 b1883fb49eae4d2875630b6b0f5b441a
BLAKE2b-256 20bbe9baf2b28a0569b2f7599dee9fdaf87f02eca474275e7d2a81992746b6db

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_design_patterns-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d48e29d712bcf253d82bc09a661d8e8e03b346f5e146f7003b42e4e022e7a8a8
MD5 0a5b18839ed58485eb80c3a5a4412508
BLAKE2b-256 4074e85067b090e1bb12c420c155e7df7742d95434aa7b38fc351d0ac37f5b2a

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