Simple py driver for bundlr
Project description
pybundlr
Simple py driver for bundlr.
- Constructed by wrapping bundlr CLI.
- Full API in pybundlr.py
- Pypi main, test
- GitHub repo
Installation
Ensure prerequisites:
- Linux/MacOS
- Python 3.8.5+
- Bundlr CLI:
npm install -g @bundlr-network/client
Open a new terminal and:
#Create & activate venv
python -m venv venv
source venv/bin/activate
#main install
pip3 install pybundlr
Using Pybundlr Library
First, a quick example that reads information from a bundlr node. In this case, a balance.
In terminal, go into Python console: python
In Python console:
from pybundlr import pybundlr
eth_address = "0x7BA3d8551A6f2C70a5d47bb448BcF7EF69661822"
bal = pybundlr.balance(eth_address, "matic")
print(f"{eth_address[:4]}'s MATIC balance in bundlr node: {bal} wei")
Exit the Python console for the next step.
Now, for more thorough example. We'll create a file, publish it online, then read it back.
The bundlr node will need funds to pay for storage. So, please ensure that you have a Polygon account that holds some MATIC. Just a few cents' worth should be enough.
In terminal, export the private key of your Polygon account:
export TEST_PRIVATE_KEY1=<your private key>
In terminal, go into Python console: python
In Python console:
import os
import requests
from pybundlr import pybundlr
eth_private_key = os.getenv('REMOTE_TEST_PRIVATE_KEY1')
#create test file
file_name = "/tmp/testfile.txt"
content_in = "test content" + "\n"
with open(file_name, 'a') as f:
f.write(content_in)
#fund the node, and upload the file
url = pybundlr.fund_and_upload(file_name, "matic", eth_private_key)
print(f"Uploaded file. It's online at: {url}")
#retrieve the result
result = requests.get(url)
content_out = result.text
assert content_out == content_in
This example was on Polygon mainnet, with currency = "matic"
. Pybundlr also works on Ethereum mainnet ("ethereum"
), Arweave ("arweave"
), and more.
Development
- Developers flow - to further develop pybundlr
- Release process - to do a new release of pybundlr
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pybundlr-0.1.11-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64920ba77d04eff84914d34ffef9f8693afc1d4291c3701d30e45553e97ecb9e |
|
MD5 | 8140762915c832bef38c50271d184270 |
|
BLAKE2b-256 | 0764cc10c8753d54676a8c741c79427d3cb0075d9a12fe4106cc6f7beb5f12e3 |