Skip to main content

unosql - A Lightweight Encrypted NoSQL Database for MicroPython

unosql is a lightweight, serverless NoSQL database designed for the MicroPython environment. It supports AES encryption for secure data storage and enables CRUD (Create, Read, Update, Delete, Backup) operations on collections stored in JSON format.

Features

  • NoSQL Database: Stores data in JSON format, allowing easy collection management.
  • AES Encryption: Provides AES encryption (ECB mode) to secure your data using a 16-byte encryption key.
  • Collection-Based Storage: Allows data to be stored and retrieved in separate collections.
  • CRUD Operations: Supports adding, searching, updating, deleting, and reading all records.
  • Key-Value Pair Searching: Efficiently find and filter data based on key-value pairs.
  • Secure Key Generation: Generates encryption keys securely using HMAC and SHA256.
  • Serverless: Perfect for use in embedded systems like ESP32, ESP8266, or other MicroPython-compatible boards.

Install in MicroPython Environment

Ensure you're using the MicroPython environment. If you haven't installed MicroPython yet, download it from the official site.

To install unosql in your MicroPython environment, use the upip package manager:

upip install unosql

Then import the library:

from unosql import unosql

No additional dependencies are required.

Usage

1. Creating a Database

To create a new database, instantiate the unosql class with the database name. Optionally, you can provide an encryption key (16 bytes) for data encryption.

db = unosql("my_database", encryption_key=b"16bytekey1234567")

2. Inserting Records

Use the insert method to add a new record (a dictionary) to a collection:

db.insert("users", {"id": 1, "name": "Arman", "age": 29})

3. Finding Records

To find records that match a key-value pair, use the find method:

db.find("users", "id", 1)

4. Updating Records

To update records based on a key-value match, use the update method:

db.update("users", "id", 1, {"name": "Arman", "age": 30})

5. Deleting Records

To delete records that match a key-value pair, use the delete method:

db.delete("users", "id", 1)

6. Reading All Records

Use the all method to retrieve all records in a collection:

db.all("users")

7. Clearing a Collection

To clear all records from a collection, use the clear method:

db.clear("users")

8. Backup and Restore

You can back up the entire database to a file or restore it from a backup:

# Backup the database
db.backup("backup.db")

# Restore the database from a backup
db.restore("backup.db")

Example Usage

Here’s a simple example demonstrating how to use unosql:

def example_usage():
    # Initialize the database with encryption
    db = unosql("my_database", encryption_key=b"16bytekey1234567")

    # Insert records into the "users" collection
    db.insert("users", {"id": 1, "name": "Arman", "age": 29})
    db.insert("users", {"id": 2, "name": "Ayso", "age": 31})
    db.insert("users", {"id": 3, "name": "Aynaz", "age": 19})

    print("All users after insertion:", db.all("users"))

    # Find a specific user by id
    print("Find user with id=2:", db.find("users", "id", 2))

    # Update a user's record
    db.update("users", "id", 2, {"name": "Arman", "age": 30})
    print("All users after update:", db.all("users"))

    # Delete a user
    db.delete("users", "id", 1)
    print("All users after deleting user with id=1:", db.all("users"))

    # Backup the database
    db.backup("backup.db")

    # Clear the collection
    db.clear("users")
    print("All users after clearing:", db.all("users"))

# Run the example
example_usage()

Requirements

  • MicroPython: This library is designed for use with MicroPython on ESP32, ESP8266, or other compatible boards.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Test Images

unosql in Test-file

Metadata

Release files for unosql 1.1.0

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

Source distribution (sdist)

Source distribution for unosql 1.1.0
File Size Uploaded Provenance Actions
unosql-1.1.0.tar.gz 3.4 kB Without provenance Details for unosql-1.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 6.0 kB

Release files / unosql-1.1.0.tar.gz

Download URL unosql-1.1.0.tar.gz
Size 3.4 kB
Tags Source
SHA-256 checksum
How to use checksums
3495e5f3e6ec21a2aca7d2373aae192c5e3ba8e4b3b4f4509e2366a462fd457b
BLAKE2b-256 checksum
How to use checksums
674c3c776f54eb26938e3da6da2975bdf0ebd36ae60439a171fa9ddeb5e783bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.0

Release files / unosql-1.1.0-py3-none-any.whl

Download URL unosql-1.1.0-py3-none-any.whl
Size 2.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5978c38efa85a078b52b068d688fb294d1693df38b98ec5c44defb03b58e81b6
BLAKE2b-256 checksum
How to use checksums
72b17b1f605f6fc685062fcb0a1209d7470ca8464aa7bfc0c10f63b73f1292d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.0

Security for unosql 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files No provenance

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