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

Uploaded CPython 3.13Windows x86-64

kglite-0.7.15-cp313-cp313-manylinux_2_35_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.35+ x86-64

kglite-0.7.15-cp313-cp313-macosx_11_0_arm64.whl (3.3 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

kglite-0.7.15-cp313-cp313-macosx_10_12_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

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

Uploaded CPython 3.12Windows x86-64

kglite-0.7.15-cp312-cp312-manylinux_2_35_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.35+ x86-64

kglite-0.7.15-cp312-cp312-macosx_11_0_arm64.whl (3.3 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

kglite-0.7.15-cp312-cp312-macosx_10_12_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

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

Uploaded CPython 3.11Windows x86-64

kglite-0.7.15-cp311-cp311-manylinux_2_35_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.35+ x86-64

kglite-0.7.15-cp311-cp311-macosx_11_0_arm64.whl (3.3 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

kglite-0.7.15-cp311-cp311-macosx_10_12_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

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

Uploaded CPython 3.10Windows x86-64

kglite-0.7.15-cp310-cp310-manylinux_2_35_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.35+ x86-64

kglite-0.7.15-cp310-cp310-macosx_11_0_arm64.whl (3.3 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

kglite-0.7.15-cp310-cp310-macosx_10_12_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.10macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: kglite-0.7.15-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.15-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 3b626109d9037d16d02c611cf3879bc5ca70ea8cd0dfca98d834b2651fccef84
MD5 a1149341dc7a1343d4685bf4b7c31f83
BLAKE2b-256 e2573cc7962bffa1481b937929877eb3e3a04f593b60f20ea772f6f33c2615ca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.15-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 27078686ec1d21609d2232bd00635281f6622ca8437d06652f851b4074eaa702
MD5 f4cc5807257153cc0981f58a29e464a9
BLAKE2b-256 fd5bcb6037fa0d0be41ce0eb40e93b69522964c843d7381aa22c06487e8f10bb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.15-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 30b88562ed665156d06ebe9d2463fa702e4a83d947fb0e1bfa0c38fe370a1358
MD5 0ed0a7d5c9fea48e16eeb7cfb72ec659
BLAKE2b-256 b12276fc53828e0f39d13b344fff540728a967a24c9bcfa5f2c59d3e9495c696

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.15-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 db167044379f59ae0c3b467cde8f0439ac1603f112482b303a784de04804123a
MD5 d40b63d6e09d7b3ea7e392d788ce4108
BLAKE2b-256 28cd19466f1fed0780230c195ed5472d2273de22e3a00c0ff968f9881b6e28af

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.15-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.15-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 d709d689cacd3b77013d93772d4458994b77b4d1eaba8377d1f7e8b552c86539
MD5 542b04c97b48dd292264da9d65dcc1a8
BLAKE2b-256 b48f7cfb436e33d186206b10c74a083911767e5ec12f88eadd6bf15eca2b7c71

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.15-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 eddc6064a825f67305f0f952177c487268375d505c9ad98b4a0cdcbbb83da6d3
MD5 cb5dbbb11d2d4c620639bcc55e3dbfec
BLAKE2b-256 68d51fefc012ef748f16d27057e6c376552ee0686559b2f5f4684424299f7d81

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.15-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f388f3c1a5bb71ae0d10988f39e76720277b8210889d5eb5fb6a58ddeb70785e
MD5 ea6c3f4f421e853cdfb231315f64731b
BLAKE2b-256 a3cc7c3f22eea1f83b0f46cca8d74d92af6cd47cbd4bd976f4b0bc97209667c6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.15-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 cbf762a4862962db57ba369706c2aa3c85677ad1f66357a70e061ceff3ca3666
MD5 b9d33dc3b9a934941bb7167d84536f3b
BLAKE2b-256 1c6123b3448fb9277cacde0afc892d0a8fdd33983833686dae92024b0378846e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.15-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.15-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 43d70c16c7177beb9f9f84955da9725d00973f4cd42ea3cca35e012a24713a51
MD5 27357303e8a16edadb891d675985712b
BLAKE2b-256 227d9922d04d80a6b908a67202c7f940ee87a4d6e3dc81d1627ebf72c11ba09f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.15-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 60ce70e856ee9b74b8e8c208b0e1c6df30a19156d25c4a70371b883c3a9d2664
MD5 428fe99b8c81eee8ce45402cc956c4cb
BLAKE2b-256 71860a9dd793e41e456e47e55ecc6f298cc60c3a292c5626f1153bbf1db3e587

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.15-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5171f7194665d6371c327ab483f524b12e0a530a42da3141e3096126ec42ec73
MD5 76bf3d7d7d3e58f1a4ef6ea547c61858
BLAKE2b-256 303d2d56b3fb921f5b96410964f85019c82f40fc27625a8e1819e74038264596

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.15-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 59e7bd494ec859e21e952ffe966eb4c3c34b0e394ffbfc38a7e1dc9f2d64993b
MD5 1869dd7ad86c6c87903c4b20677fd9eb
BLAKE2b-256 8c2708e4560fdf834d06dfa7344382582bb4de6d55ee3d45d0837fb9b13fb973

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.15-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.15-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 7ecf5be15a326a84319db54a742a67765d968f625e6f7d6f24a7a8bb23872dcb
MD5 93d3d873d81631c73bd3912eed89045a
BLAKE2b-256 6bdb0f8363f6c21c8991a13600c50a7b4750688a748d28031411499fc6631dbd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.15-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 d8d13f97caf1b72350f93c19dacae4162355846be9e8c2d5fa045d2e27b96b92
MD5 f0bbbb4d898c55940b8263ef81d95c04
BLAKE2b-256 b8a1da6e2e3cb051e0a76f54ca1ced2c25b5744377ce07ee3db62bdc98159d5a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.15-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4ee976d5b7be53dabcc26bebec6d6021c690404475da36fcae7eae2316eb93c2
MD5 f1d7ce55709a3764fc39bd273d263d21
BLAKE2b-256 53ed12caf5fda5a7f96c005e0a56ffc2737372fac82762e269b61eb05c9e7780

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.15-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 eaee2ec40c9ac7acd195bdb86bd2b8a195d6698a12d0f17d6f3d8e07c13e2465
MD5 eb128958e03840a4fdaa275f33b4c34e
BLAKE2b-256 f62418fb19f57630a177ddc8d75ab49d87ae8c4f0248906128bb9d8714c9358f

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