Skip to main content

A graph database in a single file

Kinbaku is the japanese art of bondage. In a graph, ropes are replaced by edges between nodes. This library allows you to manage large graphs on disk, using only one file and without having to load the whole graph in memory. The library is written in pure Python.

Installation

It is recommended to install the cityhash package:

pip install cityhash

To install Kinbaku:

pip install kinbaku

Basic usage

import kinbaku as kn

# create graph if the file doesn't already exist
G = kn.Graph("graph.db")

# add nodes
G.add_node("A")  # keys must be strings
G.add_node("B")
G.add_node("C")

# add edges
G.add_edge("A", "B")
G.add_edge("A", "C")

# get a node
print(G.node("A"))
print(G["A"])

# get out neighbors
print(list(G.neighbors("A")))

# get incoming nodes
print(list(G.predecessors("B")))

# iterating through the nodes
for node in G.nodes:
    print(node)

# iterating through the edges
for edge in G.edges:
    print(edge)

Node keys must imperatively be strings with a maximum length. The maximum length can be set before the graph is created using the max_key_len keyword argument.

Using custom attributes

With Kinbaku, nodes and edges can have custom attributes. The way to proceed is to create Python dataclasses that inherit from Kinbaku structures.

from dataclasses import dataclass
import kinbaku as kn


@dataclass
class User(kn.structure.Node):
    age: int = 0
    bio: str = ""


@dataclass
class Relation(kn.structure.Edge):
    weight: float = 0


G = kn.Graph("graph_with_attributes.db",
             node_class=User,
             edge_class=Relation,
             max_str_len=40)  # max string length

# using the 'add_node' method:
G.add_node("Mark", {"age": 25, "bio": "first text"})
# or using '__setitem__':
G["Mary"] = {"age": 32, "bio": "second text"}

# adding an edge with custom attributes:
G.add_edge("Mark", "Mary", {"weight": .1})

Release files for kinbaku 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kinbaku 0.0.2
File Size Uploaded
kinbaku-0.0.2.tar.gz 14.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for kinbaku 0.0.2
File Interpreter ABI Platform
kinbaku-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 29.2 kB

Release files / kinbaku-0.0.2.tar.gz

Download URL kinbaku-0.0.2.tar.gz
Size 14.9 kB
Tags Source
SHA-256 checksum
How to use checksums
1ebf264449b57ebdc567f4d4622d0080bf8ec044afcc78958aef92761fb16cff
BLAKE2b-256 checksum
How to use checksums
481f40898c511e87230c6d4bd10c6f40ecbbbca3e75c2800444f3991f094349b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.1

Release files / kinbaku-0.0.2-py3-none-any.whl

Download URL kinbaku-0.0.2-py3-none-any.whl
Size 14.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d47a1f68541ed3d37d2435517fd93f8247068835a376f2c5c8c44baf4d9ac2d2
BLAKE2b-256 checksum
How to use checksums
ed5766f3d00609e24f7b7e0ac6af532915fad20b32578675eaa09a0e9712f5fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.1

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

2 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page