{"id":4761,"library":"serpyco-rs","title":"serpyco-rs: High-Performance Dataclass Serialization and Validation","description":"Serpyco-rs is a high-performance Python library for serializing and deserializing dataclasses, inspired by `serpyco`. It leverages Rust for speed and provides features like data validation, JSON Schema generation (Draft 2020-12), and custom encoder/decoder support. It supports Python 3.9+ and maintains a frequent release cadence, with version 1.20.0 being the latest as of March 2026.","status":"active","version":"1.20.0","language":"en","source_language":"en","source_url":"https://github.com/ermakov-oleg/serpyco-rs","tags":["serialization","deserialization","json","dataclasses","performance","rust","validation","json-schema"],"install":[{"cmd":"pip install serpyco-rs","lang":"bash","label":"Install serpyco-rs"}],"dependencies":[],"imports":[{"note":"The primary class for defining serializers for dataclasses.","symbol":"Serializer","correct":"from serpyco_rs import Serializer"},{"note":"Used to define the data structures that serpyco-rs serializes.","symbol":"dataclass","correct":"from dataclasses import dataclass"}],"quickstart":{"code":"import dataclasses\nfrom serpyco_rs import Serializer\n\n@dataclasses.dataclass\nclass User:\n    id: int\n    name: str\n    email: str\n    is_active: bool = True\n\n# Create a serializer for the User dataclass\nuser_serializer = Serializer(User)\n\n# Create a User instance\nuser_instance = User(id=1, name=\"Alice\", email=\"alice@example.com\")\n\n# Serialize the dataclass instance to a dictionary\ndumped_data = user_serializer.dump(user_instance)\nprint(f\"Dumped data: {dumped_data}\")\n# Expected: {'id': 1, 'name': 'Alice', 'email': 'alice@example.com', 'is_active': True}\n\n# Load data from a dictionary into a dataclass instance\nloaded_data = {'id': 2, 'name': 'Bob', 'email': 'bob@example.com', 'is_active': False}\nuser_from_dict = user_serializer.load(loaded_data)\nprint(f\"Loaded instance: {user_from_dict}\")\n# Expected: User(id=2, name='Bob', email='bob@example.com', is_active=False)\n\n# Generate JSON Schema for the dataclass\njson_schema = user_serializer.json_schema()\nprint(f\"JSON Schema: {json_schema}\")","lang":"python","description":"This example demonstrates how to define a dataclass, create a serializer for it, and then use the serializer to dump a dataclass instance to a dictionary, load a dictionary into a dataclass instance, and generate a JSON Schema for the defined structure."},"warnings":[{"fix":"For explicit control, use the `inclusive` flag (e.g., `Min(value, inclusive=False)` or `Max(value, inclusive=False)`) to restore exclusive behavior where needed.","message":"As of v1.20.0, `Min` and `Max` validators are now inclusive by default. If your existing code or schemas relied on exclusive behavior without explicitly setting an `inclusive` flag, this change will alter validation logic.","severity":"breaking","affected_versions":">=1.20.0"},{"fix":"Ensure inputs strictly adhere to integer types where integers are expected, and booleans where booleans are expected. Upgrade to v1.17.1 or newer for correct type validation.","message":"Prior to v1.17.1, boolean values (`true`/`false`) were incorrectly accepted as integers during validation. If you were implicitly relying on this behavior, validation might now fail for such inputs.","severity":"gotcha","affected_versions":"<1.17.1"},{"fix":"Review generated JSON schemas after upgrading to ensure compatibility with downstream schema consumers. Adjust expectations or tooling to accommodate the more compliant schema output.","message":"For JSON Schema generation, simple union types now correctly generate `anyOf` constructs (since v1.17.0) and integer fields explicitly include `\"format\": \"int64\"` (since v1.15.0). These changes improve JSON Schema compliance but might cause discrepancies for consumers expecting older schema formats.","severity":"gotcha","affected_versions":"<1.17.0 (union types), <1.15.0 (int64 format)"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}