Skip to main content

Onya is a knowledge graph expression and implementation. This repository combines a data model and format spec with a Python parser and API implementation.

Python quick start

Installation

Requires Python 3.12 or later. The package is still in early development, so install directly from source:

git clone https://github.com/OoriData/Onya.git
cd Onya
pip install -U .

Basic Usage

Here's a simple example demonstrating the core Onya API. First, let's define a small friendship graph in Onya Literate format:

# @docheader

* @document: http://example.org/friendship-graph
* @base: http://example.org/people/
* @schema: https://schema.org/
* @type-base: https://schema.org/

# Chuks [Person]

* name: Chukwuemeka Okafor
* nickname: Chuks
* age: 28

# Ify [Person]

* name: Ifeoma Adebayo
* nickname: Ify
* age: 27

Now let's parse this graph and interact with it using the Python API:

from onya.graph import graph
from onya.serial import literate_lex

# Parse the Onya Literate text into a graph
onya_text = '''
# @docheader

* @document: http://example.org/friendship-graph
* @base: http://example.org/people/
* @schema: https://schema.org/
* @type-base: https://schema.org/

# Chuks [Person]

* name: Chukwuemeka Okafor
* nickname: Chuks
* age: 28

# Ify [Person]

* name: Ifeoma Adebayo
* nickname: Ify
* age: 27
'''

g = graph()
doc_iri = literate_lex.parse(onya_text, g)
print(f"Parsed document: {doc_iri}")
print(f"Graph has {len(g)} nodes")

# Access nodes and their properties
chuks = g['http://example.org/people/Chuks']
ify = g['http://example.org/people/Ify']

# Get a specific property value
for prop in chuks.getprop('https://schema.org/name'):
    print(f"Name: {prop.value}")

# Add a friendship edge between Chuks and Ify
friendship = chuks.add_edge('https://schema.org/knows', ify)
print(f"Added edge: {friendship}")

# Add nested properties to the friendship (metadata about the relationship)
friendship.add_property('https://schema.org/startDate', '2018-03-15')
friendship.add_property('https://schema.org/description', 'Met at university')

# Add a new property to Ify
ify.add_property('https://schema.org/jobTitle', 'Software Engineer')

# Modify a property by removing the old one and adding a new one
age_props = list(chuks.getprop('https://schema.org/age'))
for prop in age_props:
    chuks.remove_property(prop)
chuks.add_property('https://schema.org/age', '29')

# Traverse edges
for edge in chuks.traverse('https://schema.org/knows'):
    friend = edge.target
    for name_prop in friend.getprop('https://schema.org/name'):
        print(f"Chuks knows: {name_prop.value}")
    # Access nested properties on the edge
    for date_prop in edge.getprop('https://schema.org/startDate'):
        print(f"  Friends since: {date_prop.value}")

# Find all nodes of a certain type
for person in g.typematch('https://schema.org/Person'):
    for name_prop in person.getprop('https://schema.org/name'):
        print(f"Person in graph: {name_prop.value}")

This example demonstrates:

  • Parsing Onya Literate format
  • Accessing nodes and properties
  • Adding edges with nested properties (reified relationships)
  • Modifying properties
  • Traversing the graph
  • Querying by type

Background

Onya is based on experience from developing Versa and also working on the MicroXML spec and implementations thereof.

The URL used for metavocabulary is managed via purl.org.

The name is from Igbo "ọ́nyà", web, snare, trap, and by extension, network. The expanded sense is ọ́nyà úchè, web of knowledge.

Contributing

Contributions welcome! We're interested in feedback from the community about what works and what doesn't in real-world usage. To get help with the code implementation, read CONTRIBUTING.md.

License

The specification is under CC BY 4.0 to encourage broad adoption and derivative work while ensuring attribution. We want the format itself to be as open and reusable as possible, allowing anyone to create implementations in any language or adapt the format for their specific needs.

Acknowledgments

Created by Oori Data. Word Loom emerged from our work building multilingual LLM applications and finding gaps in existing prompt management approaches.

Related Work

  • networkx: Network Analysis in Python
  • Apache AGE: PostgreSQL Extension that for graphs. ANSI SQL & openCypher over the same DB.

Metadata

Release files for Onya 0.1.1

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

Source distribution (sdist)

Source distribution for Onya 0.1.1
File Size Uploaded Provenance Actions
onya-0.1.1.tar.gz 21.3 kB With provenance Details for onya-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for Onya 0.1.1
File Interpreter ABI Platform Actions
onya-0.1.1-py3-none-any.whl Python 3 none any Details for onya-0.1.1-py3-none-any.whl

Total release size: 37.6 kB

Release files / onya-0.1.1.tar.gz

Download URL onya-0.1.1.tar.gz
Size 21.3 kB
Tags Source
SHA-256 checksum
How to use checksums
8a09497aaaf0c974cbccdd2c1e71fd51d5d96089a70b1aa334c580486627ad2a
BLAKE2b-256 checksum
How to use checksums
8550bf3630f163c9bd633369d6bd4bd16a46fbc1e535725be0c3a18ae22d9ffc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Nov 18, 2025.

Transparency log

Release files / onya-0.1.1-py3-none-any.whl

Download URL onya-0.1.1-py3-none-any.whl
Size 16.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1aef71d0b2bf5b0c1d3bc5564801129d973d39fba276b1de828b700e32fbc8d0
BLAKE2b-256 checksum
How to use checksums
69fc9c47716c647cca8879ffc95fde5e8183c52a6398a4f6f503e03dfde8a8e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Nov 18, 2025.

Transparency log

Security for Onya 0.1.1

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for onya-0.1.1.tar.gz

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 Nov 18, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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