Skip to main content

deontic

A constraint language for obligation, permission and prohibition — the things a system must do, may do, and must not do.

Status: alpha. The grammar is implemented and reproduces the whole conformance corpus: deontic.parse gives the AST, deontic.load reads a dictionary and deontic.resolve checks a sentence against it. There is no evaluator in this package, by design; the corpus's evaluate/ cases are for implementations that add one.

Why a language rather than a library

Deontic statements are usually buried in imperative checks, where the rule and the enforcement of the rule are the same code. Writing them down as data makes them reviewable by the people who own the policy rather than only by the people who own the codebase, and lets more than one evaluator agree on what a rule means.

Design

docs/design.md states what the language is meant to be: the closed-class vocabulary, the shapes, filters and paths, attestation, the storage form, the interpretation rules, the outcome model, and how it relates to Attempto Controlled English and to deontic logic.

Conformance

conformance/ is the normative test data: source text plus the result every implementation must agree on, kept as data rather than Python tests so that an implementation in another language can consume it too. An implementation is conformant when it reproduces the corpus. It has three parts — parse/ (source to AST, no lexicon needed), reject/ (source to error) and evaluate/ (sentences, a world and a date to outcomes) — over one invented fixture lexicon, and its README records the language decisions the cases fix.

Use

import deontic

ast = deontic.parse("Every $exhibit$ tagged fragile must @be located in@ a $gallery$ tagged storage.")
# {'shape': 'obligation', 'subject': {...}, 'predicate': {...}}

lexicon = deontic.load("conformance/lexicon.json")
deontic.resolve(ast, lexicon)   # raises a ResolutionError with the corpus's error code otherwise

Sentences are authored as English and stored with markers on the typed spans ($Term$, @verb@, #90 days#, <parameter>); editors write the markers, people do not. A verb's meaning is a pattern in the dictionary or, failing that, code under the contract in docs/hooks.md.

Install

pip install deontic

Stdlib only, no runtime dependencies — a grammar meant to be implemented by other people should not put a parser generator in everyone's dependency tree.

License

MIT.

Release files for deontic 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for deontic 0.1.0
File Size Uploaded
deontic-0.1.0.tar.gz 26.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for deontic 0.1.0
File Interpreter ABI Platform
deontic-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 47.3 kB

Release files / deontic-0.1.0.tar.gz

Download URL deontic-0.1.0.tar.gz
Size 26.7 kB
Tags Source
SHA-256 checksum
How to use checksums
9c699a8436e1fa866ee1862c36e3563513f2d6cda9938465f62d58671bdfaff7
BLAKE2b-256 checksum
How to use checksums
6878a292eabb506d4b437a9c07b970096c61e7f96b857db5cea9b3f5815b247d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 25, 2026.

Transparency log

Release files / deontic-0.1.0-py3-none-any.whl

Download URL deontic-0.1.0-py3-none-any.whl
Size 20.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e5ba9d6e750c2208ffe8b3443bb26c6ec00b040af4c12792a19560aef0bb23d5
BLAKE2b-256 checksum
How to use checksums
0d8e74afb2e78df4dda1cf79d0055e4dee7d4b3cbde0295ef56ef0dbdb936afd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 25, 2026.

Transparency log

Release history Release notifications | RSS feed

0.1.1

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page