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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

kglite-0.6.18-cp313-cp313-macosx_10_12_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.12macOS 10.12+ x86-64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 10.12+ x86-64

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

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

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

File metadata

  • Download URL: kglite-0.6.18-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.18-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 8d02e2cf7a52c0519e1ba417b05d277a83c96221ac9446d08f66d659126c06a7
MD5 1b89f9f479499ce312fbb736041668b4
BLAKE2b-256 b46fb58aff67a49c0e38ad4000eebc680f838a846f89ccf8afe7dd85c892a288

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.18-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 52af3817e74e613d27bd60f4f300a8f7ac2b87463f6f7a7699187639d4ab4899
MD5 07877926c42710454e5a9cb596bc4f2a
BLAKE2b-256 ff09f5d80b3cbd2fa43ba82548fabdc303b0aed4555d64fcdf09489da3b15b23

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.18-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1e3522476bc99b35635a24252538291bd9ce9cf2bc1c95dbc62dfafeed233da4
MD5 f7d088c8ceb762bd2be56f34268d1766
BLAKE2b-256 349cb9c5a592acdb2179463918ab9fa3c0d7725bdf2d80274a894d913cb73bc2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.18-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 0f0bbe448c2454bbdd888b5cc40b7396a8c56b5d222decdea89e89c483dc714d
MD5 681a08fb3097730b88572ef017c1fc69
BLAKE2b-256 3b43f38cd8a53f51c3a15883fae253505fbb9b108ee8d1b020c7c8475dece0c1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.6.18-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.18-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 5fd057764f792530520e812dfc907bb3c187315d77b9bba3a435351380639e73
MD5 25f2c40b2e731cc72d85415a93dced34
BLAKE2b-256 0cb6366a30ff6d6c1b5341b9d1a1aad46c9452a2d20e37d33ac4e82a8914a3be

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.18-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 857ecf00f80f475beec8c872058cfef78ee3576ef34d4cab1a8a7bf4f505b356
MD5 8715be267aba9809ea13f15de2c87579
BLAKE2b-256 9c129de1a12c30e60cfa007c49a86ce824eccda9cbd12532a9d27948f2eeba75

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.18-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1c4f45a94644ff3b2d86a21dfcbe9ae50cff822108db85dbab158e36c8d3041d
MD5 c6077e25a6dcb4fb7770a99196f0b512
BLAKE2b-256 50df916f993b41e8a0f801f648138d329ffcc13f0cdff1e16849cdec904672ef

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.18-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 53c3f1d67d0cf656f4d0efab57235d450536bd39bf984e5acafcf2622d4f85db
MD5 ad4c54030bd117fd2a34a26ab7b26fcc
BLAKE2b-256 852c04a0ed04691597e3d431d1c7053aab80ffb7b7f1de4ad7000c236c51936a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.6.18-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.18-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 34d4151cc5c2fa95a38b6eabce019b96121f3320be615704082c8a26d1d1a441
MD5 55262483be44bc22b344c8f9e934bdc2
BLAKE2b-256 e6935ea90768304a24a98770541bfa554c4e626ae57ad8d7e72f62fe7c76c755

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.18-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 17343667fc361e16491c8a15ac5008a9e5badd0bb6d272eb78b869115bdb68e8
MD5 a84881211bcb5d74f482aa36880d20b5
BLAKE2b-256 86479da1e4a7bed609318c05beec57cabc742b5ed2c4ec861a70bf50b06b6793

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.18-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 70897967bb2741d2f67acd0a56f25b2ea498737507a96943feb66f110907b4e1
MD5 03fadc7268cf096956b1ebebe92f80f8
BLAKE2b-256 4b37c618e07c936a4e5954416d2157600b6faeb2cf4cd199e0c33856c1cf0623

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.18-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 9bcbb00198af1ba219cab786713a85d20bd037cc089d3ff1844dcba73cba392c
MD5 ad3713e8b537eb2c068244d644623406
BLAKE2b-256 ef2ce1b8010b937f56342cf94ae463992997b8b1d05a554bb6e3824803bcf018

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.6.18-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.18-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 b70d1e0860e7d1c02cfe40ffd058c4fa310311ed66466dafb070ba482ba2a1d3
MD5 7c9cc1ab1b3183c196d300f56797e7ca
BLAKE2b-256 57774b560fe0d33f18d4fcdd628543d9e2064cf8d7878c7b633ac8f610ec143f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.18-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 d085abcc5335f405c999c39a9aa76422deee0cbaf1cc1265234c029cdb9e09bf
MD5 caf9cceb065b3bd4f99e528fe74424c5
BLAKE2b-256 9c7f71dc72235f99507dc89ce1c5850fc3bbef774cfd8eb0f64fb94f322379a3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.18-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5fa299277344bc302734455b05998d08be8cc3300fdb310973ac824b5c2dee95
MD5 e72858af9292355938f697f205cb4274
BLAKE2b-256 0e2423bfd7bf241b5c0b6d0470df92bdfed331a1db676e65b5b1cbf08b871603

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.18-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5838269845f45037c4ed426ff5e3d2e837faf37dff40a24ae0797f73e8f8b435
MD5 1009b94a4e71949c2b891e41e032239d
BLAKE2b-256 42535884780f3c3ed88b33d33b111a928c4e0d9a00cd6f2fea6d4ff75660fcde

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