Skip to main content

A high-performance graph database library with Python bindings written in Rust

Project description

KGLite — Lightweight Knowledge Graph for Python

PyPI version Python versions License: MIT Docs

An embedded, in-memory knowledge graph database for Python — built in Rust for speed, with a Cypher query engine, semantic search, and first-class support for RAG pipelines and AI agents. No server, no setup, no infrastructure. Just pip install kglite and go.

Why KGLite?

  • Zero infrastructure — runs inside your Python process. No database server to install, configure, or maintain.
  • Fast — Rust core (via PyO3 + petgraph) with zero-copy where possible. Load millions of nodes without leaving Python.
  • Query with Cypher — familiar graph query language for pattern matching, mutations, aggregations, and traversals.
  • Built for AI — semantic search with text_score(), schema introspection via describe(), and a ready-made MCP server for LLM tool use.
  • DataFrames in, DataFrames out — bulk-load from pandas, query results as DataFrames. Fits naturally into data science workflows.

Quick Start

pip install kglite
import kglite

graph = kglite.KnowledgeGraph()

# Create nodes and relationships
graph.cypher("CREATE (:Person {name: 'Alice', age: 28, city: 'Oslo'})")
graph.cypher("CREATE (:Person {name: 'Bob', age: 35, city: 'Bergen'})")
graph.cypher("""
    MATCH (a:Person {name: 'Alice'}), (b:Person {name: 'Bob'})
    CREATE (a)-[:KNOWS]->(b)
""")

# Query — returns a ResultView (lazy; data stays in Rust until accessed)
result = graph.cypher("""
    MATCH (p:Person) WHERE p.age > 30
    RETURN p.name AS name, p.city AS city
    ORDER BY p.age DESC
""")
for row in result:
    print(row['name'], row['city'])

# Or get a pandas DataFrame
df = graph.cypher("MATCH (p:Person) RETURN p.name, p.age ORDER BY p.age", to_df=True)

# Persist to disk and reload
graph.save("my_graph.kgl")
loaded = kglite.load("my_graph.kgl")

Use Cases

RAG & Retrieval Pipelines

Store documents, chunks, and entities as a knowledge graph. Use text_score() for semantic similarity search and Cypher for structured retrieval — combine both for hybrid RAG.

graph.cypher("""
    MATCH (c:Chunk)
    RETURN c.text, text_score(c.embedding, $query_vec) AS score
    ORDER BY score DESC LIMIT 5
""", params={"query_vec": query_embedding})

AI Agent Memory & Tool Use

Give LLM agents a structured, queryable memory. describe() generates a progressive-disclosure schema that agents can reason over, and the included MCP server exposes the graph as a tool.

xml = graph.describe()  # schema for agent context
prompt = f"You have a knowledge graph:\n{xml}\nAnswer using graph.cypher()."

Data Exploration & Analysis

Load CSVs or DataFrames, explore relationships, run graph algorithms (shortest path, centrality, community detection), and export results — all without leaving your notebook.

graph.add_nodes(data=users_df, node_type='User', unique_id_field='user_id', node_title_field='name')
graph.cypher("MATCH path = shortestPath((a:User {name:'Alice'})-[*]-(b:User {name:'Eve'})) RETURN path")

Codebase Analysis

Parse Python and Rust codebases into a knowledge graph with functions, classes, calls, and imports. Search, trace dependencies, and review code structure.

from kglite.code_tree import build
graph = build(".")
graph.cypher("MATCH (f:Function) RETURN f.name, f.file ORDER BY f.name")

Key Features

Feature Description
Cypher queries MATCH, CREATE, SET, DELETE, MERGE, aggregations, ORDER BY, LIMIT, SKIP
Semantic search Vector embeddings + text_score() for similarity ranking
Graph algorithms Shortest path, centrality, community detection, clustering
Spatial Coordinates, WKT geometry, distance and containment queries
Timeseries Time-indexed data with ts_*() Cypher functions
Bulk loading Fluent API (add_nodes / add_connections) for DataFrames
Blueprints Declarative CSV-to-graph loading via JSON config
Import/Export Save/load snapshots, GraphML, CSV export
AI integration describe() introspection, MCP server, agent prompts
Code analysis Parse codebases via tree-sitter (kglite.code_tree)

