Code Monkey home page Code Monkey logo

odin's Introduction

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

Quick links

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

odin's People

Contributors

timsavage avatar thedrow avatar pyup-bot avatar dependabot-preview[bot] avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.