Git Product home page Git Product logo

py-dtn7's Introduction

py-dtn7 (Work in Progress -- don't use yet)

Licence AGPL-3.0

A Python wrapper library for the DTN7 REST and WebSocket API of dtn7-rs. The library includes a fully spec compliant Bundle type (but without fragment and CRC support), which allows full bundle creation and (de-)serialization.

The bundle.py, dtn_rest_client.py, utils.py modules/files are Micropython compatible. But, this requires a bit of manual library management. Please refer to the Micropython installation guide below.

Getting Started

To use py-dtn7 in your project, simply install it from PyPI with Poetry:

$ poetry install --no-dev py_dtn7

Development

This is very much a work-in-progress and by far not complete. The Bundle implementation is very rudimentary and does not support any blocks other than Primary and Payload.

To generate the API documentation use pdoc:

$ pdoc ./py_dtn7 --output-directory ./docs

... or check out py-dtn7.readthedocs.org

Quickstart

>>> from py_dtn7 import DTNRESTClient
>>> client = DTNRESTClient(host="http://localhost", port=3000)
>>> d.peers
{'box1': {'eid': [1, '//box1/'], 'addr': {'Ip': '10.0.0.42'}, 'con_type': 'Dynamic', 'period': None, 'cla_list': [['MtcpConvergenceLayer', 16162]], 'services': {}, 'last_contact': 1653316457}}
>>> d.info
{'incoming': 0, 'dups': 0, 'outgoing': 0, 'delivered': 3, 'broken': 0}

When sending a bundle to a known peer, we can simply supply the peer name and endpoint, otherwise we use the complete URI:

>>> d.send(payload={"body": "This will be transferred as json"}, peer_name="box1", endpoint="info")
<Response [200]>
>>> r = d.send(payload="Is there anybody out there?", destination="dtn://greatunkown/incoming")
>>> r.content.decode("utf-8")
'Sent payload with 27 bytes'

Micropython Installation Guide

To be extended:

The dummy libraries __future__.py, abc.py, typing.py, the micropython-cbor library (specifically the cbor.py module/file) and urequests as well as datetime are needed:

$ mpremote mip install urequests
$ mpremote mip install datetime

py-dtn7's People

Contributors

lh70 avatar teschmitt avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

lh70

py-dtn7's Issues

Substitute urllib for requests

In an effort to minimize the dependency footprint, urllib could be used instead of requests, since we're not using any of the advanced utilities anyways.

POST requests will have to be manually augmented with the appropriate headers though:

body = {'ids': [12, 14, 50]}
myurl = "http://www.testmycode.com"

req = urllib.request.Request(myurl)
req.add_header('Content-Type', 'application/json; charset=utf-8')
jsondata = json.dumps(body)
jsondataasbytes = jsondata.encode('utf-8')   # needs to be bytes
req.add_header('Content-Length', len(jsondataasbytes))
response = urllib.request.urlopen(req, jsondataasbytes)

from here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.