Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

License

NotificationsYou must be signed in to change notification settings

python-odin/odin

Repository files navigation

Odin provides a declarative framework for defining resources (classes) and their relationships, validation of the fieldsthat 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/HelpReadTheDocsGitter.im
BuildPython package
QualityMaintainabilitySecurityCoverageOnce you go Black...
PackageLatest VersionPyPI - 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 PyPy1 supported
  • Support for documenting resources withSphinx
  • 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 thePint library.

Development

  • pytest - Testing
  • pytest-cov - Coverage reporting

Example

Definition

importodinclassAuthor(odin.Resource):name=odin.StringField()classPublisher(odin.Resource):name=odin.StringField()classBook(odin.Resource):title=odin.StringField()authors=odin.ArrayOf(Author)publisher=odin.DictAs(Publisher)genre=odin.StringField()num_pages=odin.IntegerField()

Using Annotations

importodinclassAuthor(odin.AnnotatedResource):name:strclassPublisher(odin.AnnotatedResource):name:strwebsite:odin.Url|NoneclassBook(odin.AnnotatedResource):title:strauthors:list[Author]publisher:Publishergenre:strnum_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.codecsimport 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

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors6

Languages


[8]ページ先頭

©2009-2025 Movatter.jp