SwarmLib Repository
This library facillitates access to the Swarm network.
Examples
The SwarmLib makes it easy to create Swarm Agents. There are two types of Agents: Consumers and Providers. See the examples below.
Consumer
A consumer is an agent that only uses the Swarm resources. For example:
from swarm_lib import Consumer
consumer = Consumer(keys_file="keys.json")
query = {
"operation": {"@type": "swarm:ReadOperation", "returns": "swarm:Image"},
"usageDuration": 30
}
image_executor = consumer.get_executor(query)
if image_executor.contract_providers():
result = image_executor.execute()
Provider
A provider makes resources available 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:
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.port(), threaded=True, debug=True, use_reloader=True)
else:
print("Could not join the Swarm Network")
Usage
Install with pip:
pip3 install swarm_lib
Follow the examples above to build your own Swarm Agents.
Contributing
Dependencies
sudo apt install python3-pip python3-setuptools python3-dev
pip3 install -r requirements.txt
Publish a new version
To make a new release, follow these steps:
- Update the version in
setup.py - Run
python3 setup.py sdist bdist_wheelto 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).
Metadata
Release files for swarm-lib 0.0.18
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| swarm_lib-0.0.18.tar.gz | 9.2 kB | Without provenance | Details for swarm_lib-0.0.18.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| swarm_lib-0.0.18-py3-none-any.whl | Python 3 | none | any | Details for swarm_lib-0.0.18-py3-none-any.whl |
Total release size: 20.4 kB
Release files / swarm_lib-0.0.18.tar.gz
| Download URL | swarm_lib-0.0.18.tar.gz |
|---|---|
| Size | 9.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
078d8cbdd6cb7d4c134888497f975e3e51ce6e06c0b8a2b55f0e3cc7fda653c7
|
|
BLAKE2b-256 checksum How to use checksums |
a3bfc788cd2c4527a850550fd47380ff1124af61020ed5b9a055e77d10695630
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.26.0 CPython/3.7.3
|
Release files / swarm_lib-0.0.18-py3-none-any.whl
| Download URL | swarm_lib-0.0.18-py3-none-any.whl |
|---|---|
| Size | 11.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2a5b5653737ab42aebc5d0430c1cff04de1c8b317597ffdb71cf3cc28cdc1b4a
|
|
BLAKE2b-256 checksum How to use checksums |
2b56cb4526b8629b4a5d8ba0b8fab99e95be0f412c60e1eae867c94d0024442e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.26.0 CPython/3.7.3
|
Security for swarm-lib 0.0.18
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.