Schemars is a high-performance Python serialization library, leveraging Rust and PyO3 for efficient handling of complex objects

Overview

Schemars

PyPI version Downloads

Introduction

Schemars is a Python package, written in Rust and leveraging PyO3, designed for efficient and flexible serialization of Python class instances. It provides a simple yet powerful schema-based approach to serialize complex Python objects.

Installation

To install Schemars, run the following command:

pip install schemars

Requirements

  • Python 3.x
  • Rust (optional for development)

Usage

To use Schemars, define your Python class and corresponding schema class, then serialize instances as shown below:

class Product:
    def __init__(self, name, price, created):
        self.name = name
        self.price = price
        self.created = created

product = Product("test", 10, "1577836800")

import schemars
class ProductSchema(schemars.Schema):
    name = schemars.Str(strict=True)
    price = schemars.Decimal()
    created = schemars.Date(format='%Y/%m/%d')

print(ProductSchema().serialize(product))

Documentation Coming Soon!

We are currently working on comprehensive documentation for Schemars, which will cover detailed usage, advanced features, and integration guides. Stay tuned for updates, and feel free to reach out to us with any specific questions or suggestions in the meantime.

Upcoming in Version 1.0

In the upcoming Version 1.0 of Schemars, we will be introducing additional functionalities including both validation and deserialization. This enhancement aims to provide a more comprehensive and robust experience in handling and processing Python class instances.

Inspired by Marshmallow and Django REST Framework

Schemars was developed in response to performance challenges encountered with existing serialization tools like Marshmallow and Django REST Framework. Our goal was to create a solution that not only addresses these performance issues but also remains user-friendly and familiar.

Easy Migration

If you're already using Marshmallow or Django REST Framework, you'll find Schemars's syntax and usage comfortably similar. This design choice is intentional to ensure that migration to Schemars is smooth and can be accomplished in just minutes. We have prioritized maintaining a familiar interface while significantly enhancing performance, so you can switch to Schemars with minimal adjustments to your existing codebase.

Benchmarking Schemars

Quick Benchmark Setup

To compare Schemars with Django REST Framework (DRF), Marshmallow and Pydantic, follow these steps:

Installation

Install benchmarking requirements:

python3 -m pip install -r bench/requirements.txt

Running the Benchmark

Execute the benchmark script:

python3 bench/run.py

This will run serialization tasks using Schemars, Marshmallow, DRF and Pydantic, allowing you to directly compare their performance.

License

Schemars is released under the [MIT License]

You might also like...
A high-performance WebSocket integration library for streaming public market data. Used as a key dependency of the `barter-rs` project.

Barter-Data A high-performance WebSocket integration library for streaming public market data from leading cryptocurrency exchanges - batteries includ

Rust based Kubernetes Operator to deploy K8s objects minimally.

kube-nimble nimble /ˈnɪmbl/ - quick and light in movement or action; agile. This project began from a place of curiosity about Kubernetes CRDs and the

This crate provides a set of functions to generate SQL statements for various PostgreSQL schema objects

This crate provides a set of functions to generate SQL statements for various PostgreSQL schema objects, such as tables, views, materialized views, functions, triggers, and indexes. The generated SQL statements can be useful for schema introspection, documentation, or migration purposes.

This is a `Rust` based package to help with the management of complex medicine (pill) management cycles.
This is a `Rust` based package to help with the management of complex medicine (pill) management cycles.

reepicheep This is a Rust based package to help with the management of complex medicine (pill) management cycles. reepicheep notifies a person(s) via

A program that provides LLMs with the ability to complete complex tasks using plugins.

SmartGPT SmartGPT is an experimental program meant to provide LLMs (particularly GPT-3.5 and GPT-4) with the ability to complete complex tasks without

A complex numbers, graphing, cli calculator

calc requires gnuplot for graphing history file is stored in ~/.config/.calc_history or C:\\Users\\%USERNAME%\\AppData\\Roaming\\calc.history usage Us

The joker_query is a cute query builder, with Joker can implement most complex queries with sugar syntax
The joker_query is a cute query builder, with Joker can implement most complex queries with sugar syntax

