Skip to main content

Instrospective Factory pattern library

Project description


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 commonly showed in factory examples:

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

So, this module factorize any class from any module and works only in python 3 for python 2 don’t make any sense wasted time adapting differences between both version also is important know which this module only factorize classes or functions from modules so if can’t __import__ them, raises an exception, and if you want factorize class or function who is in the same module you need make it reachable to the __import__ statement


git clone
cd ng-factory
python3 install
pip install ng_factory


python test/


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() = data
    def save(self):

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

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

Project details

Download files

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

Files for ng_factory, version 0.1.2
Filename, size File type Python version Upload date Hashes
Filename, size ng_factory-0.1.2.tar.gz (4.2 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page