Skip to main content

Software Design Patterns with types in Python.

Project description

A Python package with common Software Design Patterns.

build

CircleCI Codecov Read the Docs (version)

package

PyPI PyPI - Python Version PyPI - Downloads PyPI - Wheel GitHub commits since tagged version (branch)

code quality

Scrutinizer code quality

Overview

This repository hosts the open-source code of the Software Patterns project. The project’s main component is the software-patterns python package hosted on Pypi at https://pypi.org/project/software-patterns It also features online Documentation Pages hosted at https://software-patterns.readthedocs.io/ and a public CI workflow hosted on CircleCI.

What are Software Design Patterns?

Software Engineers are employing various designs and solutions to solve their problems. The emerging (software) patterns, among the code solutions, targeting reoccuring problems have been studied and formalized in terms of how they are used, what problem they solve and why they are a fit candidate to solve it. These code designs, which are frequently found in various code bases, are known as Software Design Patterns.

The software-patterns package exposes a set of Python Classes that allow convient usage of common Software Design Patterns.

Design Patterns implemented:

  • Notification (aka Broadcast/Listener pattern)

  • Object Pool (aka Memoize)

  • Classes Registry (aka Abstract Factory)

  • Proxy

Installation

Install from the Pypi server:

pip install software-patterns

Quickstart

Example code to use the factory pattern in the form of a (sub) class registry:

from software_patterns import SubclassRegistry

class MyClassRegistry(metaclass=SubclassRegistry):
    pass

@MyClassRegistry.register_as_subclass('a')
class ClassA:
    def __init__(self, number):
        self.attr = number

@MyClassRegistry.register_as_subclass('b')
class ClassB:
    def __init__(self, number):
        self.attr = number - 1

assert MyClassRegistry.subclasses == {'a': ClassA, 'b': ClassB}

instance_a = MyClassRegistry.create('a', 10)
assert type(instance_a) == ClassA
assert instance_a.attr == 10

assert isinstance(instance_a, ClassA)

instance_b = MyClassRegistry.create('b', 10)
assert type(instance_b) == ClassB
assert instance_b.attr == 9

assert isinstance(instance_b, ClassB)

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

software_patterns-2.1.0.tar.gz (34.3 kB view details)

Uploaded Source

Built Distribution

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

software_patterns-2.1.0-py3-none-any.whl (34.8 kB view details)

Uploaded Python 3

File details

Details for the file software_patterns-2.1.0.tar.gz.

File metadata

  • Download URL: software_patterns-2.1.0.tar.gz
  • Upload date:
  • Size: 34.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.16

File hashes

Hashes for software_patterns-2.1.0.tar.gz
Algorithm Hash digest
SHA256 481a6a39ead7de370266d10c443c52e3e1ac2cec583ec0d9aa42304ac870e580
MD5 9bd444cb7792663b470e33f8da9c8a33
BLAKE2b-256 1f3c1b86a42aaea97e77bd255c25af06caac5b08e1616fd022243475324aa20f

See more details on using hashes here.

File details

Details for the file software_patterns-2.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for software_patterns-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5a4ac673d5dd91d7f01e58b5b758dd3fce05416c1ff450bdc9413ca09a56b1f3
MD5 3d5cbac040b60a81ee93aec0e09d260b
BLAKE2b-256 8f6be028fa1f86e26c9b8a1a3b2d9c11587a2ed911bd30d7bc170aabdbece395

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