Skip to main content

Pythonic Object Serializer

Project description

Dii: A Pythonic Object Serializer

PyPI License

Dii is a lightweight and flexible Python library that enables easy serialization of class instances into dictionaries. It supports renaming fields dynamically, custom serialization logic, and automatic attribute extraction.


✨ Features

  • 🔹 Convert class instances into dictionaries with dictify()
  • 🔹 Rename attributes dynamically using field->new_name
  • 🔹 Custom serialization via _dictify_{field}() methods
  • 🔹 Automatic attribute detection (no need to list fields manually)
  • 🔹 Lightweight and dependency-free

📦 Installation

pip install dii

🚀 Quick Start

1️⃣ Basic Usage

from dii import Dictify

class User(Dictify):
    def __init__(self, username, email):
        self.username = username
        self.email = email

user = User("john_doe", "john@example.com")
print(user.dictify())  # {'username': 'john_doe', 'email': 'john@example.com'}

2️⃣ Select Specific Fields

print(user.dictify("username"))  
# {'username': 'john_doe'}

3️⃣ Rename Fields

print(user.dictify("username->user", "email->contact"))

{'user': 'john_doe', 'contact': 'john@example.com'}

4️⃣ Custom Serialization for Specific Fields

from datetime import datetime

from dii import Dictify

class User(Dictify):
    def __init__(self, username, created_at):
        self.username = username
        self.created_at = created_at

    def _dictify_created_at(self):
        return self.created_at.strftime('%Y-%m-%d')

user = User("john_doe", datetime(2025, 3, 15))
print(user.dictify())  
# {'username': 'john_doe', 'created_at': '2025-03-15'}

📝 License

Dii is released under the MIT License.

🤝 Contributing

Contributions are welcome! Feel free to submit issues or pull requests.

📮 Contact

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

diq-0.0.1.tar.gz (3.4 kB view details)

Uploaded Source

File details

Details for the file diq-0.0.1.tar.gz.

File metadata

  • Download URL: diq-0.0.1.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for diq-0.0.1.tar.gz
Algorithm Hash digest
SHA256 a56f7de5e115541bb013332d64d65298969f0660d6b021093e0a22cb43827baa
MD5 38a4a9e872e1c76c454c26970642b2a1
BLAKE2b-256 55f6609aa0e6acbfe1ac1c45c83012e69e03adc7ab05dbcfa5db0555fb7880e3

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