Skip to main content
Warning: You are using the test version of PyPI. This is a pre-production deployment of Warehouse. Changes made here affect the production instance of TestPyPI (testpypi.python.org).
Help us improve Python packaging - Donate today!

Instrospective Factory pattern library

Project Description

Overview

Python 3 object factory pattern implementation. The principal idea is keep it simple and readable, the main function provide a mechanism to factorize any object with introspection and don’t make the horrible code conditions like in factory examples:

def factory(type):
    if type == 'MyClass':
        return MyClass()
    if type == 'MyOtherClass':
        return MyOtherClass()

So for it this module factorize any class from any module and works only in python 3 for python 2 you have pypi module named Factory and maybe is better for you with more functionality and complexity.

Installation

git clone https://github.com/engine-cl/ng_factory.git
cd ng-factory
python3 setup.py install
pip install ng_factory

Testing

python test/factory.py

Example

Create any module with your atomic class encapsulation with GOPS and then factorize object to inject the dependencies into the business logic like persistence layer or any another layer.

from ng_factory import factorize
class persistence(object):
    """ assumes all code needed to connect db and commit data transaction """
    def __init__(self, data):
        import database
        self._dbcon = database.get_connection()
        self.data = data
    def save(self):
        self._dbcon.commit(this.data.persist())

class DataObjectTypeOne(object):
    """ assumes all serializable function to format the data output """
    @staticmethod
    def persist():
        return self.get_save_format()

try:
    db = persistence(factorize(module=Example, object_type=DataObjectTypeOne))
except(ArgumentError, NonExistentTypeError, NonExistentModuleError) as e:
    print("factory error {}".format(e))
    raise

db.save()
Release History

Release History

This version
History Node

0.9.2

History Node

0.9.1

History Node

0.1.0

Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
ng_factory-0.9.2.tar.gz (2.7 kB) Copy SHA256 Checksum SHA256 Source May 13, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting