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.4.tar.gz (203.7 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.4-py3-none-any.whl (73.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: typedown-0.2.4.tar.gz
  • Upload date:
  • Size: 203.7 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.4.tar.gz
Algorithm Hash digest
SHA256 7666be8851ba864948278e3439726546f0e15b93aae774b3d26d7ec2fee09304
MD5 23c7b496b7ac2de7f789bcb796a1534e
BLAKE2b-256 2602b73e79bc83dd7a3363fa2fd8a66284368801b429d6d01330c20e2f1dfa0d

See more details on using hashes here.

Provenance

The following attestation bundles were made for typedown-0.2.4.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.4-py3-none-any.whl.

File metadata

  • Download URL: typedown-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 73.7 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8efee7c6d5f3a061166b03dc674b67b7103dff9cf27a7a92607749c2c1f13ab8
MD5 e6c6956c985401bb3fd35768893f9bdd
BLAKE2b-256 f08f81178ee569b2c800963a67f6f1f0ca3394d12f9333d30986737c7422ccd6

See more details on using hashes here.

Provenance

The following attestation bundles were made for typedown-0.2.4-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