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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 10.12+ x86-64

kglite-0.6.9-cp312-cp312-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.12macOS 10.12+ x86-64

kglite-0.6.9-cp311-cp311-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

kglite-0.6.9-cp311-cp311-macosx_10_12_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

kglite-0.6.9-cp310-cp310-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

kglite-0.6.9-cp310-cp310-macosx_10_12_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.10macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: kglite-0.6.9-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.9-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 e49ca61454934ed03f4b0392d79826a968a4c25b52c2be32c748787b77093d64
MD5 33ac1f83a061878c4d24c23a2dd83b79
BLAKE2b-256 2b35e6990e9659e90bc16058112ca3071e9630421162269620f9fe3daabd38cd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.9-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 f65706cf2503af64298de4d8dfb9b9eb287f4c3328b55f746824981f26192da9
MD5 0749f93e0037285506ffde984fb8d1e2
BLAKE2b-256 67c9c749ac433f94750700962ae817308eeaf9096b2c56b23b70947ba079f3d5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.9-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fe5cb48f31874e3715b5657ab8a80cdd3e675830980a6e4099b3fcf83b087e3b
MD5 e5f553a5c5eb78b1a1c75caebcefc14d
BLAKE2b-256 8167aad473c97ca1a94bcdd3bde28f181e11b71bca4c35189712d85a600588db

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.9-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 079a4e64e56e6ebce1ed7fcf29a62b88f075c9da8e30e9b4c265755c7727fbec
MD5 0f0db6785809011b3ef78e0ae072864f
BLAKE2b-256 972f5c0e256b87b36a4b1224376949459cbbedff2e30c9412b1de40b08138734

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.6.9-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 3.1 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.9-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 e5b9c7b05bdbc2d904228b6f09c465f2cc5b478de13bca0b4623ab345621ae83
MD5 01e741f46d9393c89616a63bfd442f9b
BLAKE2b-256 25033b8717ac2785667526671b3648b865af05b2efaabf6cd98a092c035f1e78

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.9-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 f67b0fb49063adcdeb49b26be81a0372f88089467ddb70ebd6e0d037a1e4bd7f
MD5 681f2e878d7ee873798af2d657218607
BLAKE2b-256 ca2bfc3ace6fcab141f3de81b2ef26ac6003c165e2fba94fc61aa0a742931224

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.9-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6374923ddf1e84a483dad9ec9b59489cdfc1165dc588279ffa9fe84fb75d6cbb
MD5 4d0cddcb256810235c6130d8e3c8fee1
BLAKE2b-256 758e10e34b40c4405aadedb6fdcd1bdaa7cfdc1ac599b859572e6160bf757590

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.9-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 363da01d8d53e84f4ba65f190db2b4f35af74e6fc4247120590769ce3720333e
MD5 4a933c1416df8c86929cac56a2fe85b2
BLAKE2b-256 aa7d810dd0c2d7559f2d3d91d3815bf25e0c61ac2fcf050caf2e19a51cd0fedc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.6.9-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 3.1 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.9-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 528b3429175890af40a4e6ef104ecac5d28fc8c4aebc71431cf9dc2d90717871
MD5 2d0cecb28da15e47f551c60d1948c730
BLAKE2b-256 03f6d8a695b39b93eb15359fa21835e98dbc7933639c7bd7a9af8479781e1f0e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.9-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 d0cff2586953d12c027cddd308c8a3e346600cdd112d2a785a8fd2ac897c73b1
MD5 75b2976e7a886f11eaaaff359f8d2b2f
BLAKE2b-256 b208c1dc1731d5d419a75b44a80304be02fa98b35f2cf03fdc049e4562a72920

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.9-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3b8c11c00fecc4d80582b3b7ccd7a4b6f8940564aa1d6240c2aa8caac9e6818a
MD5 63d8592d28f94c56ff3d02b5d2e2cbbc
BLAKE2b-256 aad138a2ef86805c43a37a5d7fee2ad4257f65d6166698087b7d5aa4d933c44b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.9-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 0c0f96dd5f1180ca4674870ca0bc05c252bb28ec23f161b6ae01318ead97ab81
MD5 632809ed514d1810031e2a8efe43a55b
BLAKE2b-256 e090d1739a40a33447edc8b88737c75e0a653b17bc2c69ea10eac36adede55fb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.6.9-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 3.1 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.9-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 d78f2c404aad2ef7b09f6beb560113adcb7e9ccedce695aef892cafd9a62686f
MD5 21718cb9be80533c55025401e6ce3f03
BLAKE2b-256 3459e93a0dbf160eaaa27c29a98b929cab1aed62a448380902c7fb92fa2b05a3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.9-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 6737238ea40066dcab468e0a71053eaf699d139e99996c701de56dd2657b2448
MD5 b4cd7ca919ac0dc152d81b9480ec9e11
BLAKE2b-256 f63496a1e6cc3f0acf1d4e8f206e8bf15b4e350029220f2f16416546a4e5400f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.9-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6dc1d68667f312a599bb81ecf226c006bd9b427564d392f97d1f735c327e2ee5
MD5 d9ace83196ad2c07a491f543b2b8f0cf
BLAKE2b-256 a8e56e97822f8e19fefefde1ecc01cfc0442ad621d7715685ffc6b4c6e720a69

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.9-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ae5b3d4aa3dadae79ec954dded6f5374e94ae94e6a168105e8355abac9ac52dc
MD5 5a02ac6b4a348148e80ecbfd9db285f6
BLAKE2b-256 ee441e60776bf620ddaba833116a31c57406a6aeef8266f8f1ca3a4b559bbd3a

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