Graphora Python Client
Official Python client and CLI for the Graphora API
A Python client for interacting with the Graphora API. This library provides a simple and intuitive interface for working with Graphora's graph-based data processing capabilities. Graphora is a Text to Knowledge Graphs platform that helps you transform unstructured text into powerful knowledge graphs.
Features
- CLI Tool: Extract knowledge graphs from the command line
- Complete API Coverage: Access all Graphora API endpoints
- Type Safety: Fully typed with Pydantic models
- Dual Mode: Run locally (embedded) or via remote API
- Async Support: Efficient handling of long-running operations
- Minimal Dependencies: Lightweight with few external dependencies
Installation
# Basic client library
pip install graphora
# With CLI support
pip install graphora[cli]
Quick Start
CLI (Fastest - 3 commands)
# 1. Install
pip install graphora[cli]
# 2. Configure (downloads graphora-api automatically)
graphora config init --api-key "your-gemini-api-key"
# 3. Extract!
graphora extract document.pdf -o graph.json
That's it! The CLI automatically downloads and manages graphora-api for you.
Python Client
import os
from graphora import GraphoraClient
# Initialize client with a Clerk-issued bearer token. The base URL defaults to
# GRAPHORA_API_URL (or https://api.graphora.io if unset), so you can omit it
# for most cases.
client = GraphoraClient(
auth_token=os.environ["GRAPHORA_AUTH_TOKEN"],
)
# Upload an ontology
with open("ontology.yaml", "r") as f:
ontology_yaml = f.read()
ontology = client.register_ontology(ontology_yaml)
# Upload documents and wait for processing
transform = client.transform(
ontology_id=ontology.id,
files=["document1.pdf", "document2.txt"],
)
final_status = client.wait_for_transform(transform.id)
print("Transform status:", final_status.overall_status)
# Inspect the resulting graph
graph = client.get_transformed_graph(transform_id=transform.id)
print(
f"Nodes: {graph.total_nodes or len(graph.nodes)} | "
f"Edges: {graph.total_edges or len(graph.edges)}"
)
# Start merging the processed data
merge = client.start_merge(
session_id=ontology.id,
transform_id=transform.id,
)
CLI Usage
The Graphora CLI provides a convenient way to extract knowledge graphs from documents.
Configuration
Config is stored in ~/.graphora/config.yaml:
# Interactive setup
graphora config init
# Set individual values
graphora config set llm.api_key "your-gemini-api-key"
graphora config set defaults.mode embedded # or 'remote'
# View configuration
graphora config show
# Check status
graphora status
Extraction
# Extract with auto-inferred schema
graphora extract document.pdf -o graph.json
# Extract multiple files
graphora extract doc1.pdf doc2.pdf docs/ -o combined.json
# Use custom schema
graphora extract document.pdf --schema ontology.yaml -o graph.json
# Output as Cypher statements
graphora extract document.pdf -f cypher -o import.cypher
# Verbose output
graphora extract document.pdf -o graph.json -v
Schema Management
# Infer schema from documents
graphora schema infer document.pdf -o ontology.yaml
# Validate a schema file
graphora schema validate ontology.yaml
Inspecting graphs (remote mode)
These commands talk to a Graphora API server and need --mode remote.
# Show the evidence and decisions behind a node or edge
graphora explain tx_abc123 --node-id n_alice
graphora explain tx_abc123 --edge-id e_works_at --json > evidence.json
# Compare two transforms — added / removed / changed
graphora diff tx-old tx-new
graphora diff tx-old tx-new --json | jq '.summary'
graphora diff tx-old tx-new -n 5 # tighter detail tables
Scenarios (named graph snapshots)
A scenario is a named point-in-time snapshot of a transform's extracted graph — useful for branching what-if comparisons before publishing.
# Create a snapshot
graphora scenario create -t tx-abc -n baseline
graphora scenario create -t tx-abc -n "merge-alice-alicia" -d "what-if ER"
# List / show / delete
graphora scenario list
graphora scenario show sc-abc123
graphora scenario delete sc-abc123 --yes # --yes for non-interactive use
Regression testing against a golden corpus
# Informational run — exit 0 regardless of F1
graphora test golden/
# Gate CI on nodes.f1 and edges.f1 >= 0.6
graphora test golden/ --min-f1 0.6
# Capture the full per-doc report
graphora test golden/ -o report.json
Each subdirectory of the corpus must contain document.txt, ontology.yaml,
and expected.json. Exit codes: 0 all green, 1 at least one below
threshold, 2 configuration / corpus problem.
MCP integration
Wire Graphora's MCP server into an agent client's config:
# Workspace-relative install (cursor / vscode / codex / claude-code)
graphora install cursor
# User-global install
graphora install claude-desktop
# Preview without writing
graphora install cursor --dry-run
Supported clients: claude-code, claude-desktop, codex, cursor,
vscode. Existing mcpServers entries are preserved unless you pass
--force.
Modes
The CLI supports two modes:
| Mode | Description | Requirements |
|---|---|---|
embedded |
Runs extraction locally (default) | Gemini API key only |
remote |
Uses hosted Graphora API | API URL + auth token |
Embedded mode (recommended) runs the full extraction pipeline locally:
# Auto-downloads graphora-api, just need your API key
graphora config init --api-key "your-gemini-key"
Remote mode uses the hosted Graphora API:
graphora config init --mode remote \
--api-url "https://api.graphora.io" \
--auth-token "your-token"
Updating
# Update graphora-api to latest version
graphora update
# Install specific version
graphora update --version v1.2.0
Advanced: Custom API Path
For local development, you can point to your own graphora-api clone:
graphora config set embedded.api_path /path/to/my/graphora-api
Environment Variables
The following environment variables can be used to configure the client:
GRAPHORA_AUTH_TOKEN: Clerk-issued bearer token (preferred)GRAPHORA_API_KEY: Legacy API key support (deprecated; replaced by bearer tokens)GRAPHORA_USER_ID: Optional user ID for client-side bookkeepingGRAPHORA_API_URL: Custom API URL (optional). Defaults tohttps://api.graphora.ioif unset.
Core API Methods
Ontology Management
register_ontology(ontology_yaml)- Register and validate an ontologyget_ontology(ontology_id)- Retrieve an ontology by ID
Document Processing
transform(ontology_id, files, metadata=None)- Upload documents for processingget_transform_status(transform_id)- Check transformation statuswait_for_transform(transform_id)- Wait for transformation to completecleanup_transform(transform_id)- Clean up transformation data
Graph Operations
get_transformed_graph(transform_id)- Retrieve graph dataupdate_transform_graph(transform_id, changes)- Save graph modifications
Merge Operations
start_merge(session_id, transform_id)- Start merging processed dataget_merge_status(merge_id)- Check merge statusget_conflicts(merge_id)- Get conflicts requiring resolutionresolve_conflict(merge_id, conflict_id, ...)- Resolve specific conflictsget_merge_statistics(merge_id)- Get merge statisticsget_merged_graph(merge_id, transform_id)- Retrieve merged graph
Documentation
For detailed documentation, see the docs directory or visit our official documentation website.
Examples
Check out the examples directory for sample code demonstrating various use cases:
manage_ontology.py- Ontology creation and managementupload_and_transform.py- Document upload and transformationmodify_graph.py- Graph data manipulationmerge_graph_data.py- Merging and conflict resolution
Contributing
We welcome contributions! Please see our Contributing Guide for details.
Before Contributing
- Read the Code of Conduct
- Sign the Contributor License Agreement
- Check out good first issues
Documentation
- Contributing Guide - How to contribute
- Security Policy - How to report security issues
- Support - How to get help
- Trademark Policy - Trademark usage guidelines
- Examples - Code examples
Related Repositories
- Frontend: graphora/graphora-fe
- Backend API: graphora/graphora-api
License
This project is licensed under the MIT License.
See LICENSE for full terms.
Community
- GitHub Discussions: Ask questions, share ideas
- Discord: Coming soon
- Twitter: Coming soon
Security
Please report security vulnerabilities to support@graphora.io
See SECURITY.md for details.
Made with ❤️ by Arivan Labs
Metadata
Release files for graphora 0.5.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| graphora-0.5.1.tar.gz | 98.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| graphora-0.5.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 177.5 kB
Release files / graphora-0.5.1.tar.gz
| Download URL | graphora-0.5.1.tar.gz |
|---|---|
| Size | 98.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f828099ac83a71a10f47901924d714889773e746378845650eaadb947e0b63d0
|
|
BLAKE2b-256 checksum How to use checksums |
10962c068f6c20e7266424095c9a866f62e8e14ba2211493358502145dabe6de
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / graphora-0.5.1-py3-none-any.whl
| Download URL | graphora-0.5.1-py3-none-any.whl |
|---|---|
| Size | 78.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1f207a6175c889e300c228eaea0e0a1ff3989d46f369cc300e38b7ebbe0095c1
|
|
BLAKE2b-256 checksum How to use checksums |
66e1b2633ffdee2494b50e91d78356a62cf163e45574c655d1b0afa6540802d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Security for graphora 0.5.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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.