Skip to main content

Progressive Formalization for Markdown using Pydantic and Pytest

Project description

Typedown: The Consensus Modeling Language (CML)

License: MIT Python 3.12+ Linter: Ruff

Typedown is a language designed for Literate Modeling. It bridges the gap between the fluidity of human thought (Markdown) and the rigor of engineering (Pydantic + Pytest).

"You don't know it until you model it."Manifesto


The Trinity

Typedown treats Markdown as a first-class language for Consensus as Code (CaC), built on three pillars:

  1. Markdown (Interface): Retains nature language expressiveness. It's the habitat for humans and AI.
  2. Pydantic (Structure): Defines strict data schemas via model blocks.
  3. Pytest (Logic): Enforces business rules and constraints via spec blocks.

Why Typedown?

Traditional tools force a binary choice:

  • Liquids (Text/Markdown): High fluidity but zero structural integrity. Documentation rots instantly.
  • Crystals (Code/JSON/SQL): High integrity but zero flexibility. Hard for humans to browse and for AI to grasp intent.

Typedown is Active Soft Matter. It allows information to "phase transition" from loose notes into solid, validated models within the same document.

Core Features

  • Progressive Formalization: Start with a sketch, end with a verified system.
  • Triple Resolution: Resolve references [[ref]] through Hash (L0), Handle (L1), and Logical ID (L2).
  • Evolution Semantics: Track time using former (versioning) and derived_from (prototyping).
  • Context-Aware Scoping: Implicit hierarchy via config.td and directory inheritance.
  • QC Pipeline: Four-layered validation from syntax (Lint) to external facts (Test).

Quick Start

1. Define a Model

Define your schema directly in Markdown using Python:

```model:UserAccount
class UserAccount(BaseModel):
    name: str
    age: int = Field(..., ge=18)
    role: str = "member"
```

2. Declare an Entity

Instantiate data using YAML with smart reference unboxing:

```entity UserAccount: alice
id: "iam/user/alice-v1"
name: "Alice"
age: 30
role: "admin"
```

3. Write a Specification

Add business logic that targets your data:

```spec id=check_roles
@target(type="UserAccount")
def validate_admin(subject: UserAccount):
    if subject.role == "admin":
        assert subject.age >= 25, "Admins must be senior"
```

CLI Usage

The td tool is your companion for the development loop:

  • td lint: (L1) Check Markdown syntax and YAML formatting.
  • td check: (L2) Validate entities against Pydantic models.
  • td validate: (L3) Check references and run spec blocks (Internal Logic).
  • td test: (L4) Run external verification (Oracles/APIs).
  • td run <script>: Execute scripts defined in Front Matter.

Installation

Typedown thrives in the uv ecosystem.

# Clone and sync
git clone https://github.com/IndenScale/Typedown.git
cd Typedown
uv sync

# Run help
uv run td --help

# Or use the alias
uv run typedown --help

Documentation


License

MIT © IndenScale

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

typedown-0.2.3.tar.gz (200.3 kB view details)

Uploaded Source

Built Distribution

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

typedown-0.2.3-py3-none-any.whl (73.3 kB view details)

Uploaded Python 3

File details

Details for the file typedown-0.2.3.tar.gz.

File metadata

  • Download URL: typedown-0.2.3.tar.gz
  • Upload date:
  • Size: 200.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for typedown-0.2.3.tar.gz
Algorithm Hash digest
SHA256 a41dccf5d1bb7bbce7ee6cf36136be3d9e2cbd60bd67001a66a12e29959976f7
MD5 147dfb5711c79c73fe11393b581d71a2
BLAKE2b-256 d9272c0a9e0c13319939a2e71f9ee301fadcfbe065eb1ba019a49af654a319e9

See more details on using hashes here.

Provenance

The following attestation bundles were made for typedown-0.2.3.tar.gz:

Publisher: publish-pypi.yml on IndenScale/Typedown

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file typedown-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: typedown-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 73.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for typedown-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 3992878050eb58c526e152af1bfa68a80a1178e197412a10644e772246b76bf9
MD5 c7eb7751ce20e7adab86b95d92dc12ca
BLAKE2b-256 4c76ef402682602f6ac878e764627e3e3240fb0b2dca81359c3948178a516982

See more details on using hashes here.

Provenance

The following attestation bundles were made for typedown-0.2.3-py3-none-any.whl:

Publisher: publish-pypi.yml on IndenScale/Typedown

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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