Skip to content

Python client library for connecting to Bee decentralised storage

License

Notifications You must be signed in to change notification settings

alienrobotninja/bee-py

🐝 Bee Py

Feature Value
Technology Python Ape GitHub Actions Pytest pdm-managed
Linting Code style: black Style Guide Imports: isort
Type Checking Ruff Checked with mypy
CI/CD Tests Labeler pre-commit
Docs Read the Docs
Package PyPI - Version PyPI - Python Version PyPI - License
Meta GitHub license GitHub last commit GitHub commit activity GitHub top language

πŸ“– Table of Contents

🌐 Overview

This is the library for connecting to Bee decentralised storage using python.

✨ Features

  • TODO

πŸ“‹ Requirements

  • Python3.9+

πŸš€ Testing Locally

πŸ› οΈ Installation

You can install bee-py via [pip] from [PyPI]:

pip install swarm-bee-py

πŸš€ Usage

🐝 Bee Endpoint

from bee_py.bee import Bee

bee = Bee("https://18.134.10.41:1633")
# List Tags
all_tags = bee.get_all_tags({"limit": 1000})
print(all_tags) 
>>> [Tag(split=0, seen=0, stored=0, sent=0, synced=6, uid=2270760008, started_at='2023-12-27T19:00:24Z', total=6, processed=6),
 Tag(split=0, seen=0, stored=0, sent=0, synced=0, uid=2271272542, started_at='2023-12-09T13:22:52Z', total=0, processed=0),
 Tag(split=0, seen=0, stored=0, sent=0, synced=3, uid=2272654825, started_at='2023-12-26T22:15:30Z', total=3, processed=3),
 Tag(split=0, seen=0, stored=0, sent=0, synced=3, uid=2274652661, started_at='2023-12-19T20:27:27Z', total=3, processed=3),
 Tag(split=0, seen=0, stored=0, sent=0, synced=4, uid=2274680401, started_at='2024-01-05T20:03:17Z', total=4, processed=4),
 Tag(split=0, seen=0, stored=0, sent=0, synced=16, uid=2274738522, started_at='2023-12-27T00:12:46Z', total=16, processed=16),
 Tag(split=0, seen=0, stored=0, sent=0, synced=6, uid=2277789382, started_at='2024-01-05T19:30:39Z', total=6, processed=6),
 Tag(split=0, seen=0, stored=0, sent=0, synced=5, uid=2278169907, started_at='2023-12-27T00:44:34Z', total=5, processed=5),
 Tag(split=0, seen=0, stored=0, sent=0, synced=1, uid=2278428847, started_at='2023-12-19T01:29:06Z', total=1, processed=1),
 Tag(split=0, seen=0, stored=0, sent=0, synced=1, uid=2280360127, started_at='2023-12-27T16:18:04Z', total=1, processed=1)]

# Random Taken for example
batch_id = "eeba33ebe515c3ca9827a5e82e07987f813966fd39067126b120bcd6cd714ce9"
# Upload Data
upload_result = bee.upload_data(batch_id, "Bee is Awesome!")

print(upload_result)
>>> UploadResult(reference=Reference(value='b0d6b928d0f64fab1a50d37a965515cc6f152d3c27f58fbcefb6b8506f23b076'), tag_uid=None)

print(upload_result.reference)
>>> Reference(value='b0d6b928d0f64fab1a50d37a965515cc6f152d3c27f58fbcefb6b8506f23b076')

print(upload_result.reference.value)
>>> 'b0d6b928d0f64fab1a50d37a965515cc6f152d3c27f58fbcefb6b8506f23b076'

# Both can be done to obtain the reference value

print(str(upload_result.reference))
>>> 'b0d6b928d0f64fab1a50d37a965515cc6f152d3c27f58fbcefb6b8506f23b076'

data = bee.download_data(upload_result.reference.value)
print(data)
>>> Data(data=b'Bee is Awesome!')

# Data can be converted into json format, hex, bytes or plain-text
print(data.to_json())
>>> '{"data":"Bee is Awesome!"}'

print(data.text())
>>> 'Bee is Awesome!'

print(data.hex())
>>> '42656520697320417765736f6d6521'

πŸš€ Bee Debug Endpoint

from bee_py.bee_debug import BeeDebug

bee_debug = BeeDebug("https://18.134.10.41:1635")

# Be aware, this creates on-chain transactions that spend Eth and BZZ!
# Get Postage
batch_id = bee_debug.create_postage_batch('2000', 20)
print(batch_id)
>>> "17cbeb913ff852e34ade49c6df75adc7ff6f263b86d59c1cb2c3b0388cfe9cf3"

πŸ‘©β€πŸ’» Development

This project is developed using pdm. So the quickest way to get started is using pdm. Install pdm using pip, pipx etc & then follow the following steps

git clone https://github.com/alienrobotninja/bee-py
cd bee-py
# To install all the dev & lint dependencies 
pdm install -G:all

That's it, you're environment is ready. Now install docker to run bee-factory. Now to start the bee-factory do bee-factory start --detach 1.15.0-rc2. As of 7th January 2024 1.15.0-rc2 is the latest release for bee-factory which uses a very outdated versions of bee.

🀝 Contributing

Contributions are very welcome. To learn more, see the Contributor Guide.

πŸ“„ License

Distributed under the terms of the GPL 3.0 license, Bee Py is free and open source software.

🐞 Issues

There are some know issues like:

  • Some tests are perfomed on older versions of bee.
  • Some tests are stuck for hours when using the latest Bee API(not bee-py issue).
  • Some tests are skipped because of outdated libraries used by various ethersphere projects.

If you encounter any problems, please [file an issue] along with a detailed description.

πŸ“š Documentation

You can find the full documentation here. The API reference documentation can be found here.

πŸ‘ Credits

Developed by @Aviksaikat