Documentation

Full docs at kglite.readthedocs.io:

Requirements

Python 3.10+ (CPython) | macOS (ARM/Intel), Linux (x86_64/aarch64), Windows (x86_64) | pandas >= 1.5

License

MIT — see LICENSE for details.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

kglite-0.6.10-cp313-cp313-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.13Windows x86-64

kglite-0.6.10-cp313-cp313-manylinux_2_35_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.35+ x86-64

kglite-0.6.10-cp313-cp313-macosx_11_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

kglite-0.6.10-cp313-cp313-macosx_10_12_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

kglite-0.6.10-cp312-cp312-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.12Windows x86-64

kglite-0.6.10-cp312-cp312-manylinux_2_35_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.35+ x86-64

kglite-0.6.10-cp312-cp312-macosx_11_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

kglite-0.6.10-cp312-cp312-macosx_10_12_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

kglite-0.6.10-cp311-cp311-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.11Windows x86-64

kglite-0.6.10-cp311-cp311-manylinux_2_35_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.35+ x86-64

kglite-0.6.10-cp311-cp311-macosx_11_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

kglite-0.6.10-cp311-cp311-macosx_10_12_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

kglite-0.6.10-cp310-cp310-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.10Windows x86-64

kglite-0.6.10-cp310-cp310-manylinux_2_35_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.35+ x86-64

kglite-0.6.10-cp310-cp310-macosx_11_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

kglite-0.6.10-cp310-cp310-macosx_10_12_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.10macOS 10.12+ x86-64

File details

Details for the file kglite-0.6.10-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: kglite-0.6.10-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 3.1 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kglite-0.6.10-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 96515ba3831a945d696c5594dbca51ee0db9fd3f79a8912299aac37cfc3ccb9a
MD5 bd829ac56fb137b78c454cdbc4777b33
BLAKE2b-256 33dec88c46ba90a631fd0b052f6f094bf5ab74c351841df9eb1d59da47d69556

See more details on using hashes here.

File details

Details for the file kglite-0.6.10-cp313-cp313-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for kglite-0.6.10-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 14ba7415a038288a8b38533282bbb7c2bdbdaa48179a16bf6a7f4c36d8d3ab5d
MD5 98b53af831b98f36e6402d4facb8534b
BLAKE2b-256 4a7c6c586ddeea1981577ee52084db4807805085d1b2f3b1bf48fdc10b1697e3

See more details on using hashes here.

File details

Details for the file kglite-0.6.10-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for kglite-0.6.10-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4271eee3fe9c0ed1b70df2a0c3754230c4da68c11ee9e322bf6118d64ff534a7
MD5 e4ce6df490fdd261e7a430ded55b4b57
BLAKE2b-256 12d45faed504fc0b18e7831a3cea42070f7e0bdd3f78aa4e376a94614eef8d8c

See more details on using hashes here.

File details

Details for the file kglite-0.6.10-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for kglite-0.6.10-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b491e6d0dbb0000a7a272c6e19728433c1533b258b4679860943d34aa233879b
MD5 a7d6b91999453cc8885e80d9b1b4246b
BLAKE2b-256 5877bdb22745f99e48d3144cc240ee0a1cd2f7238eb7835a221c76e1787dda60

See more details on using hashes here.

File details

Details for the file kglite-0.6.10-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: kglite-0.6.10-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 3.1 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kglite-0.6.10-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 0adee7644815ff63ca7106e3d1d2b6829b614dd3a02679207613259df34e5d66
MD5 5fdfc56270bc4b7dbfc3e2c678e42b2d
BLAKE2b-256 39d21e2f8eda5d09043fa341cd8273a8791dc0ed104d292152b4ff8a37c19fa4

See more details on using hashes here.

File details

Details for the file kglite-0.6.10-cp312-cp312-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for kglite-0.6.10-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 670818aa9896ea695dfefc11649fc33cbc73a5fb68ef70772962ee4174affd66
MD5 62a592f17d4ccc4e10db21541d2992b2
BLAKE2b-256 a5d0fde23f546c491c772eae5a16a9cb5a88b38ed75189cd33ffcf5ffdcbc15d

See more details on using hashes here.

File details

