Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

Helpers for Generic Python Classes

Project description

EASY Class package build coverage

EASY Class is a toolkit for creating generic classes in an elegant way.


from easy_class import EasyClass, StringVariable, IntegerVariable

class MyClass(EasyClass):
    attr1 = IntegerVariable()
    attr2 = StringVariable()

The above code declares a class with two member variables attr1 and attr2, where attr1 can only be an integer value and attr2 can only be a string. Hence, if you try to do the following

obj = MyClass()
obj.attr1 = "Test"

it will raise the exception TypeError: attr1 expects int type, but received str.

Class Variable Reference

All Variable types (i.e. IntegerVariable, StringVariable) are inherited from the class Variable which represents a class attribute type. Below contains all the API references of Variable including the variable options and field types this package offers.

Variable options

The following arguments are available to all variable types. All are optional.


If False the attribute cannot be assigned a NULL variable. Default is True. You cannot also instantiate a class which has any Non-nullable attributes without specifying the correct arguments. Below is what I meant to say.

class MyClass(EasyClass):
    attr1 = IntegerVariable(null=False)
    attr2 = StringVariable(null=False)

obj = MyClass()

The above will raise the exception ValueError: Following attributes cannot be null: [attr2, attr1]


A list to use as choices for the attribute. Will raise exception if value being is stored is not included in this list of choices.


The default value for the attribute. Right now, callables are not supported.


If False, the attribute value cannot be edited. Default is True.

Variable Types


An Integer Variable. IntegerVariable allows the following extra arguments.


The maximum value that can be set for the attribute. Default is None (i.e., no validation is done)


The minimum value that can be set for the attribute. Default is None (i.e., no validation is done)


A string variable, for small- to large-sized strings. StringVariable has the following extra arguments


The maximum length (in characters) of the attribute. Defaults 255.


The minimum length (in characters) of the attribute. Defaults 0.


A true/false attribute.


A floating-point number represented in Python by a float instance. FloatVariable accepts same arguments as an IntegerField.


A custom class variable. Required keyword argument cls must be passed to a ClassVariable. Below is an example.
class A(object):

class MyClass(EasyClass):
   a = ClassVariable(cls=A, null=False)


A dictionary variable.


A python datetime variable. DateTimeVariable either accepts a datetime variable or string of the format YYYY-MM-DDTHH:MM:SS.


A python date variable. DateVariable either accepts a date variable or string of the format YYYY-MM-DD.


A python time variable. TimeVariable either accepts a time variable or string of the format HH:MM:SS.

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 easy-class, version 1.1.2
Filename, size File type Python version Upload date Hashes
Filename, size easy_class-1.1.2-py2.py3-none-any.whl (9.0 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size easy_class-1.1.2.tar.gz (13.6 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 Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page