A Library for accessing the Swarm network written in Python
Project description
SwarmLib Repository
Instructions for using swarm_lib.
Dependencies
sudo apt install python3-pip python3-setuptools python3-dev
pip3 install -r requirements.txt
Install
Install with pip3
: pip3 install swarm_lib
Or, put this on your requirements.txt
:
swarm_lib
Use
The SwarmLib can be used to create Swarm Consumers and Providers.
Consumer
A consumer is a client that only uses the Swarm resources. For example:
from swarm_lib import Consumer
consumer = Consumer(keys_file="keys.json")
query = {
"@type": "swarm:Camera",
"operation": {"@type": "ReadOperation"},
"usageDuration": 30
}
image_executor = consumer.get_executor(query)
if image_executor.contract_providers():
result = image_executor.smart_use()
Provider
A provider provides resources to the Swarm. For example:
from flask import Flask, request, jsonify
from swarm_lib import Provider
from onboard_camera import read_frame
app = Flask(__name__)
provider = Provider(
description_file="./description.jsonld",
policies_file="./policies.json",
keys_file="./keys.json"
)
@app.route("/camera-service/image", methods=['GET'])
@provider.enforce_authorization
def get_frame():
try:
return jsonify(read_frame())
except Exception as e:
print(e)
return(jsonify({"error": "could not get frame from onboard camera"}))
if __name__ == "__main__":
if provider.join_swarm():
app.run(host="0.0.0.0", port=provider.get_port(), threaded=True, debug=True, use_reloader=True)
else:
print("Could not join the Swarm Network")
Publish a new version
If you are changing the code of this library, and want to make a new release, follow these steps:
- Update the version in
setup.py
- Run
python3 setup.py sdist bdist_wheel
to create a distributable release - Run
python3 -m twine upload dist/*
to upload to pip
If a password is asked and you don't know what to do, ask the maintainer (Geovane Fedrecheski).
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
swarm_lib-0.0.2.tar.gz
(8.7 kB
view hashes)
Built Distribution
swarm_lib-0.0.2-py3-none-any.whl
(10.7 kB
view hashes)
Close
Hashes for swarm_lib-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 09f89c67c9d5b141eeea7a2bd0ca870c6043431888796b2ad20d7a512352909b |
|
MD5 | 9a069727d3b87a53eb8d33692b5fd101 |
|
BLAKE2b-256 | cc65c920769d59b2513b1a9dc06d625c30770c737882caba01f310bba64781eb |