Skip to main content

Documents schema and data validation

Project description

Dictify

Lightweight validation for Python mappings and JSON-like documents.

dictify is a lightweight validation library for standalone fields and mapping-shaped models.

It is designed for small schema layers, partial validation, and annotation-first models with explicit dict-like behavior.

  • Python 3.12+
  • Use Field(...) for defaults, required fields, and extra validators
  • Use Python annotations to declare Model field types
  • Access model data with either attributes or mapping syntax

Why Dictify?

  • Validate a single value with Field(...) without defining a full model
  • Define annotation-first Model classes for dict-shaped documents
  • Keep mapping access and attribute access together
  • Handle unknown keys and public attributes explicitly with strict
  • Convert back to plain Python data with dict(model) and model.dict()

Install

pip install dictify

Quick Example

from datetime import UTC, datetime
from typing import Annotated

from dictify import Field, Model


class Note(Model):
    title: Annotated[
        str,
        Field(required=True).verify(
            lambda value: len(value) <= 300,
            "Title must be 300 characters or fewer",
        ),
    ]
    content: Annotated[str, Field()]
    timestamp: Annotated[
        datetime,
        "creation time",
        Field(default=lambda: datetime.now(UTC)),
    ]


note = Note({"title": "Dictify", "content": "dictify is easy"})

note.content = "Updated content"
note["content"] = "Updated again"

# These raise Model.Error.
note.title = 0
note["title"] = 0

Strict Mode

Model is strict by default.

  • strict=True rejects undeclared keys and undeclared public attributes
  • strict=False stores undeclared keys and attributes as extra model data
note = Note({"title": "Dictify"}, strict=False)

note.category = "docs"
assert note["category"] == "docs"
assert dict(note)["category"] == "docs"

Native Conversion

Use explicit conversion when you need plain Python data.

import json

note_dict = dict(note)        # shallow dict conversion
note_native = note.dict()     # recursive dict/list conversion
note_json = json.dumps(note.dict())

Standalone Fields

Field.instance(...) still works well for standalone validation.

email = Field(required=True).instance(str).match(r".+@.+")
email.value = "user@example.com"

AI Skill

dictify ships with an installed CLI for the packaged AI skill.

dictify ai-skill-install

The installer prompts for the exact destination folder and defaults to:

.agents/skills/dictify-usage

If the destination already exists, dictify asks before overwriting it.

Development CLI

Repository-local maintenance commands live under dev/cli.

Run them from the repo root with:

uv run python -m dev.cli --help

Examples:

uv run python -m dev.cli docs build
uv run python -m dev.cli docs dev
uv run python -m dev.cli ai skill-ref
uv run python -m dev.cli build
uv run python -m dev.cli release-check

See dev/README.md for the command summary.

Typing Status

The annotation-first model API is fully supported at runtime.

For static type checkers, prefer Annotated[str, Field(...)] without assigning Field(...) as the class value. Declarations like email: str = Field(...) remain supported at runtime, but static type checker support for that assignment style may vary.

Documentation

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

dictify-4.1.1.tar.gz (16.7 kB view details)

Uploaded Source

Built Distribution

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

dictify-4.1.1-py3-none-any.whl (27.1 kB view details)

Uploaded Python 3

File details

Details for the file dictify-4.1.1.tar.gz.

File metadata

  • Download URL: dictify-4.1.1.tar.gz
  • Upload date:
  • Size: 16.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"43","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for dictify-4.1.1.tar.gz
Algorithm Hash digest
SHA256 de6c95fe0ac1667734923bdd011007ed4d349e571af366517f758a295f8bccd0
MD5 fd9d221a727a99522ec586f3c6ac0ba7
BLAKE2b-256 bd9fec4520e6feb84e0745e08b1bb4950d43b74d409901b396e0f61c3c5d45f3

See more details on using hashes here.

File details

Details for the file dictify-4.1.1-py3-none-any.whl.

File metadata

  • Download URL: dictify-4.1.1-py3-none-any.whl
  • Upload date:
  • Size: 27.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"43","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for dictify-4.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d8420d1a79d25257cb050c3b86d1ae01b7dfcf1378e0579a3a6d7b8fcafd9b02
MD5 fb6c65b9db916e3c913a00256f409f49
BLAKE2b-256 bf0487b395f98a4152746f6caf3d43767d24a2c389ea31c9e86ba882cc8d27e3

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