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

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

  • Class based annotations style! ✨ new in 2.0

  • Fields for building composite resources

  • Field and Resource level validation

  • Easy extension to support custom fields

  • Python 3.8+ and PyPy 1 supported

  • Support for documenting resources with Sphinx

  • Minimal dependencies

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 only)

  • Complete documentation coverage

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

Requires

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

  • arrow - Support for Arrow data types.

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

Development

  • pytest - Testing

  • pytest-cov - Coverage reporting

Example

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()

Using Annotations

import odin

class Author(odin.AnnotatedResource):
    name: str

class Publisher(odin.AnnotatedResource):
    name: str
    website: Optional[odin.Url]

class Book(odin.AnnotatedResource):
    title: str
    authors: List[Author]
    publisher: Publisher
    genre: str
    num_pages: int

Usage:

>>> 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"
}

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

Uploaded Source

Built Distribution

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

odin-2.2-py3-none-any.whl (85.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: odin-2.2.tar.gz
  • Upload date:
  • Size: 105.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for odin-2.2.tar.gz
Algorithm Hash digest
SHA256 92a806a65737017e08a6fa3c2118f598030c7e863aaf4cfe5f00af29159238be
MD5 260c0c5729ac2b6c33110da1007858e6
BLAKE2b-256 d6aa0320b43cb872e4cd69a72a8515b5a26151f6e447cc4d513604f561fd25dc

See more details on using hashes here.

File details

Details for the file odin-2.2-py3-none-any.whl.

File metadata

  • Download URL: odin-2.2-py3-none-any.whl
  • Upload date:
  • Size: 85.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for odin-2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 675206e28b50920ea244277d349b81f86cd44a7c1d6005f66f88652533aacc6a
MD5 6350411d182bf7bc2afd5448f6b4abca
BLAKE2b-256 4ccf9a9286a75ded230ce762e7489a73d7cb632e10313c048f84066a39bd0895

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