GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - python-odin/odin: Data-structure definition/validation/traversal, mapping and serialisation toolkit for Python

BranchesTags
Open more actions menu

Latest commit

 

History

1,372 Commits
1,372 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
docs
docs
 
 
samples
samples
 
 
src/odin
src/odin
 
 
tests
tests
 
 
.checkignore
.checkignore
 
 
.codeclimate.yml
.codeclimate.yml
 
 
.gitignore
.gitignore
 
 
.pre-commit-config.yaml
.pre-commit-config.yaml
 
 
.readthedocs.yaml
.readthedocs.yaml
 
 
AUTHORS
AUTHORS
 
 
HISTORY
HISTORY
 
 
LICENSE
LICENSE
 
 
MANIFEST.in
MANIFEST.in
 
 
README.md
README.md
 
 
noxfile.py
noxfile.py
 
 
poetry.lock
poetry.lock
 
 
pyproject.toml
pyproject.toml
 
 
sonar-project.properties
sonar-project.properties
 
 

Repository files navigation

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

  • Documentation
  • Project home
  • Issue tracker

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

About

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

odin.readthedocs.org/en/latest/

Topics

csvdata-mappingdata-structuresde-serializejsonmsgpackpythonserializevalidationxmlyaml

Resources

Readme
BSD-3-Clause license
Activity
Custom properties

Stars

40 stars

Watchers

2 watching

Forks

12 forks
Report repository

Releases

Sponsor this project

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.