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.2.tar.gz (2.9 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.2-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: python_design_patterns-0.1.2.tar.gz
  • Upload date:
  • Size: 2.9 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.2.tar.gz
Algorithm Hash digest
SHA256 83981ad5eaa258e8a88fce6033d4861b0647ad6080510137ca6389fcf4b61a25
MD5 4f1ff6b026a10b34d15674f4da9611a3
BLAKE2b-256 9e940eb21c3e89b37198f5c4186b210a4123fbf2f2852056673739cdec0cd58b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python_design_patterns-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 be37004a8e4497aa71a89592bb120aadcc056baa65d1a404fb18818e14f28594
MD5 79f1d741ce918e00e393ad3aa9eb6256
BLAKE2b-256 5672cc5a52d4e8bc1354dbb117c93b8b39557c01df6176250e1350db9762df3a

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