Skip to main content

Marsha

pipeline status coverage report

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

Status

🔬 Experimental

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

Documentation

📖 https://deckar01.gitlab.io/marsha

Features

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

Installation

pip install marsha

Usage

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

@marsha.schema(Artist)
class ArtistSchema:
    name: str

@marsha.schema(Album)
class AlbumSchema:
    title: str
    artists: List[Artist]

# dict -> Album
album = marsha.load(album_data, Album)
# Do stuff
album.save()
# 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

@marsha.schema()
class Artist(dict):
    name: str

@marsha.schema()
class Album(dict):
    title: str
    artists: List[Artist]

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

Development

📚 Dependencies

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

🏅 Testing

# Quick testing.
flake8
pytest
# 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

Metadata

Release files for marsha 0.2.4

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

Source distribution (sdist)

Source distribution for marsha 0.2.4
File Size Uploaded Provenance
marsha-0.2.4.tar.gz 9.5 kB Without provenance Details

Release files / marsha-0.2.4.tar.gz

Download URL marsha-0.2.4.tar.gz
Size 9.5 kB
Tags Source
SHA-256 checksum
How to use checksums
6e41dceded88344c81320575333f50fcc86c14d0ac45f42a46731ecdf4b5ec98
BLAKE2b-256 checksum
How to use checksums
909a8ab8357aa223595fbeae160573a9cc762c6f33410fa387a3b2cb3d9c9651
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for marsha 0.2.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

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