Skip to main content

QuickBean is a tool that reduces the boilerplate code required to define beans.

Installation

Here is how to install QuickBean :

pip install quickbean

Starting with QuickBean

Suppose you have defined the following bean :

>>> class MyObject(object):
>>>     def __init__(self, my_property, my_other_property):
>>>         self.my_property = my_property
>>>         self.my_other_property = my_other_property

If you would like your bean to have a human-readable representation, you have to override the __repr__ method :

>>> class MyObject(object):
>>>     def __init__(self, my_property, my_other_property):
>>>         self.my_property = my_property
>>>         self.my_other_property = my_other_property
>>>
>>>     def __repr__(self):
>>>         return 'MyObject(my_property=%s, my_other_property=%s)' % (self.my_property, self.my_other_property)

If you would like your bean to be equality comparable, you also have to override the __eq__ and __ne__ methods :

>>> class MyObject(object):
>>>     def __init__(self, my_property, my_other_property):
>>>         self.my_property = my_property
>>>         self.my_other_property = my_other_property
>>>
>>>     def __repr__(self):
>>>         return 'MyObject(my_property=%s, my_other_property=%s)' % (self.my_property, self.my_other_property)
>>>
>>>     def __eq__(self, other):
>>>         return other.__class__ is MyObject and other.__dict__ == self.__dict__
>>>
>>>     def __ne__(self, other):
>>>         return not self.__eq__(other)

Although there is nothing difficult here, it would be better if this boilerplate code could be automatically generated for you. This is exactly what QuickBean brings to you :

>>> import quickbean
>>>
>>> @quickbean.AutoBean()
>>> class MyObject(object):
>>>     def __init__(self, my_property, my_other_property):
>>>         self.my_property = my_property
>>>         self.my_other_property = my_other_property

You may even let QuickBean generate the __init__ method for you :

>>> import quickbean
>>>
>>> @quickbean.AutoInit('my_property', 'my_other_property')
>>> @quickbean.AutoBean()
>>> class MyObject(object):
>>>     pass

See the documentation for more information on how to use QuickBean.

Download files

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

Source Distribution

QuickBean-1.0.1.tar.gz (18.7 kB view details)

Uploaded Source

File details

Details for the file QuickBean-1.0.1.tar.gz.

File metadata

  • Download URL: QuickBean-1.0.1.tar.gz
  • Upload date:
  • Size: 18.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for QuickBean-1.0.1.tar.gz
Algorithm Hash digest
SHA256 60cd0a8934644a6ab0f7cda40f921141fdac32b2e55eb2f0ecb78244c6a7b3d3
MD5 5a6e8308163b5b53c6487c6df4997a2c
BLAKE2b-256 33b90d2c51a15ea2ab03ef16b81c9bf5c7fd60844dba406dee86c96de66c6063

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