Skip to main content

A tool that reduces the boilerplate code required to define beans.

Project description

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.

Project details


Release history Release notifications

History Node

1.8.1

History Node

1.8.0

History Node

1.7.2

History Node

1.7.1

History Node

1.7.0

History Node

1.6.1

History Node

1.6.0

History Node

1.5.4

History Node

1.5.3

History Node

1.5.2

History Node

1.5.1

History Node

1.5.0

History Node

1.4.0

History Node

1.3.3

History Node

1.3.2

History Node

1.3.1

History Node

1.3.0

History Node

1.2.2

History Node

1.2.1

History Node

1.2.0

History Node

1.1.2

History Node

1.1.1

History Node

1.1.0

History Node

1.0.5

History Node

1.0.4

History Node

1.0.3

History Node

1.0.2

This version
History Node

1.0.1

History Node

1.0.0

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
QuickBean-1.0.1.tar.gz (18.7 kB) Copy SHA256 hash SHA256 Source None Jun 15, 2014

Supported by

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