Skip to main content

Bison is a fast, lightweight NoSQL database, written in Rust with seamless Python bindings.

Project description

Bison

Bison

Bison is a fast, lightweight NoSQL database, written in Rust with seamless Python bindings. It combines the speed and safety of Rust with the flexibility of JSON storage, offering a MongoDB-like query language to easily store, query, and manipulate your data. Perfect for developers who need a powerful, schema-less database that integrates smoothly into Python projects, Bison is designed to handle complex queries and efficient updates while keeping your data operations simple and intuitive.

Features

  • NoSQL Document Storage: Stores JSON documents in collections.
  • MongoDB-like Query Language: Use familiar query operators such as $eq, $ne, $gt, $gte, $lt, $lte for filtering documents.
  • Insert and Query: Easily insert documents into collections and retrieve them based on queries.
  • Update Operators: Modify documents using $set, $inc, $dec, $add, $substract, and $delete operators.
  • Mixed Queries: Perform complex queries with multiple conditions and nested fields.
  • Conditional Updates: Update only the documents that match a query filter.
  • Python Bindings: Fully integrated with Python via bindings, allowing you to use Bison in Python projects.
  • File Commit: Changes are committed to disk only when explicitly requested via db.write() or db.write_all().

Installation

To use Bison in your Python project, install it using:

pip install bison-db

Basic Usage

Creating a Collection and Inserting Documents

from bison import Bison

db = Bison()

# Create a collection
db.create_collection("test")

# Insert documents
db.insert("test", {"a": 10, "b": 20})
db.insert("test", {"a": True, "b": False})

Querying Data

# Simple equality query
result = db.find("test", {"a": 10})
print(result)  # Returns documents where field 'a' equals 10

# Query with greater than operator
result = db.find("test", {"a": {"$gt": 5}})
print(result)  # Returns documents where 'a' is greater than 5

Update Documents Conditionally

You can update documents only when a filter query is matched. If no filter query is provided, all documents in the collection will be updated.

# Conditionally update documents where 'a' equals 10
db.update("test", {"b": {"$set": 30}}, {"a": {"$eq": 10}})

# Update all documents in the collection if no filter is provided
db.update("test", {"b": {"$set": 50}}, None)

Committing Changes to Disk

By default, Bison stores all updates in memory. Changes will only be committed to a file when you explicitly call db.write(collection_name) for a specific collection, or db.write_all() to write all collections to disk:

# Commit changes of a specific collection to disk
db.write("test")

# Commit changes of all collections to disk
db.write_all()

Update Documents

# Update document by setting a new value
db.update("test", {"a": {"$set": 30}})

# Increment a field
db.update("test", {"a": {"$inc": ""}})

# Decrement a field
db.update("test", {"a": {"$dec": ""}})

Delete Fields

# Delete a field from a document
db.update("test", {"a": {"$delete": ""}})

Query Operators

Bison supports a range of MongoDB-like query operators:

  • $eq: Matches values that are equal to a specified value.

  • $ne: Matches all values that are not equal to a specified value.

  • $gt: Matches values that are greater than a specified value.

  • $gte: Matches values that are greater than or equal to a specified value.

  • $lt: Matches values that are less than a specified value.

  • $lte: Matches values that are less than or equal to a specified value.

Example Queries

# Equality
result = db.find("test", {"a": {"$eq": 10}})

# Not equal
result = db.find("test", {"a": {"$ne": 20}})

# Greater than
result = db.find("test", {"a": {"$gt": 10}})

# Less than
result = db.find("test", {"a": {"$lt": 100}})

Update Operators

Bison provides several operators for updating fields within documents:

  • $set: Sets the value of a field.

  • $inc: Increments a field by 1.

  • $dec: Decrements a field by 1.

  • $add: Adds a specified value to a field.

  • $substract: Subtracts a specified value from a field.

  • $delete: Deletes a field from a document.

Example Updates

# Set a value
db.update("test", {"a": {"$set": 40}})

# Increment a field
db.update("test", {"b": {"$inc": ""}})

# Delete a field
db.update("test", {"a": {"$delete": ""}})

Mixed Queries

You can combine multiple query conditions, including nested fields:

# Query with mixed conditions
result = db.find(
    "test",
    {
        "a": {"$eq": {"myobj": 20}},
        "b": {"$gt": 19},
        "c": {"$lte": 120}
    }
)
print(result)  # Returns documents matching all the conditions

Handling Errors

Invalid queries will raise exceptions. For example:

from bison import Bison
import pytest

db = Bison()

# Insert a document
db.insert("test", {"a": 10})

# Invalid query
with pytest.raises(ValueError):
    db.find("test", {"a": {"$gt": False}})

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bison_db-0.1.0.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bison_db-0.1.0-cp310-cp310-manylinux_2_34_x86_64.whl (365.4 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

File details

Details for the file bison_db-0.1.0.tar.gz.

File metadata

  • Download URL: bison_db-0.1.0.tar.gz
  • Upload date:
  • Size: 17.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.7.1

File hashes

Hashes for bison_db-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cbb4c106a778171bfa0495705e1ab15ee4f11717640f14d0fabcad3a6ac9d495
MD5 991472f4ec1d8bfaa97ed4f7a8708552
BLAKE2b-256 495750e7ec1522c65d0b13c6e4205d79c5d16ba0b29699f11738ead16193bcf4

See more details on using hashes here.

File details

Details for the file bison_db-0.1.0-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for bison_db-0.1.0-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 c147f9f14ef5df12b8eb0ece7ca0ed49f55d8e6bc189d0b541ab123f1e695d04
MD5 c9021abb7e7194776d6d3f71b2360184
BLAKE2b-256 b508312fd9b68d62d2cc26c9a0c94fcb2bbcc443909d50e9382e6ea832f909a1

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