Skip to main content

Odin

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 Coverage Once you go Black...
Package Latest Version 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.10+ 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

Quick links

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: odin.Url | None

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

Metadata

Release files for odin 2.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for odin 2.11
File Size Uploaded
odin-2.11.tar.gz 109.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for odin 2.11
File Interpreter ABI Platform
odin-2.11-py3-none-any.whl Python 3 none any Details

Total release size: 203.5 kB

Release files / odin-2.11.tar.gz

Download URL odin-2.11.tar.gz
Size 109.9 kB
Tags Source
SHA-256 checksum
How to use checksums
283d6fd8b49775b59873d65dbfae9ae0e31a81e9e7553d8faecc06d60f321176
BLAKE2b-256 checksum
How to use checksums
52fc2701ed79061856e8ee1d0cfc1da000b4272c7aa0d79953b62fa4579217f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / odin-2.11-py3-none-any.whl

Download URL odin-2.11-py3-none-any.whl
Size 93.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4155f984a293b859d7bc252e7ac8ea93647d8b10c1603d6d090acf9865e5bd8d
BLAKE2b-256 checksum
How to use checksums
7c28eac232ee44fba1959635307b76b171b3871105b89b9d5e81cde0c39a0a2b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release history Release notifications | RSS feed

This release

2.11 This release

2 release files

2.10

2 release files

2.9.0

2 release files

2.8.1

2 release files

2.8

2 release files

2.6

2 release files

2.5

2 release files

2.4

2 release files

2.3.1

2 release files

2.3

2 release files

2.2

2 release files

2.1

2 release files

2.0

2 release files

1.8.1

2 release files

1.8.0

2 release files

1.7.3

2 release files

1.7.2

2 release files

1.7.1

2 release files

1.7.0

2 release files

1.6.2

2 release files

1.6.1

2 release files

1.6.0

2 release files

1.5.2

2 release files

1.5.1

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.1

3 release files

1.1

2 release files

1.0

2 release files

0.10

2 release files

0.9

1 release file

0.8.2

2 release files

0.8.1

2 release files

0.8

1 release file

0.7.1

1 release file

0.7

1 release file

0.6

1 release file

0.5.7.1

1 release file

0.5.6

1 release file

0.5.5

1 release file

0.5.2

1 release file

0.5

1 release file

0.4.3.2

1 release file

0.4.3.1

1 release file

0.4.3

1 release file

0.4.2

1 release file

0.4.1.1

1 release file

0.4.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page