Skip to main content

Peer to Peer B-tree

Project description

Hyperbee

A peer-to-peer append-only B-tree built on Hypercore. Compatible with the JavaScript version.

$ cargo add hyperbee

Usage

From the examples:

use hyperbee::Hyperbee;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let hb = Hyperbee::from_ram().await?;
    // Insert "world" with key "hello"
    hb.put(b"hello", Some(b"world")).await?;

    // Get the value for key "hello"
    let Some((_seq, Some(val))) = hb.get(b"hello").await? else {
        panic!("could not get value");
    };
    assert_eq!(val, b"world");

    // Trying to get a non-exsitant key returns `None`
    let res = hb.get(b"no key here").await?;
    assert_eq!(res, None);

    // Deleting a key returns `true` if it was present
    let res = hb.del(b"hello").await?;
    assert!(res.is_some());

    // Getting deleted key returns `None`
    let res = hb.get(b"hello").await?;
    assert_eq!(res, None);

    Ok(())
}

Foreign Language Bindings

We use UniFFI to generate libraries for other languages. To build the library for python run:

cargo build -F ffi && cargo run -F ffi --bin uniffi-bindgen generate --library target/debug/libhyperbee.so --language python --out-dir out

This generates a file out/hyperbee.py, which an be used. This file requires that libhyperbee.so be present alongside the .py file. Distributable python packages are still a work-in-progress. Currently only Python is tested. See the tests for example usage.

Parity with JS Hyperbee

  • full functional interoperability with JS Hyperbee files
  • read, write, and delete operations
  • in-order key streaming like JS's createReadStream
  • support gt, lt, etc bounds for key streaming
  • accept compare-and-swap for put and del.
  • support prefixed key operations like JS's sub
  • one-to-one binary output

Future work

  • Build FFI wrappers
  • improved wire format
  • configurable tree parameters

Development

Run the tests with $ cargo test.

Project details


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 Distribution

hyperbeepy-0.3.1-py3-none-manylinux_2_34_x86_64.whl (19.8 MB view details)

Uploaded Python 3 manylinux: glibc 2.34+ x86-64

File details

Details for the file hyperbeepy-0.3.1-py3-none-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for hyperbeepy-0.3.1-py3-none-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 6cd141c333301391ee5a45cf83121b276c840ee8a09ac0b49b9d3fe0acc7548d
MD5 aab0608c189b86b538be56b3b0728496
BLAKE2b-256 8c851c69a4fe786a51121c3efa5edced17805555157330a07dd77137c4b3a63b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page