Skip to main content

A powerful serialization framework for Python objects with automatic type registration and validation

Project description

Serilux ๐Ÿ“ฆ

PyPI version Python 3.7+ License Documentation

Serilux is a powerful, flexible serialization framework for Python objects. With its intuitive API and automatic type registration, you can easily serialize and deserialize complex object hierarchies with minimal code.

โœจ Why Serilux?

  • ๐ŸŽฏ Simple API: Just inherit from Serializable and you're ready to go
  • ๐Ÿ”„ Automatic Type Registration: Classes are automatically registered for deserialization
  • ๐Ÿ›ก๏ธ Type Safety: Built-in validation ensures objects can be properly deserialized
  • ๐ŸŒณ Nested Objects: Automatically handles nested Serializable objects, lists, and dictionaries
  • ๐Ÿ”ง Callable Serialization: Full support for serializing functions, methods, and lambda expressions
  • ๐Ÿ”’ Security: Strict mode prevents deserialization of unknown fields
  • โšก Zero Dependencies: Pure Python with no external dependencies
  • ๐ŸŽ“ Easy to Use: Minimal boilerplate, maximum flexibility

๐ŸŽฏ Perfect For

  • Object Persistence: Save and restore complex object states
  • Configuration Management: Serialize configuration objects to JSON/YAML
  • Data Transfer: Convert objects to dictionaries for API communication
  • State Management: Save application state for recovery
  • Workflow Orchestration: Serialize workflow definitions and states
  • Testing: Create test fixtures from serialized objects

๐Ÿ“ฆ Installation

Quick Install (Recommended)

pip install serilux

That's it! You're ready to go.

Development Install

For development with all dependencies:

pip install -e ".[dev]"
# Or using Makefile
make dev-install

๐Ÿš€ Quick Start

Create Your First Serializable Class in 3 Steps

Step 1: Define a Serializable Class

from serilux import Serializable, register_serializable

@register_serializable
class Person(Serializable):
    def __init__(self):
        super().__init__()
        self.name = ""
        self.age = 0
        # Register fields to serialize
        self.add_serializable_fields(["name", "age"])

Step 2: Create and Use Objects

# Create an object
person = Person()
person.name = "Alice"
person.age = 30

# Serialize to dictionary
data = person.serialize()
print(data)
# {'_type': 'Person', 'name': 'Alice', 'age': 30}

Step 3: Deserialize

# Deserialize from dictionary
new_person = Person()
new_person.deserialize(data)
print(new_person.name)  # "Alice"
print(new_person.age)   # 30

๐ŸŽ‰ Done! You've created your first serializable class.

๐Ÿ’ก Key Features

๐Ÿ”„ Automatic Type Registration

Classes decorated with @register_serializable are automatically registered:

@register_serializable
class MyClass(Serializable):
    def __init__(self):
        super().__init__()
        self.add_serializable_fields(["field1", "field2"])

๐ŸŒณ Nested Objects

Automatically handles nested Serializable objects:

@register_serializable
class Address(Serializable):
    def __init__(self):
        super().__init__()
        self.street = ""
        self.city = ""
        self.add_serializable_fields(["street", "city"])

@register_serializable
class Person(Serializable):
    def __init__(self):
        super().__init__()
        self.name = ""
        self.address = None
        self.add_serializable_fields(["name", "address"])

# Create nested objects
person = Person()
person.name = "Alice"
person.address = Address()
person.address.street = "123 Main St"
person.address.city = "New York"

# Serialize - nested objects are automatically handled
data = person.serialize()

๐Ÿ“‹ Lists and Dictionaries

Handles lists and dictionaries containing Serializable objects:

@register_serializable
class Team(Serializable):
    def __init__(self):
        super().__init__()
        self.name = ""
        self.members = []  # List of Person objects
        self.add_serializable_fields(["name", "members"])

team = Team()
team.name = "Engineering"
team.members = [person1, person2, person3]

# Serialize - list items are automatically serialized
data = team.serialize()

๐Ÿ”’ Strict Mode

Enable strict mode to prevent deserialization of unknown fields:

# Strict mode raises error for unknown fields
try:
    person.deserialize(data, strict=True)
except ValueError as e:
    print(f"Error: {e}")

โœ… Validation

Validate that objects can be properly deserialized:

from serilux import validate_serializable_tree

# Validate before serialization
validate_serializable_tree(person)

๐Ÿ“š Documentation

๐Ÿ“– Full documentation available at: serilux.readthedocs.io

Documentation Highlights

  • ๐Ÿ“˜ User Guide: Comprehensive guide covering all features
  • ๐Ÿ”ง API Reference: Complete API documentation
  • ๐Ÿ’ป Examples: Real-world code examples

Build Documentation Locally

pip install -e ".[docs]"
cd docs && make html

๐ŸŽ“ Examples

Check out the examples/ directory for practical examples:

  • basic_usage.py - Your first serializable class
  • advanced_usage.py - Nested objects, lists, and dictionaries
  • validation_example.py - Using validation features

Run examples:

python examples/basic_usage.py

๐Ÿ—๏ธ Project Structure

serilux/
โ”œโ”€โ”€ serilux/              # Main package
โ”‚   โ”œโ”€โ”€ __init__.py       # Package initialization
โ”‚   โ””โ”€โ”€ serializable.py   # Core serialization classes
โ”œโ”€โ”€ tests/                # Comprehensive test suite
โ”œโ”€โ”€ examples/             # Usage examples
โ””โ”€โ”€ docs/                 # Sphinx documentation

๐Ÿงช Testing

Serilux comes with comprehensive tests:

# Run all tests
make test-all

# Run with coverage
make test-cov

# Run specific test suite
pytest tests/

๐Ÿค Contributing

We welcome contributions! Here's how you can help:

  1. Star the project โญ - Show your support
  2. Report bugs ๐Ÿ› - Help us improve
  3. Suggest features ๐Ÿ’ก - Share your ideas
  4. Submit PRs ๐Ÿ”ง - Contribute code

๐Ÿ“„ License

Serilux is licensed under the Apache License 2.0. See LICENSE for details.

๐Ÿ”— Links

โญ Show Your Support

If Serilux helps you build amazing applications, consider giving it a star on GitHub!


Built with โค๏ธ by the Serilux Team

Making object serialization simple, powerful, and fun.

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

serilux-0.2.0.tar.gz (34.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

serilux-0.2.0-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

Details for the file serilux-0.2.0.tar.gz.

File metadata

  • Download URL: serilux-0.2.0.tar.gz
  • Upload date:
  • Size: 34.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.11

File hashes

Hashes for serilux-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c55a19a297d309c03b3a67b11bffc3f3825214dbb9d1429a0ca0c6990147d161
MD5 b31d09a095576f9fbafbd8ee820117bc
BLAKE2b-256 5c641843f109f2378521df269c8997dcc34517e46d08cfae4f79dc87731e9445

See more details on using hashes here.

File details

Details for the file serilux-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: serilux-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 18.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.11

File hashes

Hashes for serilux-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9f7af020d8e16e03f467be6c0b8043314575dcd27bebec4ee665afdf30df180b
MD5 a13fe22c81659e554bd7b8c0f8194c68
BLAKE2b-256 511ca67040972659dee27a5433a4c34ad506b037d4a50fcd006fbc81dad38c6e

See more details on using hashes here.

Supported by

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