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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 10.12+ x86-64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

kglite-0.6.16-cp312-cp312-macosx_10_12_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 10.12+ x86-64

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

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

kglite-0.6.16-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.16-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: kglite-0.6.16-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.16-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 1f7046e8f6c27447f2485e3b4a930935f3b2b83021c00036db1bd0fc9db8ad17
MD5 2899eb0a51018be195987507ff1f9df8
BLAKE2b-256 6881f46c0d0e939c70e58e967e144ed8b93b92b88513db9df43f6114b30cf9fc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.16-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 a757fc15aedcd01b8e9f4722bd2c636bf126d9d9e3d146f5bc4b44b6dd416059
MD5 6b773c01a18f02d6e5b3e106545d5b2a
BLAKE2b-256 5d86e81b7d3b01592c77f8be3c9af45bb575944097aab5203215f09de0356c65

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.16-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9dfb448eb44f7a09b7811cdb55d6ce861397ec6c79bfe4be0312e7a77a3185db
MD5 e89834f0c96afb279a6f3a3bae8306f4
BLAKE2b-256 1d27c245c07e074573ec25ccdc9888839309991a113c2a1982385d16141ccbc7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.16-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 88465c20c79c980e15f33a7dde727baa86783e906f713b685b77e89d13d5acb0
MD5 5f4074aad6c1f25df861d16b571ede0d
BLAKE2b-256 a791460f875c88e9468d1f5e308e9f794fb8b20c11091653b2a23bf261b264ca

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.6.16-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.16-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 02d49516747c2f38f482a9f3308e3f4764e90d4aebc190130c14e9c82bb6a083
MD5 dcd9654489e61613de775c14cc088704
BLAKE2b-256 f05ad04b6eb6b4fed5f561a1521370d5359a63667cb5dc4303d8c10c0b3c2d5d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.16-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 21860c3e3c8f9a23a6f080bff1ae3ebc7ace79d4c5c668a0edf00b899484691a
MD5 0e0645c08a4492113219434388cd0f88
BLAKE2b-256 e1b82f2e50ce36ed126e2ea1bd42da07ef2566290dfb47f98eb3bd4cae43d52b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.16-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c086822635490cd53be461ac672e9e9204d28eeaac786766b0bf3d8a9a1bb24d
MD5 f19dd53337cae8f9c32f728b259f5673
BLAKE2b-256 b1943417db1f2e39b77a0cbbebb52c876bf0ddc1f5040b00be67e857727ad501

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.16-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 fa1cbf9e173b8d84b4c16486a3e1a23be109d9a4231516ca4d137d802750fa87
MD5 7bda2f128490e30b1e2da10250b21bf0
BLAKE2b-256 691c6ca0ba85b9d040347c57680b7dc9e8b4e2fe3f49fbcaa24846fa58ff0ed0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.6.16-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.16-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 fda381d4e2545e998cf62128a51a90a6e98fd079b980bb927822e105460847cf
MD5 668c81b389cdb1eed7960a7e59a8706e
BLAKE2b-256 43cd7feb10d757fa5aa80ee20ee1d9cda684f53c9de97b033ac339eccd871d23

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.16-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 89f2da9d713c6c9c6a821e5f24cc8749dab7f494d85bf4595b8c1f243b961c09
MD5 410aaaf7a8a5ba6d56cc564b75d24ebc
BLAKE2b-256 ba4d5fd6f26a1c5f8d17e6d6ad3a6575a3732a6d5b221c127a8078caaca6ddcd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.16-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1c794ee5b6235235b18ab57f6b2a5e760071b3af19a4b6ab835cad2db8341189
MD5 e978f24746887704d1bbd67b1d90ede8
BLAKE2b-256 5995aff8ac30f3254a827f52ad268fadc2ed8ef5d4e416a3c078c275268eba47

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.16-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 2e5d9e9aed1d42e53a87938aaf32b6f40a2e740a023efff20b769c7f58153ed7
MD5 966c345ea67519f91c01e3aea5df7a5c
BLAKE2b-256 af6696cfa0d38497fe4b816e263681db172c1c9a560edd27b0b0ba505c34c5b5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.6.16-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.16-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 839bdf555d67e896c877964eeb3af76a4b6177a2a48cfa2c0f211ae29a6620cd
MD5 2e506b84b0e567660aec5cb58abfaa9c
BLAKE2b-256 a43212afba1e2c2b34443ab3f0264b90e68fe56c2ef2b20479cd9b580c0a7dee

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.16-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 a91031558424e2a872b0be892d33c86a045ff47ec0ca34f9798e6a427ab024b8
MD5 34606310d9931f4d11fdc647942c8c20
BLAKE2b-256 47105d520c94a36c92ad42c7d838b31c0e37fc181e4e34ec07a2a679ce8d73e7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.16-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 deb8ce9dc55012a459203b9a822e690e989930510a54042ab5328d6e6bd1ab55
MD5 17bbd91377ae85326341704b2378e9bf
BLAKE2b-256 031825a4f97d00920c44f04c203e6a9ba639d232674b9ac8907d0f6effb6f0dd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.16-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 2c6d2b356af81a4a7f365d51d3820a2b0638100d78ce82bdef28075c5ea22796
MD5 e415256dd31b3f3ce1df365d18215de1
BLAKE2b-256 cf110f6109fff450c0e6a153e242b743e56c1ee5adbd6e1fd882cb16b52c2ad2

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