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

##Example:

pip install SpecialModel

from special_model.SpecialModelFactory import SpecialModelFactory


class TestObj:
    number: int
    question: bool

    NUMBER_SOURCE = "data-number"
    QUESTION_SOURCE = "data-question"
    DISABLE_TYPE_EXCEPTIONS = True
    DISABLE_PATH_EXCEPTIONS = True


dict_input_test = {
    "data": {
        "number": 123,
        "question": True
    }
}

factory = SpecialModelFactory(TestObj, dict_input_test)
test_obj: TestObj = factory.run()
print(test_obj.number, test_obj.question)
print(type(test_obj.number), type(test_obj.question))

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.22.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

SpecialModel-0.0.22-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file SpecialModel-0.0.22.tar.gz.

File metadata

  • Download URL: SpecialModel-0.0.22.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.5

File hashes

Hashes for SpecialModel-0.0.22.tar.gz
Algorithm Hash digest
SHA256 fe9fec29a46e194803e4f1b7dd48e81c0a1f1f6962f8197f1591020d9968c279
MD5 9a7f8e4216b1e1dfe3f5450d1f542dc8
BLAKE2b-256 cfa0f0a7b6026d3b7c5ceae2d0afbfd756f07e30b157ae6312acb7dc9002943d

See more details on using hashes here.

File details

Details for the file SpecialModel-0.0.22-py3-none-any.whl.

File metadata

  • Download URL: SpecialModel-0.0.22-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.5

File hashes

Hashes for SpecialModel-0.0.22-py3-none-any.whl
Algorithm Hash digest
SHA256 7db764b6caca53115cc8b9afda7ed76ec468359ba925aa985305ab329ed722cf
MD5 4cb228ff30e607684bd9c91f690ace25
BLAKE2b-256 cb79e999c20ec0e1e9ceed781783cdcef390458d705c3fc4dd78f46e72a948ad

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