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

Uploaded CPython 3.13Windows x86-64

kglite-0.7.5-cp313-cp313-manylinux_2_35_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.35+ x86-64

kglite-0.7.5-cp313-cp313-macosx_11_0_arm64.whl (3.2 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

kglite-0.7.5-cp313-cp313-macosx_10_12_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

kglite-0.7.5-cp312-cp312-win_amd64.whl (3.6 MB view details)

Uploaded CPython 3.12Windows x86-64

kglite-0.7.5-cp312-cp312-manylinux_2_35_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.35+ x86-64

kglite-0.7.5-cp312-cp312-macosx_11_0_arm64.whl (3.2 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

kglite-0.7.5-cp312-cp312-macosx_10_12_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

kglite-0.7.5-cp311-cp311-win_amd64.whl (3.6 MB view details)

Uploaded CPython 3.11Windows x86-64

kglite-0.7.5-cp311-cp311-manylinux_2_35_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.35+ x86-64

kglite-0.7.5-cp311-cp311-macosx_11_0_arm64.whl (3.2 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

kglite-0.7.5-cp311-cp311-macosx_10_12_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

kglite-0.7.5-cp310-cp310-win_amd64.whl (3.6 MB view details)

Uploaded CPython 3.10Windows x86-64

kglite-0.7.5-cp310-cp310-manylinux_2_35_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.35+ x86-64

kglite-0.7.5-cp310-cp310-macosx_11_0_arm64.whl (3.2 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

kglite-0.7.5-cp310-cp310-macosx_10_12_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.10macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for kglite-0.7.5-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 3144edcc3b16f9cedd739b94d74d7571ba216935941c7302790abdb3e14f8d47
MD5 2e6d9adff7b2cde92797ddff5a08bad0
BLAKE2b-256 c9641e50eaf6814ee48624cb346d132445d06c8822391baa3ae2f6c844834e53

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.5-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 69d56164a5ced8cd4b5c87159eaf9aa44c16e7d43fdfe794dcf7f1ab78637ce8
MD5 b4af08346e79c69a9a08b94443a57daf
BLAKE2b-256 77188bbb7e7e2b1c9e2ab1b597007546c46127d81a1f65019a9ef153c3da7150

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.5-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 29f72dfffb2b873a5c79232f78e8e43de2b9c10154488d384f1c737cdc14237d
MD5 8481e0ac637c9311c26d9a937b27636c
BLAKE2b-256 adbf4fd5e32f98925ba9afbab7e04b897c87520f215b3dd7fba00817d1a2d7d7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.5-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 f95cd2c41b07487bc87619b5597f9296fae80e8a1568f5516abeb1d66b53211f
MD5 f8ffeece23ec549eca2fb788ef2d2fe9
BLAKE2b-256 a1f601da9af05fb380bd3f453cd5a752ec814e5042bc01254ac9d61c298d1a6a

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for kglite-0.7.5-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 3728127bc8b381f1da04977956ef5c3a3eeff034a7fc907080eee90cf1fc75b9
MD5 1c6d418f9695dae893c46295c283c1fd
BLAKE2b-256 45d74b179c46259195f75935ae16a3bfca84f61af25902ee21385ae0c2175f97

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.5-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 105b9c40dad9724f59bc77c0154d5737d9480bcb19caad59a6e2a89d5280eb23
MD5 a2997316d73c2e11242017127465a9d6
BLAKE2b-256 5f961c50c72fe202ce17cc907e2e71d69ba47516292b0fbbf7a495e710cf5bd9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.5-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6a6db65decbfc6f47613def1e58a3d05c9202faf15a2e4c59ac0d207ad45d781
MD5 2738497a581d7a04dada061b2d8af57b
BLAKE2b-256 d56866ead788dd5ad1a1cc156d522cc82325f4c31666a44c10eff2ebb12c8739

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.5-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 7c603fb82e30c706b6f2bc9b80a4c66f5b7f322c8b1079675970794ee1f20ace
MD5 672314cce7d6e4e830fb8ea53f81f4fb
BLAKE2b-256 7d94ce3c6de53c3fee27f3d67b2e14ef002658cfb331416f038922180c3b951d

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for kglite-0.7.5-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 e9ac0b8da9c71d0d92f3f4c026d06362aeedaf4f5cf27422ab6cfaf0e8df8884
MD5 73589c5a89fc0342a52a82e8c21fda38
BLAKE2b-256 6817cbbb6712fde5b940c6dd183ece40a256d49408c9be5550844df3e47d5545

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.5-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 9e34f22a88ac22a4a6ebc58ea3baf578dd6bb1f482da75597e3e47304a91107a
MD5 47a5cfdd18a26394d664e2aa58e9dec5
BLAKE2b-256 1b8bec2b6ab5c8f8e9ae92cc2f8ec1547c8ee7c60426829bc66c3f0ca2c45eec

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.5-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3722aa43bd999326c9fc0592cc31240ebb23cffe80ccb59d3ca2ee3cb50e451e
MD5 bf5bd759905559985dbd502bff58972c
BLAKE2b-256 79611b764160c6df2682e7c06c4f1f565cf974c31bad02efe6298082ceffe246

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.5-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 11ffa2bead28d6c0818ceeff524c1b038da826b851a8e2a8c883b2a0c2ea3ac5
MD5 7620608212a61c3d27e1697d166e6af3
BLAKE2b-256 7657d94ca8f8611eff600a3a5c8d0656e5dc327f8dfad85c20fc4ba6737869f7

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for kglite-0.7.5-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 d7e48b3e13a10cf08d42dbe23b37af489881dd11a972bd419b5aac162589dc91
MD5 9c445845647d567a5b1c04c04efd65af
BLAKE2b-256 8e82760e36993d1fea036b564e0aa49b83ae7914dde77ff7ccc9dbfb58e6a43a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.5-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 4af3de33a18f83e2eb3f9afbde79c901ac7186aea7df6f510506b9c83fe8fd84
MD5 1461ab880d3df01a9a4cf3c9da5f924a
BLAKE2b-256 8958558a6389741d4f716919d221816a263dee8aedef499797e0e4dfd47541ea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.5-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3ce604e4e3eb3a932265c46c649b522e0ed34186fd0dccf4976301f55bd11d13
MD5 c6a86ba6839b56961f31b0507fabd9cd
BLAKE2b-256 236c40c9d9047fa9bb7e7fab25fe9694e37b1826a58dfd37b104e95a52cf7062

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.5-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ddebd52dc90efbf11a757a9248d6d896fbae9a9180b417ce80dd98f408753045
MD5 e5e562284ec43bdf3bd285e6340c9d8d
BLAKE2b-256 60809366d1828d657edcdada0d1f70af678cd794ff14dac8a2c5dc15cd0ec509

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