Coder Social home page Coder Social logo

maurosilber / datastruct Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hgrecco/datastruct

0.0 1.0 0.0 79 KB

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

License: Other

Python 100.00%

datastruct's Introduction

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)

Other features

You can easily specify default values that

>>> class EmailServer(DataStruct):
...
...     host: str
...     port: int = 25
...     username: str
...     password: str

See AUTHORS for a list of the maintainers.

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

datastruct's People

Contributors

hgrecco avatar maurosilber avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.