Skip to main content

A strongly typed list of dictionaries data type with validation and serialization support.

Project description

listofdicts

Enterprise-grade strongly-typed list of dictionaries for Python


Summary

listofdicts is a powerful custom Python data structure designed for modern data processing, data pipelines, ETL systems, API layers, and JSON-based applications where structured lists of dictionaries are commonly used.


Key Features

  • ✅ Only allows dictionaries inside.
  • ✅ Optional schema validation (enforce required keys and value types).
  • ✅ Optional immutability (lock data after loading).
  • ✅ Full JSON serialization/deserialization.
  • ✅ Supports deep copying and safe mutations.
  • ✅ Strict runtime type safety.
  • ✅ Merge and update support.
  • ✅ Fully tested and production-grade.

Installation

pip install listofdicts

Usage

from listofdicts import listofdicts

# Define schema for safety
schema = {
    'id': int,
    'name': str,
    'active': bool
}

lod = listofdicts([
    {'id': 1, 'name': 'Alice', 'active': True},
    {'id': 2, 'name': 'Bob', 'active': False}
], schema=schema)

# Append valid
lod.append({'id': 3, 'name': 'Carol', 'active': True})

# Partial update
lod.update_item(0, {'active': False})

# Merge with another listofdicts
lod2 = listofdicts([
    {'id': 4, 'name': 'Eve', 'active': True}
], schema=schema)

merged = lod.merge(lod2)

# Serialize to JSON
json_str = merged.to_json(indent=2)

# Deserialize from JSON
restored = listofdicts.from_json(json_str, schema=schema)

print(restored)

Why Use listofdicts?

  • Prevent accidental bad data.
  • Fail fast with strict schema enforcement.
  • Easy to serialize and deserialize.
  • Safer than plain list[dict].
  • Perfect for: ETL, API validation, data cleaning pipelines.

API Summary

Method Description append() Append a validated dictionary extend() Extend with another listofdicts merge() Merge two instances update_item() Partially update an entry copy() Deep copy as_mutable() Return mutable copy as_immutable() Return immutable copy to_json() Serialize to JSON from_json() Deserialize from JSON immutable Property to check mutability schema Property to access schema

Directory Structure

listofdicts/
    ├── src/
    │   ├── __init__.py
    │   └── listofdicts.py
    ├── tests/
    │   └── test_listofdicts.py
    ├── README.md
    ├── pyproject.toml
    ├── setup.cfg
    └── LICENSE

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

listofdicts-1.0.0.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

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

listofdicts-1.0.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file listofdicts-1.0.0.tar.gz.

File metadata

  • Download URL: listofdicts-1.0.0.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.5

File hashes

Hashes for listofdicts-1.0.0.tar.gz
Algorithm Hash digest
SHA256 3acb4cdc4fa7bd63fef0283585d6814e5475dce24147a1f62e64cdaededff7e2
MD5 e07d2529e55d5df82ecdc288e26c09b2
BLAKE2b-256 434673ed5d9942ea2cb7c68df6e520bc53f347812b19db5484c5635e82056cd8

See more details on using hashes here.

File details

Details for the file listofdicts-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: listofdicts-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.5

File hashes

Hashes for listofdicts-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1f6b16cca831e9f9998b5249acdc0c7e982ef83b6faf6596fa61b40759445ffc
MD5 1447cecb842a15edfa2b8805e66c85f9
BLAKE2b-256 0b1fd0d0cde7d2a2253b38f738a9a278be3755413b3518485b02893f0042d567

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