Skip to main content

No project description provided

Project description


pipeline status coverage report

A serialization and validation library for python 3 based on the typing module.


🔬 Experimental

Don't put this code on servers. You can, but you probably shouldn't.




💂 Strictness

When using python's builtin types for schema annotations, the data must be instances of the specified types or the load operation will fail with an exception. Unexpected and missing data will error by default.

🕵 Clarity

Validation errors mirror the structure of the data, provide insight into the values that caused the error, and present meaningful information to help resolve the problem.

🏃 Speed

The default functionality is fast and lean. The performance degrades gracefully as complex functionality is explicitly opted into by the developer.

🤸 Flexibility

Custom data types are created by defining formatter classes, then transfored into types compatible with the builtin typing module.

💃 Expressiveness

Python's builtin typing generics can be leveraged to declare complex type unions that know how to automatically handle multiple types using a syntax that is explicit and concise.


pip install marsha


Need to create database model instances from user input and expose them in serialized form?

Creating a schema that is separate from the model is a useful way to declare a "view" and allows defining multiple schemas to control how data is exposed in different contexts.

from my_app.database_models import Artist, Album

import marsha
from typing import List

class ArtistSchema:
    name: str

class AlbumSchema:
    title: str
    artists: List[Artist]

# dict -> Album
album = marsha.load(album_data, Album)
# Do stuff
# Album -> dict
response_data = marsha.dump(album)

Just need to validate some data and convert it to the correct type?

You can automatically register the type annotations of any model as a schema by adding the schema decorator.

import marsha
from typing import List

class Artist(dict):
    name: str

class Album(dict):
    title: str
    artists: List[Artist]

# dict -> dict
album = marsha.load(album_data, Album)
# Do stuff
first_artist = album['artists'][0]


📚 Dependencies

# python >= 3.6
pip install -r dev-requirements.txt

🏅 Testing

# Quick testing.
# Ensure all statements and branches are covered with tests.
pytest --cov=marsha --cov-branch --cov-report html --cov-report term
# Ensure documentations changes render correctly.
make html

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

marsha-0.2.4.tar.gz (9.5 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page