objectfactory is a python package to easily implement the factory design pattern for object creation, serialization, and polymorphism
Project description
py-object-factory
objectfactory is a python package to easily implement the factory design pattern for object creation, serialization, and polymorphism
- designed to support polymorphism
- integrates seamlessly with marshmallow and other serialization frameworks
- schema inherent in class definition
- load any object with a generic interface
- serialize objects to JSON
Example
Simple shapes example:
import objectfactory
@objectfactory.register
class Square(objectfactory.Serializable):
side = objectfactory.Field()
def get_area(self):
return self.side * self.side
@objectfactory.register
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.create(data)
print('class type: {}, shape area: {}'.format(type(shape), shape.get_area()))
Output:
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
More examples
See more advanced examples here
Install
Use pip for installation
pip install objectfactory
Documentation
Read the full documentation at objectfactory.readthedocs.io
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file objectfactory-0.2.0.tar.gz
.
File metadata
- Download URL: objectfactory-0.2.0.tar.gz
- Upload date:
- Size: 14.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
292950c232aca5fba1ba5957fd8b17a84e147a8dc5f5d64bb5e20320ffea38a3
|
|
MD5 |
1c0737b0167da9f504f4cad127296e36
|
|
BLAKE2b-256 |
f54277b6375afa5ca7fa46e5b67c450c6744fbe9bb6da49535c7d6ee5e555023
|
Provenance
The following attestation bundles were made for objectfactory-0.2.0.tar.gz
:
Publisher:
publish.yml
on devinaconley/py-object-factory
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1
-
Predicate type:
https://docs.pypi.org/attestations/publish/v1
-
Subject name:
objectfactory-0.2.0.tar.gz
-
Subject digest:
292950c232aca5fba1ba5957fd8b17a84e147a8dc5f5d64bb5e20320ffea38a3
- Sigstore transparency entry: 178718912
- Sigstore integration time:
-
Permalink:
devinaconley/py-object-factory@13a1fbfcc0982034e2b5364bacca53dc90248549
-
Branch / Tag:
refs/tags/0.2.0
- Owner: https://github.com/devinaconley
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com
-
Runner Environment:
github-hosted
-
Publication workflow:
publish.yml@13a1fbfcc0982034e2b5364bacca53dc90248549
-
Trigger Event:
push
-
Statement type:
File details
Details for the file objectfactory-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: objectfactory-0.2.0-py3-none-any.whl
- Upload date:
- Size: 21.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
b54a9bc59b5e7fcf8150c4fc7c66940ecd4b54da13332540afe75ec10c35b9e3
|
|
MD5 |
6df5cbf064e737c6893af752a4973648
|
|
BLAKE2b-256 |
95335657fcafa7584f508b481ad64e697a018284d780a5f2c7ebf35926375633
|
Provenance
The following attestation bundles were made for objectfactory-0.2.0-py3-none-any.whl
:
Publisher:
publish.yml
on devinaconley/py-object-factory
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1
-
Predicate type:
https://docs.pypi.org/attestations/publish/v1
-
Subject name:
objectfactory-0.2.0-py3-none-any.whl
-
Subject digest:
b54a9bc59b5e7fcf8150c4fc7c66940ecd4b54da13332540afe75ec10c35b9e3
- Sigstore transparency entry: 178718917
- Sigstore integration time:
-
Permalink:
devinaconley/py-object-factory@13a1fbfcc0982034e2b5364bacca53dc90248549
-
Branch / Tag:
refs/tags/0.2.0
- Owner: https://github.com/devinaconley
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com
-
Runner Environment:
github-hosted
-
Publication workflow:
publish.yml@13a1fbfcc0982034e2b5364bacca53dc90248549
-
Trigger Event:
push
-
Statement type: