Skip to main content

A small but useful package to load, validate and use typed data structures, including configuration files.

Project description

Latest Version License Python Versions CI Coverage

datastruct

A small but useful package to load, validate and use typed data structures, including configuration files.

You get:

  • An easy way to define a typed hierarchical data structure.

  • Hassle free definition nested structures.

  • Loading from a variety of formats (json, yaml and everything supported by Serialize),

  • Error checking including: missing values, unexpected value, wrong type, wrong value.

  • Easy to integrate in another app error reporting.

Installation

pip install datastruct

Usage

>>> from typing import List
>>> from datastruct import DataStruct
>>> class EmailServer(DataStruct):
...
...     host: str
...     port: int
...     username: str
...     password: str
>>>
>>> class Config(DataStruct):
...
...     download_path: str
...     email_servers: List[EmailServer]
...     wait_time: float
>>>
>>> cfg = Config.from_filename('settings.yaml')

When an invalid value is found, an exception will be raised.

If you want to accumulate all errors for inspection:

>>> cfg = Config.from_filename('settings.yaml', raise_on_error=False)
>>> print(cfg.get_errors())

You can then use the DataStruct object in your code:

>>> print(cfg.email_servers[0].host)

See AUTHORS for a list of the maintainers.

To review an ordered list of notable changes for each version of a project, see CHANGES

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

datastruct-0.2.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

datastruct-0.2-py2.py3-none-any.whl (14.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file datastruct-0.2.tar.gz.

File metadata

  • Download URL: datastruct-0.2.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0.post20200106 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.6.7

File hashes

Hashes for datastruct-0.2.tar.gz
Algorithm Hash digest
SHA256 8696845705246a42e4d812066655d656c1c8e04ede72ca7aa3e2fd4cc18f5308
MD5 ee991516c3a8e8472fac42e6f3b4a544
BLAKE2b-256 d2b9b54198f2665cb386f9d3612a7b967b9ab72e5dec997d2fa2facf21e17160

See more details on using hashes here.

File details

Details for the file datastruct-0.2-py2.py3-none-any.whl.

File metadata

  • Download URL: datastruct-0.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 14.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0.post20200106 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.6.7

File hashes

Hashes for datastruct-0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2903c445ba2ca8214d6fe180cab1e818dfade187b49ec60baa2fbaeebed80233
MD5 cf56a20008f840e3cb021b89e4a8d81c
BLAKE2b-256 39366f8b1487e51136bb336c4be1953423456cb1147106a07a6b55992126b481

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