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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 10.12+ x86-64

kglite-0.7.11-cp312-cp312-win_amd64.whl (3.7 MB view details)

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.12macOS 10.12+ x86-64

kglite-0.7.11-cp311-cp311-win_amd64.whl (3.7 MB view details)

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 10.12+ x86-64

kglite-0.7.11-cp310-cp310-win_amd64.whl (3.7 MB view details)

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

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

File metadata

  • Download URL: kglite-0.7.11-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 3.7 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.11-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 4fe3abeff7d678acb6be61b7e344dbb3479f844d936ec330c2db1451cc7892ff
MD5 37ec244c17735ed0439d14075fe80674
BLAKE2b-256 a25cf39d320c359aafb28ef3c11d0ce4ea2bcdea4359ce841363c8248ee8305a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.11-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 163cc7cfe9d3776df15fed678b3a5d7ac5ce8a151b4bb8caa0e783c0d0b179e5
MD5 68c7ad98299a1c7a1032ef2f754eb79b
BLAKE2b-256 722bfff06970eb815191280cacbb982ce17c339e1a2dac19982502969a9cf3ca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.11-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9486906cc84db7aadba4ee8f738db144a942aed8ab5241eba623b9b65d311c5e
MD5 86e68fb566e943deac2e4074e3613d8e
BLAKE2b-256 4f14e4d37e165a94b8a0ff1c314b27f79ee85b511189ecfe27edf30d6f0f22e1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.11-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 7b30c3a11a3099cbd569d8c8aee1d3b43b81ce0bdedb1414cd871154e96d6c5b
MD5 deb57084281605c916843e5e49489f4e
BLAKE2b-256 5cc210dd6b6f79cc714d851dd8f5b42e82b602dac5381568f1fd266c46b5ee77

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.11-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 3.7 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.11-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 a8b8b2e4351df538b9008da0b09a999fc0a46adae14b77b6aaad555a5d991e04
MD5 2aefada39eab7158ba91affb4a2ff0fc
BLAKE2b-256 0615eaefff4fcf29deb9303deb2ce95ad82605831dfb1621d1fe9a4a9f732cfc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.11-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 5c18d515f45b263c79a5d21956f1accc5ff3a5675ed27124080c078e84cd8f4f
MD5 90099036e51062e72ddc06df89217cb5
BLAKE2b-256 7e9360e12a102e30ad7ef512f8d8c19546e0e95f88856c9d8810991c14de5af7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.11-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8b29ec7303b4f8f47d0c0acf5bb003eda41cf79390d5c44b44b0e916f22a8445
MD5 1179b416d74aa1b35a0de259644f21b7
BLAKE2b-256 0c60301dc26a6dc50da149f906d1a0cebebafaa1ba3872776bdc4b3aae9b25d5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.11-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ee545ab4ee29a39d73e34ba0a61fd7c81776ab764fc70ade0018a3692ee28dbc
MD5 29056be7860835ea1b6e7b5040ff938f
BLAKE2b-256 2a9c53fce172705e6143a506f09aff0c99e78f0a4deb512e6936a930d7edbf71

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.11-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 3.7 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.11-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 88c6f46078bda07ad744a76e995356217d2ad3539169c95a2d17340059496532
MD5 bf46626a9a41e2518635d03aa12ac8d5
BLAKE2b-256 9e40b7759adf71cc8f2259c905e87d9670b29e996c9c24a566bd0712eb3ae79e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.11-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 c8ea668d282fc276ecb025add12643d974ae5712470b1596f245dfbe63057f6f
MD5 bb8d09a12cd14640f0af6e9748aab8fd
BLAKE2b-256 ad0c2db5fedd3e96e0423c8180441ebc433a7dda60a6f46c5d43fc09ba2dfef3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.11-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 44ab4c8e5319f120f103fa1eadd1d21f188278da86b3e53bf849db486218b870
MD5 c05cd28504d00163ff53f7073eee3fd4
BLAKE2b-256 cf9df1edf9e5d5531fded7cdefec13fbf7c38f85c24f4bbdb3363d977484ac66

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.11-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 bb4c482754ccbfc54eecaee30d77d030c9d7547c50a5101b70e67365bd65918c
MD5 42e096f3ae1e5fcec8dfd009e3103d52
BLAKE2b-256 0fb44f5b306efda8f7c172aa9dfe03e6f80df96e51f4f4b9ba9215ae0e09c33b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.11-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 3.7 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.11-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 41987bcdcfb836a657954386e1d941551860bf52c23d700dfb41cb4d27cd03b6
MD5 62710255b575f6c4038d218d2d3287f4
BLAKE2b-256 a41f455bf068b3f1ac60e4f6c07b4cee0148d2b7b3d7a5f68fc783faa3a70e05

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.11-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 0ef45c285d1cbcbd50207f6115ef4625b896d1f3e1386480b019d0f9bf6e1a49
MD5 fc92dc09231faceeecd2a20976678dba
BLAKE2b-256 07711ab46b63a6e3ba4b7f61017da072759af701fbe1e56d31d13d66631d1b5a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.11-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 66a0d34e50f3573ca48e377071c77055ca1bd23b0c31c4d2cccbae7dd4db3658
MD5 f2f87b7899d318e33bf5ded774e35e0e
BLAKE2b-256 f18591e92a4394d1a2e8916cf1843e94c3b6eaa2bf57d0054a48aae60d6a8800

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.11-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 0bb8107f1da28490f19db3de049e3b0ad137c3473b8fdebb962f363b3748e165
MD5 66672ca6640e6d48e0bcd812fc916699
BLAKE2b-256 6b38f7aec32a13b07db7e123f257d4910d9b06e9499a6de34dbbd241264ae8c5

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