Skip to main content

Simple py driver for bundlr

Project description

pybundlr

Simple py driver for bundlr.

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

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

pybundlr-0.1.6.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

pybundlr-0.1.6-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file pybundlr-0.1.6.tar.gz.

File metadata

  • Download URL: pybundlr-0.1.6.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for pybundlr-0.1.6.tar.gz
Algorithm Hash digest
SHA256 2adc6d2e9dd390c0559bb5e0bc11f7342980a8346e86d9402faade3cd5c8b6a4
MD5 e94c2744a9d72f604a18e34994a09a17
BLAKE2b-256 5d65dfad3ffbfbbc1c7342685042a7c50a5e2938c6e1f9abc0dbc42a3bfa4488

See more details on using hashes here.

File details

Details for the file pybundlr-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: pybundlr-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for pybundlr-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 d93a766c4352901614d3886b77d5687b7e443e20036ff20d985076ce57b041a2
MD5 4a8f093d9dac4cf1332ae8a8ea1c2ef8
BLAKE2b-256 19fa52f9da2412d60a1522b9d6ebbc9ec5d35b6bc3cef263b4f71fff20a151d2

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