Skip to main content

Data-structure definition/validation/traversal, mapping and serialisation toolkit for Python

Project description

Odin provides a declarative framework for defining resources (classes) and their relationships, validation of the fields that make up the resources and mapping between objects (either a resource, or other python structures).

Odin also comes with built in serialisation tools for importing and exporting data from resources.

Docs/ Help

ReadTheDocs Gitter.im

Build

Python package Dependabot Status

Quality

Maintainability Security Test Coverage Once you go Black...

Package

Latest Version https://img.shields.io/pypi/pyversions/odin https://img.shields.io/pypi/l/odin PyPI - Wheel

Highlights

  • Class based declarative style

  • Fields for building composite resources

  • Field and Resource level validation

  • Easy extension to support custom fields

  • Python 2.7 1, Python 2.7+, Python 3.6+ and PyPy 1 supported

  • Support for documenting resources with Sphinx

  • Minimal dependencies (base functionality only requires six)

1 certain contrib items are not supported. Pint is not installable with PyPy.

Use cases

  • Design, document and validate complex (and simple!) data structures

  • Convert structures to and from different formats such as JSON, YAML, MsgPack, CSV, TOML

  • Validate API inputs

  • Define message formats for communications protocols, like an RPC

  • Map API requests to ORM objects

Upcoming features

In development

  • XML Codec (export completed)

  • Complete documentation coverage

  • Improvements for CSV Codec (writing, reading multi resource CSV’s)

  • Integration with other libraries (ie Django Models/Forms)

  • Integration with SQLAlchemy

Requires

  • six

Optional

  • simplejson - Odin will use simplejson if it is available or fallback to the builtin json library

  • msgpack-python - To enable use of the msgpack codec

  • pyyaml - To enable use of the YAML codec

  • toml - To enable use of the TOML codec

Contrib

  • jinja2 >= 2.7 - For documentation generation

  • pint - Support for physical quantities using the Pint library.

Development

  • pytest - Testing

  • pytest-cov - Coverage reporting

Example

With definition:

import odin

class Author(odin.Resource):
    name = odin.StringField()

class Publisher(odin.Resource):
    name = odin.StringField()

class Book(odin.Resource):
    title = odin.StringField()
    authors = odin.ArrayOf(Author)
    publisher = odin.DictAs(Publisher)
    genre = odin.StringField()
    num_pages = odin.IntegerField()
>>> b = Book(
        title="Consider Phlebas",
        genre="Space Opera",
        publisher=Publisher(name="Macmillan"),
        num_pages=471
    )
>>> b.authors.append(Author(name="Iain M. Banks"))
>>> from odin.codecs import json_codec
>>> json_codec.dumps(b, indent=4)
{
    "$": "Book",
    "authors": [
        {
            "$": "Author",
            "name": "Iain M. Banks"
        }
    ],
    "genre": "Space Opera",
    "num_pages": 471,
    "publisher": {
        "$": "Publisher",
        "name": "Macmillan"
    },
    "title": "Consider Phlebas"
}

Authors

Tim Savage

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

odin-1.7.3.tar.gz (100.8 kB view details)

Uploaded Source

Built Distribution

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

odin-1.7.3-py2.py3-none-any.whl (87.4 kB view details)

Uploaded Python 2Python 3

File details

Details for the file odin-1.7.3.tar.gz.

File metadata

  • Download URL: odin-1.7.3.tar.gz
  • Upload date:
  • Size: 100.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.8.12 Linux/5.8.0-1042-azure

File hashes

Hashes for odin-1.7.3.tar.gz
Algorithm Hash digest
SHA256 16499708da42cae36f0f829de2c4eb31ec47ffb4958e30b612af3ddfc4298b8f
MD5 6bf6c2ce890e285a09284fcb40ad53e0
BLAKE2b-256 3543a9a584a04a65f715df3916c7da254d08acde21ece30cb94b918b2e418d55

See more details on using hashes here.

File details

Details for the file odin-1.7.3-py2.py3-none-any.whl.

File metadata

  • Download URL: odin-1.7.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 87.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.8.12 Linux/5.8.0-1042-azure

File hashes

Hashes for odin-1.7.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 02a3d03b51b775539116f3047e1e8eeb7ffc95e9a2c174d8e7b09609370cddac
MD5 04a9f54f0f1600c9326fedd0fd8756b9
BLAKE2b-256 750a299b9b572d3e958c1a420b34306c46ed14bc6e140a64271793c960cc0b79

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