Skip to main content

unosql - A Lightweight NoSQL Database for MicroPython

Project description

unosql - A Lightweight NoSQL Database for MicroPython

unosql is a lightweight and fast NoSQL database for the MicroPython environment that supports AES encryption and allows data to be stored in JSON files. This library provides CRUD (Create, Read, Update, Delete) operations with optional encryption support.

Features

  • NoSQL Database: Uses JSON format for data storage.
  • AES Encryption Support: Enables encryption and decryption of data using AES in ECB mode.
  • Collection Support: 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: Find and filter data based on key-value pairs.
  • HMAC-Based Security: Generates secure encryption keys using HMAC and SHA256.
  • Serverless Database: Suitable for use in embedded systems and MicroPython environments.

Installation

Install in MicroPython Environment

  1. Make sure you're using the MicroPython environment. If you haven't installed MicroPython yet, you can download it from the official MicroPython site.

  2. To install unosql, you can use upip:

for MicroPython, use the appropriate package manager like upip to install directly on your microcontroller.

upip install unosql
from unosql.core import unosql

No additional libraries are required.

Usage

1. Creating a Database

To create a database, instantiate the unosql class with the name of the database file. Optionally, you can provide an encryption key to enable encryption.

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

2. Inserting Records

To insert a record into a collection, use the insert method.

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

3. Finding Records

To find records based on a key-value pair, use the find method.

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

4. Updating Records

To update records that match a key-value pair, use the update method.

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

5. Deleting Records

To delete records matching a key-value pair, use the delete method.

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

6. Reading All Records

To read all records from a collection, use the all method.

db.all("users")

7. Clearing a Collection

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

db.clear("users")

Example Usage

Here is a simple example of using 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"))

    # 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

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

unosql-1.0.0.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

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

unosql-1.0.0-py3-none-any.whl (2.5 kB view details)

Uploaded Python 3

File details

Details for the file unosql-1.0.0.tar.gz.

File metadata

  • Download URL: unosql-1.0.0.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.0

File hashes

Hashes for unosql-1.0.0.tar.gz
Algorithm Hash digest
SHA256 2b423182651d5b9da1f332d467ce612f8eee71ff52ac554103f91edbc6b6a6ca
MD5 8f2e12263a842e5666de5d1d00c17d3c
BLAKE2b-256 b75be8e6c235af368ed9b4d9928f18ce6f7e49de6ea7f09f339863d5b656d8f4

See more details on using hashes here.

File details

Details for the file unosql-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: unosql-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 2.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.0

File hashes

Hashes for unosql-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1e07244ebe855517e005dd0122b4c2a682a691710474273e06d48609e55773f9
MD5 6f50132399c7b09beb85c3ad220ec5c5
BLAKE2b-256 8d78e369979bd6c1df348303dae7bd6d534e2db7506dc3ffcab939e57f0827ea

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