{"id":21156928,"url":"https://github.com/resilientecosystem/resilient-python-cache","last_synced_at":"2025-04-13T12:29:28.341Z","repository":{"id":261779192,"uuid":"885332116","full_name":"ResilientEcosystem/resilient-python-cache","owner":"ResilientEcosystem","description":"Python library for syncing ResilientDB data via WebSocket and HTTP with seamless reconnection.","archived":false,"fork":false,"pushed_at":"2024-11-08T12:07:50.000Z","size":18,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-22T20:06:54.225Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://pypi.org/project/resilient-python-cache/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ResilientEcosystem.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-08T11:37:03.000Z","updated_at":"2024-11-17T03:14:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"b265d1d8-5284-4599-86c9-4a099b8960fb","html_url":"https://github.com/ResilientEcosystem/resilient-python-cache","commit_stats":null,"previous_names":["resilientecosystem/resilient-python-cache"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ResilientEcosystem%2Fresilient-python-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ResilientEcosystem%2Fresilient-python-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ResilientEcosystem%2Fresilient-python-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ResilientEcosystem%2Fresilient-python-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ResilientEcosystem","download_url":"https://codeload.github.com/ResilientEcosystem/resilient-python-cache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248713892,"owners_count":21149799,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-20T11:55:06.569Z","updated_at":"2025-04-13T12:29:28.318Z","avatar_url":"https://github.com/ResilientEcosystem.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# resilient-python-cache\n\n**Python library for syncing ResilientDB data via WebSocket and HTTP with seamless reconnection.**\n\n[![License](https://img.shields.io/badge/license-Apache%202-blue)](https://www.apache.org/licenses/LICENSE-2.0)\n\n`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.\n\n## Features\n\n- Real-time sync between ResilientDB and MongoDB\n- Handles WebSocket and HTTP requests with auto-reconnection\n- Configurable synchronization intervals and batch processing\n- Provides MongoDB querying for ResilientDB transaction data\n\n## Installation\n\nTo use the library, install it via pip:\n\n```bash\npip install resilient-python-cache\n```\n\n## Configuration\n\n### MongoDB Configuration\n\nThe library uses MongoDB to store ResilientDB data. Configure it by specifying:\n\n- `uri`: MongoDB connection string\n- `db_name`: Database name in MongoDB\n- `collection_name`: Collection name in MongoDB where ResilientDB data is stored\n\n### ResilientDB Configuration\n\nFor ResilientDB configuration, specify:\n\n- `base_url`: The base URL for ResilientDB, e.g., `resilientdb://localhost:18000`\n- `http_secure`: Use HTTPS if set to `true`\n- `ws_secure`: Use WSS if set to `true`\n- `reconnect_interval`: Reconnection interval in milliseconds (optional)\n- `fetch_interval`: Fetch interval in milliseconds for periodic syncs (optional)\n\n## Usage\n\n### 1. Syncing Data from ResilientDB to MongoDB\n\nCreate a sync script to initialize and start the data synchronization from ResilientDB to MongoDB.\n\n```python\n# sync.py\n\nimport asyncio\nfrom resilient_python_cache import ResilientPythonCache, MongoConfig, ResilientDBConfig\n\nasync def main():\n    mongo_config = MongoConfig(\n        uri=\"mongodb://localhost:27017\",\n        db_name=\"myDatabase\",\n        collection_name=\"myCollection\"\n    )\n\n    resilient_db_config = ResilientDBConfig(\n        base_url=\"resilientdb://crow.resilientdb.com\",\n        http_secure=True,\n        ws_secure=True\n    )\n\n    cache = ResilientPythonCache(mongo_config, resilient_db_config)\n\n    cache.on(\"connected\", lambda: print(\"WebSocket connected.\"))\n    cache.on(\"data\", lambda new_blocks: print(\"Received new blocks:\", new_blocks))\n    cache.on(\"error\", lambda error: print(\"Error:\", error))\n    cache.on(\"closed\", lambda: print(\"Connection closed.\"))\n\n    try:\n        await cache.initialize()\n        print(\"Synchronization initialized.\")\n\n        try:\n            await asyncio.Future()  # Run indefinitely\n        except asyncio.CancelledError:\n            pass\n\n    except Exception as error:\n        print(\"Error during sync initialization:\", error)\n    finally:\n        await cache.close()\n\nif __name__ == \"__main__\":\n    try:\n        asyncio.run(main())\n    except KeyboardInterrupt:\n        print(\"Interrupted by user\")\n```\n\nThis script will:\n- Initialize the connection to MongoDB and ResilientDB\n- Continuously sync new blocks received from ResilientDB to MongoDB\n\n### API Documentation\n\n#### Class `ResilientPythonCache`\n\n- **constructor(mongo_config: MongoConfig, resilient_db_config: ResilientDBConfig)**:\n  - Initializes the sync object with MongoDB and ResilientDB configurations.\n\n- **initialize()**: Connects to MongoDB, fetches initial blocks, starts periodic fetching, and opens the WebSocket connection to ResilientDB.\n\n- **close()**: Closes the MongoDB and WebSocket connections, stopping the periodic fetching.\n\n### MongoDB Collection Structure\n\nEach document in the MongoDB collection corresponds to a ResilientDB block, containing:\n- **id**: Block identifier\n- **createdAt**: Timestamp for block creation\n- **transactions**: Array of transactions in the block, with details for each transaction’s inputs, outputs, and asset metadata\n\n### License\n\nThis library is licensed under the [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0).\n\n---\n\nEnjoy using `resilient-python-cache` to seamlessly synchronize your ResilientDB data to MongoDB with real-time updates and efficient querying!","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fresilientecosystem%2Fresilient-python-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fresilientecosystem%2Fresilient-python-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fresilientecosystem%2Fresilient-python-cache/lists"}