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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 10.12+ x86-64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.12macOS 10.12+ x86-64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 10.12+ x86-64

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

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

kglite-0.6.15-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.15-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: kglite-0.6.15-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.15-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 dbcc5f4e300edce37b8429d02290cdefa9a5f51c294cb08b7b74651e7a0c1029
MD5 c61d3e02b16513e7b0bd4ebfc6f0556d
BLAKE2b-256 f6225d497c25a4b27bffd0d626e09942c911a68e137ca661e1b6f693e61d80b6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.15-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 3ca4107ceaa35a2139f4269ff3c259dd6b6839f239d10bf00b5e17cc0d602f73
MD5 82330a4f6c7a1cdd6d6f85f7f7d98a98
BLAKE2b-256 8e146ea5f9fb7e76128a34f7884882ee26d63c3a15123e6a3b4c91a6f194faaa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.15-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e63c036610be990e0019cc527ea160db263074222ca9c0533acb7ba9d9e0c48b
MD5 34895e8c421520ea4ea5aa6364d4fabf
BLAKE2b-256 1a599cb5766fe9b69c3dfc224e7c3612e866c9c74c9ef6de43d27542a7d2e06f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.15-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 edaa5acc499cad244454ac325ee0dda016a2fca1fc7766cdd1d28071c9f3f710
MD5 93b6db9765ccf87b2d014f34bb63f172
BLAKE2b-256 58e1a5d162b0e9303f55680596e1841be3b55822e0d759992659531b719ffbd2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.6.15-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.15-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 fb74c302473daa206513b69313ecdaba2819bfeb8130ad36b545c63d6ce46bc6
MD5 74e3d791bae11eb13867f9190d9f0469
BLAKE2b-256 af04c19fafb7c959cc5c438358789cf1d49703f25dddefcfae49c7d06b2a0f3e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.15-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 adf94d6fd931d5f7c99239f2624b353fc8a91abb3c7855d32595635f870ed812
MD5 958c9162dbf0f4d3af59667a07c57559
BLAKE2b-256 9a1ba5524bfcd9c4cc183bc3af6d4e50020490bcbb579a160137eee1a59d034c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.15-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 dd8f431d405eb0e07fddc2e25d70a95009ddfd1ff5feb0a6fdd9b01824d70f67
MD5 f9853d0618708aaa43f7e6948543dbaf
BLAKE2b-256 4376cd4d90a6d9ade4f2c632b1527a779a4489b642abb47e4c681102ffd07d2a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.15-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 99348cf3f6e21e2521e8e129fd07bb81d4cfb02264aad3a71b9aafb5efe4dc95
MD5 f6cae4e15a01d2e2d90ca4a63dd6e42a
BLAKE2b-256 37c93cd405ca561da37d8b4ff4761ef9a62043586c9ca84ac5003571b7d04060

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.6.15-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.15-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 09a39fb400d54a885174325dbd4a8c9f3b4b992a384bde8aa70d8e4862ca8bef
MD5 f7e9c85e10f3d2e43dc2b199f3bd2cd8
BLAKE2b-256 cd53b45d48251421b7692e4f4b51f97f31a96876e4a43d55dffc2594ac615dac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.15-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 04befb362e26c96c330372f83f77b90051b53399d7458616da2b9ea15ae28030
MD5 69e6f714305145844c3e58c65a1efef8
BLAKE2b-256 61613892de11f794e96997b26c4ce8d0f9a2a347968fb5711a02e31769ba57d9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.15-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c967c4fc53e4bfc65ec43e2e37bc082a2e24f1281ffecb66824bb0afd0b43e78
MD5 4410001a29070c0d3b0cd3ac854768fe
BLAKE2b-256 3971a2fea4453d437fad89fa359ee6d0d39c446bb95ac4ec7c899bdcc442c600

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.15-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5e5ab5580b3f17bb7004ad0685851c2bb05fb587c98ce6ad888afcb1bdc4f617
MD5 afce7348cb91c70d377070636845c381
BLAKE2b-256 1d6961075573f5efba5c8b8dc40387a018782ec249ba343a6f9e2e820c41bf21

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.6.15-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.15-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 11136a9a913abd65059ca20e44af51f6eca4a1204b44d57b1b8478ecee21ec7d
MD5 36af20f7ee14bb56ea47ed5903ebd7ee
BLAKE2b-256 ef6ae3ac15f2aac067ff0b84ac7865d0dcd6a57d28148aa84fad1a42e1da801f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.15-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 9281b8082b80c20f143211776b8d27044ee099e178ae50c1fd3db72df5b3dcfd
MD5 145b4952f68ceaf437599f6f72a6490d
BLAKE2b-256 cc75b91b26f5b54a4c982a82b362bab28381586b73433659c60d47e7d3067643

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.15-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 037103fe99a5fad166c4bfeb4034d3aebba5742c91cf2de4bdba791a782c9448
MD5 19e01390a6180668dac7f22d87ff71ef
BLAKE2b-256 7968f887b89d6874753c4e910f5626932645037c73e22b9d7687b3cf285c123b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.6.15-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 1e93b2eea0d4c431a7f1d1466aa5bf39e4a70aafb5bacc5f4d013517bb5aa904
MD5 8c7eb4a85b72886758de8ea8a70dfd4e
BLAKE2b-256 2a450dc02952707ba02dc9d4b753248e12ad0f2f27374776cf9477a33cf10dcd

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