Skip to main content

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.

Usage

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.

null

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]

choices

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.

default

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

editable

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

Variable Types

IntegerVariable

An Integer Variable. IntegerVariable allows the following extra arguments.

max_value

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

min_value

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

StringVariable

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

max_length

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

min_length

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

BooleanVariable

A true/false attribute.

FloatVariable

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

ClassVariable

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

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

DictVariable

A dictionary variable.

DateTimeVariable

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

DateVariable

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

TimeVariable

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.

Source Distribution

easy_class-1.1.0.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

easy_class-1.1.0-py2.py3-none-any.whl (9.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file easy_class-1.1.0.tar.gz.

File metadata

  • Download URL: easy_class-1.1.0.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for easy_class-1.1.0.tar.gz
Algorithm Hash digest
SHA256 15e18600e4822ddb92d5336ffa4b652fc770e9a0ab4757e0f842ddb34a183463
MD5 6a14cc30d8a3b69cf66de3b63c683cc4
BLAKE2b-256 f3b451859b7d767c83c50b626493de116041e87806497b9878ec62ac29eb2493

See more details on using hashes here.

File details

Details for the file easy_class-1.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for easy_class-1.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 4958b1ce759dd3b8f7cde2a62de83fc718698875e54852fbb9ba25a20637ba63
MD5 74c75518fa40745b5b34943725b91fa6
BLAKE2b-256 b55f71f2af0c236dded39a48fc46ad8d8df47961d722fc5d956e8d17642d5550

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page