Skip to main content

A python package for the serializable model / factory pattern

Project description


Build Status codecov

objectfactory is a python package to easily implement the factory design pattern for object creation and serialization

  • serialization schema inherent in class definition
  • consistent interface to load many objects of arbitrary type
  • serialize object to human-readable JSON format


Simple shapes example:

import objectfactory

class Square( objectfactory.Serializable ):
    side = objectfactory.Field()

    def get_area( self ):
        return self.side * self.side

class Triangle( objectfactory.Serializable ):
    base = objectfactory.Field()
    height = objectfactory.Field()

    def get_area( self ):
        return 0.5 * self.base * self.height

serialized_data = [
    {"_type": "Square", "side": 2.0},
    {"_type": "Triangle", "base": 1.75, "height": 2.50},
    {"_type": "Square", "side": 1.5},

for data in serialized_data:
    shape = objectfactory.Factory.create_object( data )
    print( 'class type: {}, shape area: {}'.format( type( shape ), shape.get_area() ) )


class type: <class '__main__.Square'>, shape area: 4.0
class type: <class '__main__.Triangle'>, shape area: 2.1875
class type: <class '__main__.Square'>, shape area: 2.25

See more examples here


Use pip for installation

pip install objectfactory

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 objectfactory, version 0.0.3
Filename, size File type Python version Upload date Hashes
Filename, size objectfactory-0.0.3-py3-none-any.whl (9.4 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size objectfactory-0.0.3.tar.gz (6.2 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page