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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 10.12+ x86-64

kglite-0.6.14-cp312-cp312-win_amd64.whl (3.2 MB view details)

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.12macOS 10.12+ x86-64

kglite-0.6.14-cp311-cp311-win_amd64.whl (3.2 MB view details)

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

kglite-0.6.14-cp311-cp311-macosx_10_12_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

kglite-0.6.14-cp310-cp310-win_amd64.whl (3.2 MB view details)

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

kglite-0.6.14-cp310-cp310-macosx_10_12_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.10macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: kglite-0.6.14-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 3.2 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.14-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 c8470f0efa96be8616539158e543876bf2492314c60af4c050754e022fcbd1e7
MD5 d4ae6952c171f8db2f8600a0ddc9d787
BLAKE2b-256 f0a54c7d6dfab7ea3761a6027795c763b04a911d26a68d0dde14595788eccad7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.14-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 c458338ebcb02f36f5fc3ae486708d951b353eb6bc186c9c4c8397e0247e1ac0
MD5 9d583c41da95ab6c1443fef0e102fe30
BLAKE2b-256 bf9f01e042832f4960209c9c0edeb4a34bcb1ace08f9a3d2a3cc28bd4135b401

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.14-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c121e9ba8bd5f095a212c5bf6c80352666faeb74b4b901ec0474f7dacc67a517
MD5 4acb6ece59e5bdb59a8cc3288946859e
BLAKE2b-256 ead1ce25440af0e8c264ab026b140cb82527abe259f25c54ab06be7d93305e37

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.14-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ff5c360633bdedae78d9f602d86f2f5121d6edf2df7aa3515c16245caded144b
MD5 3944eb3437145ee772271fa49cc6d3a6
BLAKE2b-256 d921ecbab4c34a140571fca4f8009be3fc061bdc2ac9d27a8d28bbf0658c7d0d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.6.14-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 3.2 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.14-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 ddd1941b56fa3c6b8d36c7f0ac6314691f45b8881de6024d8d638986c0d33a3e
MD5 73d14ebaf49f88d39dadec4d4e7705f8
BLAKE2b-256 879a2325730c5509d2a109751b50d02d4845b95534d92fbf1e4e723039e24926

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.14-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 a5719c53a6351e0f1e0bca8abb1a3b1571965a12e6b4b15d9e6d72db3e278956
MD5 8fc0134b408789c39298a0ae805aa6f3
BLAKE2b-256 bfce4833d45375fff78581ab4785d91a36fb8cc2c6d7623f04256d18d00f54e8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.14-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 56d7ca9de35f20929733fd4b2e57752b5070a0662ea6d8214fec723f296ce5dd
MD5 9f7bddaa70079794a9237c616a58c759
BLAKE2b-256 b4d7e182403c73cf8dfe07a594866550198d0345d39f34cd46514da11bd33c11

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.14-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 cada5fbc34849fc5a1ed015db6a1aa30e30a9035e663d3e147986b44895aa5ec
MD5 eb6edea8356ebaed363721c409f63978
BLAKE2b-256 c6dd622a69643329b66cb29ec9b182ac232a43fcda6ec3552600069d22184dd5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.6.14-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 3.2 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.14-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 ddfe313a997ef0306c1adc3bc57fd5f463a262358c7b3c67568f989d831d5054
MD5 34a4d21c9177dfb4560c6781bf310ca5
BLAKE2b-256 6c266dc9029df8e99130e356d14637e0be3f713876ee0693a9ee2b0f271437d7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.14-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 754ea011d6a7aed6f95a921305a803037546b421a235590f3fd144f6343213e7
MD5 362751772dbc0f927cfb335b542a199d
BLAKE2b-256 e7904f73cc4a121c883119ec18803a4874281b48108ed95f6aee4847ef9f724c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.14-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2c35c3cc550c9065275485c669e83cfa26a7f164a0a8a919a2f25b907ea571b7
MD5 4bec4e5f2ec17ed58b621b1462d26ecb
BLAKE2b-256 52b9da8952551e57562c3ac5af69e1f84e844d7ffcb1e9d9c9ed157f086540c5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.14-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 61561a7654febfb6450195b15b4bd60e13d752b36c19fc082b83d56ff2d7762a
MD5 ee87e5e1390eb5d23017bd00147b0dcb
BLAKE2b-256 849154349e55184d2451c3eb3c4d96e78285bc5991ab483c02830669dd13405e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.6.14-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 3.2 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.14-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 930dec77fcd1c45e5901c48cefc2e22ea329be727714afdc0ccec85b8c7af215
MD5 116ef6710715c73b88c058093bef810b
BLAKE2b-256 d5cf990c2959872adf140c57c5055e80acd73ecd20036c9a0d34c89f930b83a2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.14-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 72d5fd7162bdf66cde44d1b48355538ea101836ebe848ee1ac1608f3feb5c49b
MD5 422e670223dc2f6436b9ca9907c3bb24
BLAKE2b-256 810822dce7be3dce62941e13c81f573dd04049d465051ba9bba0024288ba392d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.14-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0c7f5e134f360f35adb45b10cbda2bfd010e8e2b2eaaaf1fa3338d5b66f6a72a
MD5 24f1d62f1349e24df913b6fc3fb85a2a
BLAKE2b-256 776077ddb0c622956e32dc9e75442c082d3a950c60d4a45a1823c02ab07a162c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.14-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ccf37405fef4f08a317b739c261c5c5243eab41958262afb7d0c049c1db82d23
MD5 7efd72d97af0ee301c40d564fe6a1a7e
BLAKE2b-256 7bddaef5f5fb742d3f5ad99f31775f55bcd8269965aa7e1d0bdc5f442d97401d

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