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.7-cp313-cp313-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.13Windows x86-64

kglite-0.6.7-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.7-cp313-cp313-macosx_11_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 10.12+ x86-64

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

Uploaded CPython 3.12Windows x86-64

kglite-0.6.7-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.7-cp312-cp312-macosx_11_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.12macOS 10.12+ x86-64

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

Uploaded CPython 3.11Windows x86-64

kglite-0.6.7-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.7-cp311-cp311-macosx_11_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 10.12+ x86-64

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

Uploaded CPython 3.10Windows x86-64

kglite-0.6.7-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.7-cp310-cp310-macosx_11_0_arm64.whl (2.8 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

kglite-0.6.7-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.7-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: kglite-0.6.7-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.7-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 d6731b501353b5b5f15aa69deb453bf38c7cbc9f12b98cef7702c7f2fa37831d
MD5 c04e0dcd8c7ab1b089a0daf62171accd
BLAKE2b-256 0f5b5103978488aa0a3ab4207aba4dd523bff01684a2adea8925313d256b38a1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.7-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 c1d62d80c93a95f775095fd75f17084f37f3a4fd579814a8b6954518e8019274
MD5 e4df50e70ebfbc08eb11e6a0075712c1
BLAKE2b-256 c11a19e13b740dc9c7f660bf408c83d63bb69ee81f0e2f19786daf775bc4d691

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.7-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 91076c754a3f01aef4470a3366831b4244ad6ae2db45cece58fc3268cd5a44f5
MD5 184cda98ae9b0e39c0633333ba540b40
BLAKE2b-256 d0c03beee59069ff33d892779c57cd39b38dce8dde1bf819521aa152c29b5a6b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.7-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 f68ad8c80ed83ad4514a6a33a23e1e22abd80be1b4a5c5fe7527262862c46807
MD5 ee3bc444cab8fa458bfa6369d020e077
BLAKE2b-256 b0403ccc752b10aac0449e97856445e9bb7c1a5daab06b2985fe11d645355557

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.6.7-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.7-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 f2587469937b56a8e6e2c06707b863d46f53210f96cc5a25708246fad8066090
MD5 0ec9ac55a1d9d06f3f76fb6daaf01434
BLAKE2b-256 badff93189328c95ce3d2a5c7582ac1c7f897be46da80ecf1f6f79e75a2e34b2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.7-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 174fe94f139434cc22c030bc58d4079187846a0759683c9c91bef698ad9f7f17
MD5 6861f4b406bac74c0f14dcc647031268
BLAKE2b-256 51d85f7705bee78e3739c77a327a75d59038d60e218525cf210dcba21b581df8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.7-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 75154b4ad8ddb9902813b6637cf5be7c83b44e0e398a4753d6bffb91d90e19f3
MD5 b13c147267b812de7a0425618ab0fad9
BLAKE2b-256 93da96c95d6ca8ee8fc63bd39d260d759cd75dd7b1bb254cb6eeb9b220ab9274

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.7-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 6b4fd87aa6cac7293d1687020cdb46a684b3344554337055afa320926791cb05
MD5 7269c1c3e0eba7e3a43badb0936c93f5
BLAKE2b-256 113e98a979fa783d7f7eea859e3466946bb91994594d665c72d4b27ed4e6727b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.6.7-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.7-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 02902064df6a5be5af9b7408ebd77ed797b0dba58095a09271713e3a55ef7a7c
MD5 b7f56b0f6ae5b49a7dbfa977f903f2b7
BLAKE2b-256 f3bd17b7bf8e217891ce26efab47b814884332dec95cb769cf44f2f1d0ee3abc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.7-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 40f5c82ebd1a00c472b5e85424fa93f6d2771a379d69487cf2a1657516c5b29a
MD5 b3348a10cd4aceb4c929934ab14f66d5
BLAKE2b-256 4c30f9e32da2e88de4efcb0dfc0500af3b72efe4993890168237841454c31c5e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.7-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7e5d9fc96f2f07bfc4644fb432b7d4148881f8ad73054d4662cffb1422db6453
MD5 45a30625014cffae50c9deab254b8172
BLAKE2b-256 dc3a972185b413664f45a457c9ebadd56978211d05f048ed9cce192f02398841

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.7-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 400cc8b162ff40b0f90bf4e360ef2977e10a2a08466c98fcb0bc7f08d4aa4be5
MD5 b52d6aeea14c8e1a124446478e00e688
BLAKE2b-256 0da204c324c04e7fa4c4a42fac89776a7426293ed8191a4cbcbd29095dcd1c4e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.6.7-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.7-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 641821b14ecef98b007324cad18426229ddd0912cbe80396d186f019ef965e0e
MD5 163473668792a6e133980cf080a1542f
BLAKE2b-256 a3cca591c469a13b483b013a9eb7bec3a36414608e1d101ece89b524a7a10747

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.7-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 90e818c81370191b92ddacdc6f0386cd8569ee0139ac8f6f4b01d6204de64bc2
MD5 82f648cda426684d5842ecc2cb72a479
BLAKE2b-256 9e12c7099e8c9a93cc49a0dc3cc9fa1a50c0795434d32d14c53955dc7f775122

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.7-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7eae14e93902bc57122b39b44c46e1d67dd24f2035c0848806634a02c4be70c0
MD5 36665bb6801cba02fa68d03f0ba8da17
BLAKE2b-256 53862647fd7e2581121df36d1657e2ca2752a1b170a5ff2861b2f4cd84af4643

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.7-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 336eccc434fc3fe3e032f21ec55b32285485482fae149ad560a25cdc109075ec
MD5 24bc059baccc8d45f8bff0924871edbe
BLAKE2b-256 28a78ecf1b31516f895a8af1a5107a424ac0117a88d2797cef7a0c367daf5a33

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