Skip to main content

BysonDB

A serverless key-value and document based database using BSON.

What the heck is BSON?

BSON is short for Binary JavaScript Object Notation. It is the binary encoding of JSON, created by MongoDB, and is used in their database. Unlike JSON, it was actually made for the storage of data. It is faster, and allows for more datatypes, such as dates and bytes, that JSON does not allow. You can read more about it's purpose, and it's similarities and differences to JSON here.

Usage:

Installation:

pip install bysondb

Key -> Value database:

A database just like normal JSON, with each key coresponding to a value

import datetime
from bysondb import BysonDB

# Create a database with a path to a file. The suffix
# will be changed to .bson, even if there is no suffix
my_db = BysonDB('path/to/database/file.bson')

# Set values like a normal dictionary
my_db["name"] = "John"
my_db["age"] = 30

# Get values in the same way
print(f"My name is {my_db['name']}. I am {my_db['age']} years old.")

# Some objects like datetimes can be used as well
# Not all objects can be serialized
my_db["date"] = datetime.datetime.now()

print(f"Today's date is {my_db['date'].strftime('%x')}")

# Deleting a key. Can't be undone, so be careful.
my_db.remove("test")

Document based database

A database structure similar to MongoDB, with a single collection of objects

from bysondb import BysonDocumentDB

# Creating a database is the same with the BysonDB,
# but using BysonDocumentDB
my_db = BysonDocumentDB('path/to/database/file.bson')

# Insert a single object to the database
person = {
    "name": "John",
    "age": 30
}
my_db.insert_one(person)

# Insert multiuple objects into the database
people = [
    {"name": "Joe"},
    {"name": "Steve"},
    {"key": "value"}
]
my_db.insert_many(people)


# Get objects as dicts from the database using a query

# Get all objects
all_objects = my_db.find({})

# Get an object where the key 'debug' is True
debug_objects = my_db.find({"debug": True})

# Find a maximum of 5 objects where the key 'key' is 'value'
objects = my_db.find({"key": "value"}, limit=5)

# Removing values is like finding them, with a search query and a limit
my_db.remove({"remove": True})
my_db.remove({"random_number": 5}, limit=1})

This package uses bson, a package for the BSON codec that does not rely on MongoDB.

This package was formatted using Black.

Metadata

Release files for bysondb 0.1.1

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

Source distribution (sdist)

Source distribution for bysondb 0.1.1
File Size Uploaded
bysondb-0.1.1.tar.gz 5.8 kB Details

Built distribution (wheel)

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

Total release size: 13.2 kB

Release files / bysondb-0.1.1.tar.gz

Download URL bysondb-0.1.1.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
d6338583c1bd1be3c0e4852bd6af928b845df487652bec2c7ef4a5af7e10b74b
BLAKE2b-256 checksum
How to use checksums
da34f773595a96742430d23d89fd4adc57e74272aad4cf4924d773971be13c75
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.7 CPython/3.9.6 Windows/10

Release files / bysondb-0.1.1-py3-none-any.whl

Download URL bysondb-0.1.1-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6e01f13b7b96233da81e837339dc3f1cb86d2106609da2c87876ed3d88c2d3a8
BLAKE2b-256 checksum
How to use checksums
cb16a0ab35f96074f942bf5f8256ea23cab997dcb67a007462aa0c4f1a5e1b82
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.7 CPython/3.9.6 Windows/10

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.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