Skip to main content

Dictionary Model

Project description

SpecialModel

Special Model

alt_text

The library returns an object with defined attributes in types from an input dictionary, with optional rules about types and more.

The declaration for the object variables and their types uses annotations:

    number: int
    question: bool

The mapping between variable and path inside the input dictionary are inside the source variables, in this format: a string separated by '-' for each inner jump inside the dictionary For example:

    NUMBER_SOURCE = "data-number"           # == dict_input["data"]["number"]
    QUESTION_SOURCE = "data-question"       # == dict_input["data"]["question"]

The optional parameter are:

DISABLE_TYPE_EXCEPTIONS = True
DISABLE_PATH_EXCEPTIONS = True

Type exception indicate to stop the object creation if theirs an error in matching types. The second variable indicate to stop the object creation if a value don't exist in the source path. When disabled variables are true the problematic variables are set to None. The default is DISABLE_TYPE_EXCEPTIONS and DISABLE_PATH_EXCEPTIONS as False.

Full example:

class TestObj:
    number: int
    question: bool
    NUMBER_SOURCE = "data-number"
    QUESTION_SOURCE = "data-question"
    DISABLE_TYPE_EXCEPTIONS = True
    DISABLE_PATH_EXCEPTIONS = True

##Use

pip install SpecialModel

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

SpecialModel-0.0.2.tar.gz (5.2 kB view hashes)

Uploaded Source

Built Distribution

SpecialModel-0.0.2-py3-none-any.whl (6.0 kB view hashes)

Uploaded Python 3

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