Skip to main content

Hive-as-a-DB SDK for Python

Project description

haadb

Hive-as-a-DB SDK for Python.

Leveraging Hive custom JSONs to store both text-based and binary data. Hive Custom JSONs are limited to 4096 KB includng overheads, HaaDB breaks data into chunks whenever required.

When using objects such as images, files, etc., make sure you have processed it into hex-strings, for example, else it might use class names, pointers, or other data that may result to data loss.

Official Release

HaaDB can now be used on your Python projects through PyPi by running pip command on a Python-ready environment.

pip install haadb --U

Current version is 1.0.*, but more updates are coming soon.

This is compatible with Python 3.9 or later.

WARNINGS:

  • This package is still under development, some future breakage is inevitable.
  • All write transactions in the Hive Blockchain incurs RC costs.
  • Do NOT copy your private keys in your codes!

HaaDB Modules.

WARNING: Store WIFs securely in a separate file!

Import Module

from haadb import HaaDB

Initialization

# Warning: Do NOT store your WIFs in the code,
# or in the repository!
username = "valid-username"
wifs = { "active": "5*" , "posting": "5*"}

# `limit` --> bytes size before the string representation
# before the string is sliced into chunks, 1024-4096 (default 4096)
limit = 1024 

# basic usage
db = HaaDB(username, wifs=wifs, limit=limit)

Optimization

Get the last known transaction id and store in your app configuration. This will optimize the traversal in the account history.

marker = hive.get_marker()

Encryption

Generate a unique encryption key and store securely, to avoid data loss. You can create separate encryption keys for different contracts, or depending on your needs.

ek = hive.generate_encryption_key()

Broadcasting unencrypted data using custom JSONs

cid = "store-integers-v1"
data = 1234567890
hive.broadcast(cid, data)

Fetching unencrypted data (all versions)

cid = "store-integers-v1"
result = hive.fetch(cid, start=marker, latest=False)
for timestamp, content in result.items():
    print(timestamp, content)

Fetching unencrypted data (latest version)

cid = "store-integers-v1"
result = hive.fetch(cid, start=marker)
print("\nResult:", result, type(result))

Broadcasting encrypted data using custom JSONs

cid = "store_encrypted_string_v1"
data = "Lorem ipsum, this is a secret message..."
hive.broadcast(cid, data, encryption_key=ek)

Fetching encrypted data (all versions)

cid = "store_encrypted_string_v1"
result = hive.fetch(cid, encryption_key=ek, start=marker, latest=False)
for timestamp, content in result.items():
    print(timestamp, content)

Fetching encrypted data (latest versions)

cid = "store_encrypted_string_v1"
result = hive.fetch(cid, encryption_key=ek, start=marker)
print("\nResult:", result, type(result)

Lists, dictionaries, and other objects.

All native data types can be converted back, but other objects will be returned as string representation instead.

cid = "native_list_v1"
data = [1, "2", 3.4]
hive.broadcast(cid, data, encryption_key=ek)
result = hive.fetch(cid, encryption_key=ek, start=marker)
print("\nResult:", result, type(result)

cid = "native_dict_v1"
data = { "message": "Hello, world!"}
hive.broadcast(cid, data, encryption_key=ek)
result = hive.fetch(cid, encryption_key=ek, start=marker)
print("\nResult:", result, type(result)

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

haadb-1.0.0.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

haadb-1.0.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: haadb-1.0.0.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.0

File hashes

Hashes for haadb-1.0.0.tar.gz
Algorithm Hash digest
SHA256 9c62579a389d463879933db3822a793ab116112cf1be9e0ba7cd50132d773521
MD5 b52c7f9ca192272caf7eab4a4621bdce
BLAKE2b-256 5d42d4024549ec2e6285405994700781b0677e778043e78ce7bd719b8e63b0d4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: haadb-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.0

File hashes

Hashes for haadb-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 771eb637f365bcf8c6c4b261c4a7b944b170c36f22bfafe04d055d55b4d97abf
MD5 6ed55e0c4affd653be8338d56d6adce6
BLAKE2b-256 e95b286667db03a9db85fb46de14458e554916f96538bd178a88aa0b1c9b3908

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