Python implementation of jbenet's multiaddr
Project description
Multiaddr
Python implementation of jbenet’s multiaddr
Free software: MIT License
Documentation: https://multiaddr.readthedocs.org.
Usage
Simple
from multiaddr import Multiaddr
# construct from a string
m1 = Multiaddr("/ip4/127.0.0.1/udp/1234")
# construct from bytes
m2 = Multiaddr(bytes_addr=m1.to_bytes())
assert str(m1) == "/ip4/127.0.0.1/udp/1234"
assert str(m1) == str(m2)
assert m1.to_bytes() == m2.to_bytes()
assert m1 == m2
assert m2 == m1
assert not (m1 != m2)
assert not (m2 != m1)
Protocols
from multiaddr import Multiaddr
m1 = Multiaddr("/ip4/127.0.0.1/udp/1234")
# get the multiaddr protocol description objects
m1.protocols()
# [Protocol(code=4, name='ip4', size=32), Protocol(code=17, name='udp', size=16)]
En/decapsulate
from multiaddr import Multiaddr
m1 = Multiaddr("/ip4/127.0.0.1/udp/1234")
m1.encapsulate(Multiaddr("/sctp/5678"))
# <Multiaddr /ip4/127.0.0.1/udp/1234/sctp/5678>
m1.decapsulate(Multiaddr("/udp"))
# <Multiaddr /ip4/127.0.0.1>
Tunneling
Multiaddr allows expressing tunnels very nicely.
printer = Multiaddr("/ip4/192.168.0.13/tcp/80")
proxy = Multiaddr("/ip4/10.20.30.40/tcp/443")
printerOverProxy = proxy.encapsulate(printer)
print(printerOverProxy)
# /ip4/10.20.30.40/tcp/443/ip4/192.168.0.13/tcp/80
proxyAgain = printerOverProxy.decapsulate(printer)
print(proxyAgain)
# /ip4/10.20.30.40/tcp/443
History
0.0.1 (2016-1-22)
First release on PyPI.
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
multiaddr-0.0.1.tar.gz
(19.6 kB
view details)
Built Distribution
File details
Details for the file multiaddr-0.0.1.tar.gz
.
File metadata
- Download URL: multiaddr-0.0.1.tar.gz
- Upload date:
- Size: 19.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5129b99a2a7829d3c66e9ff1e229e32b1255e41d0e4e30b6688bfae65a18ed3f |
|
MD5 | 57a3b2597a66bb46c620b9f50f24f17a |
|
BLAKE2b-256 | 9f35453f4959bc318ea42b7ce08446f56ae74360df1efe25f21b6886d74f3209 |
File details
Details for the file multiaddr-0.0.1-py2.py3-none-any.whl
.
File metadata
- Download URL: multiaddr-0.0.1-py2.py3-none-any.whl
- Upload date:
- Size: 10.3 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e251883dd4a18dc5dd3df135205190113554b6d82ff6a532c18cd274bccad2c2 |
|
MD5 | 10e7f0f90a20d7fd796b765992053102 |
|
BLAKE2b-256 | 20321575617c76d9b2102fe7bdfae2af58574e348453df965898ecb07c1c9f87 |