Skip to main content

Official Python implementation of ODIN (Open Data Interchange Notation)

Project description

odin-foundation

PyPI License

Official Python SDK for ODIN (Open Data Interchange Notation) — a canonical data model for transporting meaning between systems, standards, and AI.

Install

pip install odin-foundation

Requires Python 3.8+

Quick Start

import odin

doc = odin.parse("""
{policy}
number = "PAP-2024-001"
effective = 2024-06-01
premium = #$747.50
active = ?true
""")

print(doc["policy.number"])   # "PAP-2024-001"
print(doc["policy.premium"])  # 747.50

text = odin.dumps(doc)

Core API

Function Description Example
odin.parse(text) Parse ODIN text into a document doc = odin.parse(src)
odin.dumps(doc) Serialize document to ODIN text text = odin.dumps(doc)
odin.loads(text) Alias for parse (Python-idiomatic) doc = odin.loads(src)
odin.stringify(doc) Alias for dumps text = odin.stringify(doc)
odin.canonicalize(doc) Deterministic bytes for hashing/signatures b = odin.canonicalize(doc)
odin.validate(doc, schema) Validate against an ODIN schema result = odin.validate(doc, schema)
odin.parse_schema(text) Parse a schema definition schema = odin.parse_schema(src)
odin.diff(a, b) Structured diff between two documents changes = odin.diff(doc_a, doc_b)
odin.patch(doc, diff) Apply a diff to a document updated = odin.patch(doc, changes)
odin.parse_transform(text) Parse a transform specification tx = odin.parse_transform(src)
odin.execute_transform(tx, source) Run a transform on data out = odin.execute_transform(tx, doc)
doc.to_json() Export to JSON json_str = doc.to_json()
doc.to_xml() Export to XML xml_str = doc.to_xml()
doc.to_csv() Export to CSV csv_str = doc.to_csv()
odin.dumps(doc) Export to ODIN odin_str = odin.dumps(doc)
odin.builder() Fluent document builder odin.builder().section("policy")...

Schema Validation

import odin

schema = odin.parse_schema("""
{policy}
!number : string
!effective : date
!premium : currency
active : boolean
""")

doc = odin.parse(source)
result = odin.validate(doc, schema)

if not result.valid:
    for error in result.errors:
        print(error)

Transforms

import odin

transform = odin.parse_transform("""
map policy -> record
  policy.number -> record.id
  policy.premium -> record.amount
""")

result = odin.execute_transform(transform, doc)

Export

odin_str = odin.dumps(doc)    # ODIN string
json_str = doc.to_json()     # JSON string
xml_str  = doc.to_xml()      # XML string
csv_str  = doc.to_csv()      # CSV string

Builder

doc = (odin.builder()
    .section("policy")
    .set("number", "PAP-2024-001")
    .set("effective", date(2024, 6, 1))
    .set("premium", odin.currency(747.50))
    .set("active", True)
    .build())

Testing

Tests use pytest and the shared golden test suite:

pytest

Links

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

odin_foundation-1.2.2.tar.gz (351.3 kB view details)

Uploaded Source

Built Distribution

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

odin_foundation-1.2.2-py3-none-any.whl (237.3 kB view details)

Uploaded Python 3

File details

Details for the file odin_foundation-1.2.2.tar.gz.

File metadata

  • Download URL: odin_foundation-1.2.2.tar.gz
  • Upload date:
  • Size: 351.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for odin_foundation-1.2.2.tar.gz
Algorithm Hash digest
SHA256 7b5423e2f52d171ea66bda8ade1d0f522d24a65cc57c6c8b539dee56b7dea698
MD5 ce952566760c2a0e3e8582ff6d42d41d
BLAKE2b-256 03b3afbcf605e389f3a9fc93b4c0279812975608b2d01451cfa5bdfbadd711c7

See more details on using hashes here.

Provenance

The following attestation bundles were made for odin_foundation-1.2.2.tar.gz:

Publisher: publish.yml on odin-foundation/odin-core-python

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

File details

Details for the file odin_foundation-1.2.2-py3-none-any.whl.

File metadata

  • Download URL: odin_foundation-1.2.2-py3-none-any.whl
  • Upload date:
  • Size: 237.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for odin_foundation-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 925e5a6a3507b0aa5c0441c0cd237ab428b57b689f4ee70e8672289f0dfa483e
MD5 6c8e4b62c1f0f834aed34acc4c0a68d8
BLAKE2b-256 bc861542b68a6802b8d67b6a0463bda8b83195926f41b6dcf60cb1cc7ea9a411

See more details on using hashes here.

Provenance

The following attestation bundles were made for odin_foundation-1.2.2-py3-none-any.whl:

Publisher: publish.yml on odin-foundation/odin-core-python

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