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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 10.12+ x86-64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

kglite-0.7.7-cp312-cp312-macosx_10_12_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 10.12+ x86-64

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

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

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

File metadata

  • Download URL: kglite-0.7.7-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.7-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 7d42f7d44983bbe558f5345a2ffd34f74f58f8a6c131ddf58115a5a3155c779d
MD5 8dd3cbfabb5e0df707a808dc0038aa9c
BLAKE2b-256 adf853bdf4b51498120e5e29144b5f90ac1dddbf43a117a8dbaa90815f73c242

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.7-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 88c6ecbe7291cb12f3d1b5027501552be46a0805b3842e3923460785d21a9508
MD5 b404876a22cfdc70ced38e2a66071ac4
BLAKE2b-256 6f00dbecddafe445f066e45170b47266fdf6d742fcb28100a6359c91c143f718

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.7-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2c794dacc43782fa3298bc5ed18112c66755965fe8e6ab5f7df75321ae442eb1
MD5 20c74f309bd0455edd7882881ffd2121
BLAKE2b-256 e9a4e5e5e5339eb7e1035a5dbc56565ba1c81421bf7af3ae978bdbd0c2121fd2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.7-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 8a3c1c9561e9d565c3e271bef326866492632234f97baaf90b0031d9a9055014
MD5 fd862a0c5a894a8797fe33ccadbc4673
BLAKE2b-256 ceb044bb7566bc0a7369a9fca0d95b8f606fb32a383cfdc7ec4a89f778dc215f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.7-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.7-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 e51eb681f55cef24fcf6f3f1857be4ed2afa018d71ea5e128addd9f874675893
MD5 918c444fae737c28f80149ce04710518
BLAKE2b-256 bcbd100b9c012c29553a322a8a8634f611c524b256de42ef16724f2a28d7f8d3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.7-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 6a19c368bd25e451f73faaba5857a10cae90bf896bb62de0099d784fa9000e63
MD5 ce41bb703bd53129fc1b3847c5034a42
BLAKE2b-256 9201f1eb9fb3ac7b9c2d31b42c7680c65e5ada5503be0d1645c15dcee8b811c7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.7-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2d7152c2f74424989f270564c412790a257983c2a53bc9672ead27f6d23be841
MD5 f7978b5858ae780460cf304042abc4c9
BLAKE2b-256 63d1f934f7e606a7e6c4f6f4145cc28039af5b509dffa5ca49f61cd8165c1983

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.7-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 a842c3af50ab3ffc61da4782a61af4aa1e26f8a87196a1a7953e8966c529870b
MD5 cb17769f0cc6d0a8116c0779956098f6
BLAKE2b-256 fdf9b322ef7c2ded8d1115b9e63d4110a86d0d97ac608c0e800afff9c4cf8b91

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.7-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.7-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 94efc627010d3a7e429379b5a50f2e31dde1b7291dbc923130798ae058e71869
MD5 7af773c17f0136da0784495003cb4d22
BLAKE2b-256 a0ac741f45265160548c0d2e988589fac29f069f9235cd86a35799610ba3a35d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.7-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 3a3b1696a14d0df5bb97a052bd92047408e4eaa61c5aceac81bf664061907dc8
MD5 31d0b50a7d92b1db7b6823aba8b97f1f
BLAKE2b-256 1432c270d6be00f73d181e960edbb50aceea0c38a454259b09046679404bdc6d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.7-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b2ee9808c6cf3f410d98af10b037049da83e5c902ac697e186027b3f30563f4b
MD5 dd907ed31a334c04abcda09aea371b02
BLAKE2b-256 6318dd4bef04966032c83a20a50dd7d4205d1660fa5f786ef634cf85b07b6948

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.7-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 642d55875fafa6d9a6f7420e69b08d3274c190fea8a6d695c54c09f53d60de54
MD5 a1321fb6681260db9d2c95a9fc01b6fb
BLAKE2b-256 9f1431bcf81f9b125cb22cd2c1da766748e94c7c3caa5983428c381699f471af

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.7-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.7-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 37fe3de8747e806e5c87c2c24e5dd34c97343d557be63dd0b9d19f7ab94f6cc3
MD5 bb6c3b67fff0b5b09824ddd077dddc9a
BLAKE2b-256 a7f7578ad650a1edf803cc8da7b596853a740093e425774be1c4c7cf05c41a3c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.7-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 1103cd6a7168a83b1025fb278420c357ef03e892eeaf0c0b27bb992f4ee3dda7
MD5 d2144852f78890377f9e0cc8869236c5
BLAKE2b-256 e50b03bd398754a2441705ebaf518a34c7b2b0a8edd13f382839eec551d9043f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.7-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 37d2ff861b265aa3c0b81a0dfa4431b17105a7e32877474c28785d89424da2bc
MD5 fb1dedf391ff246f71c9096d850e14c3
BLAKE2b-256 5f11f94a55fe1d9a48e8fa62cd9d685d2136047069e783967dbf31c47e1e3159

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.7-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 c23a25bc2d5d2122fc1b9009d18663a0df187c1cba704a107395bc3c8be4f237
MD5 a1611d72b09859d268ea1463fb8f6aec
BLAKE2b-256 ce1e6ba8bec1e71a8dd0e33a264e7b1bbbb0c7d6140621f93be2f4542e36dbb1

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