resilient-python-cache
Python library for syncing ResilientDB data via WebSocket and HTTP with seamless reconnection.
resilient-python-cache is a library for establishing and managing real-time synchronization between ResilientDB and MongoDB using WebSocket and HTTP. It includes automatic reconnection, batching, and concurrency management for high-performance syncing.
Features
- Real-time sync between ResilientDB and MongoDB
- Handles WebSocket and HTTP requests with auto-reconnection
- Configurable synchronization intervals and batch processing
- Provides MongoDB querying for ResilientDB transaction data
Installation
To use the library, install it via pip:
pip install resilient-python-cache
Configuration
MongoDB Configuration
The library uses MongoDB to store ResilientDB data. Configure it by specifying:
uri: MongoDB connection stringdb_name: Database name in MongoDBcollection_name: Collection name in MongoDB where ResilientDB data is stored
ResilientDB Configuration
For ResilientDB configuration, specify:
base_url: The base URL for ResilientDB, e.g.,resilientdb://localhost:18000http_secure: Use HTTPS if set totruews_secure: Use WSS if set totruereconnect_interval: Reconnection interval in milliseconds (optional)fetch_interval: Fetch interval in milliseconds for periodic syncs (optional)
Usage
1. Syncing Data from ResilientDB to MongoDB
Create a sync script to initialize and start the data synchronization from ResilientDB to MongoDB.
# sync.py
import asyncio
from resilient_python_cache import ResilientPythonCache, MongoConfig, ResilientDBConfig
async def main():
mongo_config = MongoConfig(
uri="mongodb://localhost:27017",
db_name="myDatabase",
collection_name="myCollection"
)
resilient_db_config = ResilientDBConfig(
base_url="resilientdb://crow.resilientdb.com",
http_secure=True,
ws_secure=True
)
cache = ResilientPythonCache(mongo_config, resilient_db_config)
cache.on("connected", lambda: print("WebSocket connected."))
cache.on("data", lambda new_blocks: print("Received new blocks:", new_blocks))
cache.on("error", lambda error: print("Error:", error))
cache.on("closed", lambda: print("Connection closed."))
try:
await cache.initialize()
print("Synchronization initialized.")
try:
await asyncio.Future() # Run indefinitely
except asyncio.CancelledError:
pass
except Exception as error:
print("Error during sync initialization:", error)
finally:
await cache.close()
if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
print("Interrupted by user")
This script will:
- Initialize the connection to MongoDB and ResilientDB
- Continuously sync new blocks received from ResilientDB to MongoDB
API Documentation
Class ResilientPythonCache
-
constructor(mongo_config: MongoConfig, resilient_db_config: ResilientDBConfig):
- Initializes the sync object with MongoDB and ResilientDB configurations.
-
initialize(): Connects to MongoDB, fetches initial blocks, starts periodic fetching, and opens the WebSocket connection to ResilientDB.
-
close(): Closes the MongoDB and WebSocket connections, stopping the periodic fetching.
MongoDB Collection Structure
Each document in the MongoDB collection corresponds to a ResilientDB block, containing:
- id: Block identifier
- createdAt: Timestamp for block creation
- transactions: Array of transactions in the block, with details for each transaction’s inputs, outputs, and asset metadata
License
This library is licensed under the Apache License, Version 2.0.
Enjoy using resilient-python-cache to seamlessly synchronize your ResilientDB data to MongoDB with real-time updates and efficient querying!
Metadata
Release files for resilient-python-cache 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| resilient_python_cache-0.1.1.tar.gz | 9.3 kB | Without provenance | Details for resilient_python_cache-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| resilient_python_cache-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for resilient_python_cache-0.1.1-py3-none-any.whl |
Total release size: 20.1 kB
Release files / resilient_python_cache-0.1.1.tar.gz
| Download URL | resilient_python_cache-0.1.1.tar.gz |
|---|---|
| Size | 9.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
02396b4f445a8927fdc5248ec845c0e9d722c5d52c7d892b2af8962b7297875f
|
|
BLAKE2b-256 checksum How to use checksums |
c4eb5078ea833906ad2a8c2ad11e2132e2fb2c20f6f38a8298b2798aa202a2c1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.4 CPython/3.10.15 Linux/6.5.0-1025-azure
|
Release files / resilient_python_cache-0.1.1-py3-none-any.whl
| Download URL | resilient_python_cache-0.1.1-py3-none-any.whl |
|---|---|
| Size | 10.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5e43a053e3a2d192a10cc2a5e1578a9422baf55c8d40c781e75763133f2e38db
|
|
BLAKE2b-256 checksum How to use checksums |
cdcf222da818b23f70e32d0cd9f063d8463480cf4a952ac18483cf821fcb7fbe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.4 CPython/3.10.15 Linux/6.5.0-1025-azure
|
Security for resilient-python-cache 0.1.1
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.