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

This version

0.7.3

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

Uploaded CPython 3.13Windows x86-64

kglite-0.7.3-cp313-cp313-manylinux_2_35_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.35+ x86-64

kglite-0.7.3-cp313-cp313-macosx_11_0_arm64.whl (3.1 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

kglite-0.7.3-cp313-cp313-macosx_10_12_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

kglite-0.7.3-cp312-cp312-win_amd64.whl (3.5 MB view details)

Uploaded CPython 3.12Windows x86-64

kglite-0.7.3-cp312-cp312-manylinux_2_35_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.35+ x86-64

kglite-0.7.3-cp312-cp312-macosx_11_0_arm64.whl (3.1 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

kglite-0.7.3-cp312-cp312-macosx_10_12_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

kglite-0.7.3-cp311-cp311-win_amd64.whl (3.5 MB view details)

Uploaded CPython 3.11Windows x86-64

kglite-0.7.3-cp311-cp311-manylinux_2_35_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.35+ x86-64

kglite-0.7.3-cp311-cp311-macosx_11_0_arm64.whl (3.1 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

kglite-0.7.3-cp311-cp311-macosx_10_12_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

kglite-0.7.3-cp310-cp310-win_amd64.whl (3.5 MB view details)

Uploaded CPython 3.10Windows x86-64

kglite-0.7.3-cp310-cp310-manylinux_2_35_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.35+ x86-64

kglite-0.7.3-cp310-cp310-macosx_11_0_arm64.whl (3.1 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

kglite-0.7.3-cp310-cp310-macosx_10_12_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.10macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: kglite-0.7.3-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 3.5 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.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 8c7723b4671a2d316559359109c1c9835f8768728f3e0d31e3f050655b63562d
MD5 7c6172f0f1fe4866b7b8a55cfe06905e
BLAKE2b-256 236dbdba9f127bfd06f4687e62b5413c153d0831513b02ad0aa42505c7291c17

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.3-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 3b90b0d65534b5fcdd0295d20392df91f1c984e70dfde1a1fcb82732c3f17c00
MD5 2c8f707118f601daf082079ab271397f
BLAKE2b-256 de05f39b34eac98314a523102125330293d212befc344e548c7f6b56f4c17694

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d1d3d181493d9aa9ad15880c6b98b51f0c1bbd8bc9ce53db94658c490cacbd8b
MD5 885aaf87beb5f0324f20ae7f2a6a86d2
BLAKE2b-256 c9e25ad862e07c67d94a92933f7eeee0ed08a93d6325da18aa6e494cbe57e9b4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.3-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 810ac6cfb0b4b40c356ec69ef6d9db3c33e6db7efe75c238710c36b8888d9b73
MD5 ff495354b2b7a39fff31a9400599d927
BLAKE2b-256 3ac92df842ee85c65e49cd81ea771af11fcfb3dee8aa4110ad22bbfda5a218e4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.3-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 3.5 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.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 614fb2ad7eacc88feea79ae675edc7c26943c8c7393c32a06929403f4b18a7bc
MD5 0d3ae74cab58de1823f3fa50cb0ff4ce
BLAKE2b-256 db58b397bdc8ca45a80cc7fc7fb6efcfbb8a5f60f64bc65ced21f186d08a8d0f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.3-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 ec4311ae75e170ffdfedbf96f153caae52c83f4323994adaa52f38204b3bdacd
MD5 a79b0b88b04562db2148e0c83fd0ae15
BLAKE2b-256 0bbaeafb3c631173e805767fb03c9378ae0e0aaa4f899abf11590b18bb80165e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8f8c334e6daebe35d7baefa72cc95963b50dc125c7538cf061eb3a8ed8bae5eb
MD5 0b721f56b5a7fd435f712f8f267b99b8
BLAKE2b-256 8e840baea52e94152632a1b917fb75cf074f49fa99ec959f2ae2ac63579aacff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.3-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 644ed8a620cec0d0c1e59718c4a7d04f10850650532532ec90e68961ed99a50c
MD5 de1d0187ff4a74b9e2c4b149266def60
BLAKE2b-256 d4d872e0ee03acbb8d00730bdb08a0d6b7aec7dfc567eca08256a05c4612853a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.3-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 3.5 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.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 1f4795528cac7a6910fe5c975fcbcd67c47d9a8fdfc69d84fac0d85bf9c14492
MD5 5a71229065b982a2c83e2304c86efb62
BLAKE2b-256 88bf1bd4b9564763b9598fb0d87bde8e5dae488bd152fbe059b9960a6ec9b2ee

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.3-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 a567cbc81265a1f7378c0ca80e5deba1cedbcef60a203e42d209e24b962a15cf
MD5 b27b587a24f1a568a5c47da7ae09add4
BLAKE2b-256 5943a69a091ef7255ba5d49a1a80c5811ad9ef24850cbcc3bab90ed476da84ee

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fae286ccdea53430cf20dd28713171605a6befb0f3da8bf20d9be97734db9c28
MD5 13dde10e4b8ebb1cbdcabf1bf58d63f8
BLAKE2b-256 4891040bc59afcda714e8f040d9f5eac6e461d37b17433e924af07ed1d5060d7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.3-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 99b255995c26aaa63f2a5569ae9990c5e9ae5a3045ca83e4ae3d64163bcfa13c
MD5 60d5f923fd1fadac45e32fea98da3aa3
BLAKE2b-256 0ef4370014c1acf9b0f2f7ffa812829f071df3e6a12137583f6e15790379705b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kglite-0.7.3-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 3.5 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.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 a9d4ffafc39b1b6c103ca6738a3e6716283618ec77c34358e7e4953ec577df8d
MD5 fc2ef2ae3109af239548bfd033dc2ac3
BLAKE2b-256 d7545f42ec8d7413a8f7bcc3f68e80567245a9a4163eaf16aa3d1448f1c4278a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.3-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 86740e9efbd59562a9446b4d001b43c87db6d64e8192e47ffb354364bc554974
MD5 16523fe83040926401552098850877dc
BLAKE2b-256 1a76575fb3610aeb8037851a80c83caaf229a29927a9aeaa2959b97fabad2de4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.3-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 208cb624222f8400ef31f0ae1fb8a42c3d403a0a645214b0871208be107fba51
MD5 c48d7c7484b74c3a6bf66b56dc927237
BLAKE2b-256 a2b068c0620310b1304f6a25f55e3424554925c44730cba452a0efc9184d9f4e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kglite-0.7.3-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ad2c67c566704c1fde0416154de9dd292e1c875f0e321f8524040a8139d28ca9
MD5 a5f3c6abe07617c26e57c0ad7dfb4710
BLAKE2b-256 5ef7095a4ae43333fccc9b4d8955b719c7d2a3f758d5d9898d61a7d68574f058

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