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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 10.12+ x86-64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.12macOS 10.12+ x86-64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 10.12+ x86-64

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

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

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

File metadata

  • Download URL: kglite-0.7.8-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.8-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 9290621296b006936ea8dab3e2aabc4bce4d27301a5225fb1ec25e36f1cf45b7
MD5 5ff6cf659ecd965bede97891c228d18c
BLAKE2b-256 df21ef088c8c0fdbedd10627b7693ffc15472d59887136ff75a5a0de5488c1e9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.8-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 58899ec962f03366100271c64e31e546731a054adae939aeda08dfda90de49ce
MD5 5d159b8ff93dedaf45a4a72e787a7b41
BLAKE2b-256 4d24f0f162905207ad63abf85860410f8689dd7e9ac41303498d54875ae4a205

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.8-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f3508a71328e4d824cbb2d538bd3c0add3183d2a489d0ef18ae7bd7d1ae464fa
MD5 d1af09ea84e324159040d5ac340fcb87
BLAKE2b-256 3f06bf6bfe80b68ab1abbb7d3e210097c142e59f665df0fa77d040aa2a8884e7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.8-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 8bc3564d16964293b14f0f261cb0dfdeb129e6c6d0c78a16837501b89cb130ed
MD5 129dbcc448baea1d9d185efb98364e63
BLAKE2b-256 d425dd1a82a30a7e00912573bc415bbb4897c6d112f670bdadbbb906856feca3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.8-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.8-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 4e3cbb8a5262451210fc91f366a5e1073bd0d6ee7f48825cfb13dc8fcd299038
MD5 74bb69aee6daf231b3afb2e8da33f9cf
BLAKE2b-256 fd34edcc005449ecbdba736e312c4e751bee9a2a9fc6182f0e1ef50f27a1fb5b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.8-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 2b37391d19fb24696e65e18c72c554a75df92255ac6f637af6b28449c378c1c0
MD5 40d6e7c3a21f5f6c0766c2fa81eae845
BLAKE2b-256 1324ac9574883c6bf055aa2775d4c320c5006cc29a2ccf4800a1d2369e754cad

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.8-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 567fd19c2d608872139f0d911b7210f085a18e835375c9d639631a8fa3027308
MD5 78ea249736fd760a8b25ead1ed1f6a61
BLAKE2b-256 6d52f789c860b58f539f2822add7c85caa5c8538baf7ae30d9e950aa9aeb46db

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.8-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 beb41ff8781440c041734992438e777e267183cc8225ed18ee7d871303a041f1
MD5 14280e701c57124a3de88f9c72893afe
BLAKE2b-256 ffd7745a8e749f83a6dbb08fbdb57376d6d198788a9e9ffc16633d7afd712fb3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.8-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.8-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 8fb7e66f848b87af1478167cb651a0f168cc1e84c806d755dad4ce6e0188e2d3
MD5 841be2bf2fedf99855b75a40016dcaea
BLAKE2b-256 43ab70c098311d87b14ffedbc0c1bb61ce2c2353ae20784e2aa1501ff49e7e57

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.8-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 84582f962f1c2f6a0185f419ec90331899b1ab3187f0b98baa0cd9991a1d2e76
MD5 3413fc8bc839a7237119a18e2ff382b6
BLAKE2b-256 5c8cf2a0abe3ad174b7319a1278042a813a7bbbf5302baaa060125cc82e94694

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.8-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e1369fd24e4fe5185c79373cc385430b09f07c216e8c8a57e382849833c79cf4
MD5 3d671eb043f8c4b129419ffc69127243
BLAKE2b-256 f51e8032a8cf15daf4c9ca11a49fba6c3cea0fec141f2c240a663d4441a3898a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.8-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 32ef4ad00de7a44a0d8682cef7b9a709b93301fe15e18f58c7e35b359eb2eb23
MD5 86fd70d0cb20f6af758852cce6a376b9
BLAKE2b-256 9ca3752fbc9a9fce99816e1c4d6252acfc711118aa5d87cbcba89cf4e7e9ed0b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.8-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.8-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 ef1feae28846edc9fb99aa61e9abfdd4a5c6799c33d1a65fe546142e311ee4c8
MD5 89085578cd8216e95b526a157fb4b5f4
BLAKE2b-256 dbaa916137e35e47c170f39b9e5e93bc7c696c6137d145068267263f4582d342

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.8-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 c7067bc7ce98e319e5ada90585f8a2a9c7a9da619aedfdc3436a587fae0e6f77
MD5 9d5b9d7d3ce7742726ffff52060edf7d
BLAKE2b-256 5770538a989b38f64aefd5662920f1bb7f23e19ce141a5eda707000dedf43756

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.8-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 eea7cf2c20201075e59e3062f1e7c34e8e5f5e252994ecbeb5e17cfa2a0b19a2
MD5 a35bcae1896617f8eb176ae758a43901
BLAKE2b-256 c7611b482eab4a9e61b1340a370737c601327f526469969a21ae88d6c2e8a3e3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.8-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 71c6e2ae5708058e9f512e679c732bc554a6e951f944caf2bc3bc1cb7d2779f1
MD5 614d319a18d482660177fdff86d3328f
BLAKE2b-256 4f4cf6e6422311d728a25b7845eeb49842ae3289e3d7a009da1ef3a7eecf8faf

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