joker_query The joker_query is most sugared query builder of Rust, with joker_query can implement most complex queries with sugar syntax Features − (O

The high-speed IAPWS-IF97 package in Rust with C and Python binding
The high-speed IAPWS-IF97 package in Rust with C and Python binding

SEUIF97 This is the Rust implementation of the high-speed IAPWS-IF97 package seuif97 with C and Python binding. It is suitable for computation-intensi

High-performance and normalised trading interface capable of executing across many financial venues

High-performance and normalised trading interface capable of executing across many financial venues. Also provides a feature rich simulated exchange to assist with backtesting and dry-trading.

Releases(v0.4.0)
  • v0.4.0(Nov 25, 2023)

    What's Changed

    • Update benchmarks by @Mng-dev-ai in https://github.com/Mng-dev-ai/schemars/pull/14
    • Update readme by @Mng-dev-ai in https://github.com/Mng-dev-ai/schemars/pull/15
    • Add child to Dict field by @Mng-dev-ai in https://github.com/Mng-dev-ai/schemars/pull/16
    • improvements by @Mng-dev-ai in https://github.com/Mng-dev-ai/schemars/pull/17
    • Add UUID field by @Mng-dev-ai in https://github.com/Mng-dev-ai/schemars/pull/18
    • Add Any field by @Mng-dev-ai in https://github.com/Mng-dev-ai/schemars/pull/19
    • Add alias support for fields by @Mng-dev-ai in https://github.com/Mng-dev-ai/schemars/pull/20
    • Add mimalloc by @Mng-dev-ai in https://github.com/Mng-dev-ai/schemars/pull/21
    • v0.4.0 by @Mng-dev-ai in https://github.com/Mng-dev-ai/schemars/pull/22

    Full Changelog: https://github.com/Mng-dev-ai/schemars/compare/v0.3.2...v0.4.0

    Source code(tar.gz)
    Source code(zip)
  • v0.3.2(Nov 20, 2023)

    What's Changed

    • Allow schema to store custom attributes by @Mng-dev-ai in https://github.com/Mng-dev-ai/schemars/pull/11
    • Add examples by @Mng-dev-ai in https://github.com/Mng-dev-ai/schemars/pull/12
    • v0.3.2 by @Mng-dev-ai in https://github.com/Mng-dev-ai/schemars/pull/13

    Full Changelog: https://github.com/Mng-dev-ai/schemars/compare/v0.3.1...v0.3.2

    Source code(tar.gz)
    Source code(zip)
  • v0.3.1(Nov 19, 2023)

    What's Changed

    • Enhance serialization to support general iterables by @Mng-dev-ai in https://github.com/Mng-dev-ai/schemars/pull/9
    • v0.3.1 by @Mng-dev-ai in https://github.com/Mng-dev-ai/schemars/pull/10

    Full Changelog: https://github.com/Mng-dev-ai/schemars/compare/v0.3.0...v0.3.1

    Source code(tar.gz)
    Source code(zip)
  • v0.3.0(Nov 19, 2023)

    What's Changed

    • CD update by @Mng-dev-ai in https://github.com/Mng-dev-ai/schemars/pull/6
    • Add call to schema trait by @Mng-dev-ai in https://github.com/Mng-dev-ai/schemars/pull/7

    Full Changelog: https://github.com/Mng-dev-ai/schemars/compare/v0.2.0...v0.3.0

    Source code(tar.gz)
    Source code(zip)
  • v0.2.0(Nov 19, 2023)

    What's Changed

    • Fix CD by @Mng-dev-ai in https://github.com/Mng-dev-ai/schemars/pull/3
    • Update CD by @Mng-dev-ai in https://github.com/Mng-dev-ai/schemars/pull/4
    • v0.2.0 by @Mng-dev-ai in https://github.com/Mng-dev-ai/schemars/pull/5

    Full Changelog: https://github.com/Mng-dev-ai/schemars/compare/v0.1.0...v0.2.0

    Source code(tar.gz)
    Source code(zip)
  • v0.1.0(Nov 18, 2023)

    What's Changed

    • Fix CI by @Mng-dev-ai in https://github.com/Mng-dev-ai/schemars/pull/1
    • v0.1.0 by @Mng-dev-ai in https://github.com/Mng-dev-ai/schemars/pull/2

    New Contributors

    • @Mng-dev-ai made their first contribution in https://github.com/Mng-dev-ai/schemars/pull/1

    Full Changelog: https://github.com/Mng-dev-ai/schemars/commits/v0.1.0

    Source code(tar.gz)
    Source code(zip)
Owner
Michael Gendy
Michael Gendy
PyO3 bindings and Python interface to skani, a method for fast fast genomic identity calculation using sparse chaining.

?? ⛓️ ?? Pyskani PyO3 bindings and Python interface to skani, a method for fast fast genomic identity calculation using sparse chaining. ??️ Overview

Martin Larralde 13 Mar 21, 2023
Ethereum transaction simulator leveraging Foundry's codebase

Enso Transaction ?? Simulator ?? A simple API which simulates a given transaction request. ?? API ?? POST /api/v1/simulate Simulates a single transact

null 162 Jun 4, 2023
A simple Rust library for OpenAI API, free from complex async operations and redundant dependencies.

OpenAI API for Rust A community-maintained library provides a simple and convenient way to interact with the OpenAI API. No complex async and redundan

null 6 Apr 4, 2023
PyO3's PyAny as a serde data format

serde-pyobject PyO3's PyAny as a serde data format Usage Serialize T: Serialize into &'py PyAny: use serde::Serialize; use pyo3::{Python, types::{PyAn

Jij 3 Nov 24, 2023
A rust library + CLI tool that tells you when swas will upload new video through complex calculations

A rust library + CLI tool that tells you when swas will upload new video through complex calculations. It also lets you search and play youtube videos of swas and other channels. Searching about youtube channels is also an option. Basically it's a youtube search cli tool written in rust.

midnightFirefly 4 Jun 10, 2022
Rust CLI utility library. Error handling, status reporting, and exit codes.

narrate This library provides CLI application error and status reporting utilities. The coloured output formatting aims to be similar to Cargo. Error

Christopher Morton 5 Nov 2, 2022
A library that creates a terminal-like window with feature-packed drawing of text and easy input handling. MIRROR.

BearLibTerminal provides a pseudoterminal window with a grid of character cells and a simple yet powerful API for flexible textual output and uncompli

Tommy Ettinger 43 Oct 31, 2022
A high-performance Rust library designed to seamlessly integrate with the Discord API.

Rucord - Rust Library for Discord API Interactions Note: This library is currently under development and is not yet recommended for production use. Ov

Coders' Collab 4 Feb 26, 2023
High-performance Javascript color gradient library powered by Rust + WebAssembly

colorgrad-js High-performance Javascript color gradient library powered by Rust + WebAssembly. No dependencies. Faster than d3-scale, chroma-js, culor

Nor Khasyatillah 168 Apr 25, 2023
A modern high-performance open source file analysis library for automating localization tasks

?? Filecount Filecount is a modern high-performance open source file analysis library for automating localization tasks. It enables you to add file an

Babblebase 4 Nov 11, 2022