Details for the file kglite-0.6.10-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for kglite-0.6.10-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0a31dfb4b11009254ba75b4efb3c3bd4206892973f93b4fc9e1aa8630ee0d846
MD5 f897a37b02f8f1e1807dcb0c034ecde2
BLAKE2b-256 bdc981a55e42fe89bd66c30ce26e592c17cebaad72079c923d4acdf78baaa040

See more details on using hashes here.

File details

Details for the file kglite-0.6.10-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for kglite-0.6.10-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 0a005d8e7a28080fad8e92b2b2d6b4ac809d4cd5b53deb47751f40e5d5223979
MD5 605435939d3b709bec050b721f7d6da3
BLAKE2b-256 cefe4c08bfac57b994467e06d817d1b67f66e8077f3591962ab2768e2c58d342

See more details on using hashes here.

File details

Details for the file kglite-0.6.10-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: kglite-0.6.10-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 3.1 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kglite-0.6.10-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 d4e7cd5669d44dc06ac5e1eafade16cff5caea3ca4089313ed6980b0c9f476da
MD5 cc70b0cd81fa4362ec0292ac32a908a9
BLAKE2b-256 e922f51e91f428b9c52a2f479a013ecca9a2b1f5615d7bd544400db2de6c3b35

See more details on using hashes here.

File details

Details for the file kglite-0.6.10-cp311-cp311-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for kglite-0.6.10-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 90a275a1520a9a6c8fdca63b198de493ad3cb594e4e735f52e8efbe09ed55458
MD5 94d847c35b88f18adddb8ffe7e1f5076
BLAKE2b-256 4f192094663a33c692789762cd27d5d5e7c9f64666dc6ef61c2b606622bfc547

See more details on using hashes here.

File details

Details for the file kglite-0.6.10-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for kglite-0.6.10-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 49f53660031d8e0f72407ba76520b7f224706136b3f1b5ad5d9f1fb27a0b9ed5
MD5 7f6e436927af06ecfb0fdd0a8b3e0bda
BLAKE2b-256 3f39e9f0550ddbb2c1548b0a342b8dd215f796ab9b1d4c42bdf6cae11668d165

See more details on using hashes here.

File details

Details for the file kglite-0.6.10-cp311-cp311-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for kglite-0.6.10-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 00b08ee8f7d2cd6414d870b6efe4107b846a81b22fa1fa65c0151ca68778c485
MD5 523222a1a4b1b9c4e0081bef9a75184e
BLAKE2b-256 fece22c40872759f50e3a06eb23d594a5b085d02ee4e89aa5b6093f5da9fbd3f

See more details on using hashes here.

File details

Details for the file kglite-0.6.10-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: kglite-0.6.10-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 3.1 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kglite-0.6.10-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 3f40c05caa617773e0792148fee8f2440db332cc5d852c092103bc15714f3f35
MD5 923d35334e749e9b11c84e503d418b34
BLAKE2b-256 e48d646701d08241ec401100445fb052237c9f382607af20439f76779945836b

See more details on using hashes here.

File details

Details for the file kglite-0.6.10-cp310-cp310-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for kglite-0.6.10-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 92af2554d064b7a566ccb6770d7c0d14edac3a34ee3d72400f38cf6eea66e5d9
MD5 8aac05e6cb45bdf178eb1b80d40c2adb
BLAKE2b-256 89d00fe6d52619596980a6b0cef5a14a261c3fbe2758a6d04aafd650c918a009

See more details on using hashes here.

File details

Details for the file kglite-0.6.10-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for kglite-0.6.10-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c01666edc98735e9edfa7f2df1ed9cd5b850f76eeb1366d2b2b9f2aed4d0448d
MD5 482366c03df55766a3511d52f8b7337c
BLAKE2b-256 89c71f849fde9dd68498dced2f023d8ac6af2629b852f789ae99a34816877250

See more details on using hashes here.

File details

Details for the file kglite-0.6.10-cp310-cp310-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for kglite-0.6.10-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 0a11b7010d8d76cf630a86dcccad4bcabd482fd35cf004822159b098a41b81d1
MD5 ea7a268ecd53b004b799b1620134a578
BLAKE2b-256 7d3e0aaa476228a5d36b47821e5fa03b212f05ee7ddbd2f61b1c0d2c7f75b699

See more details on using hashes here.

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