Skip to main content

Multiaddr

https://img.shields.io/pypi/v/multiaddr.svg https://travis-ci.org/sbuss/py-multiaddr.svg?branch=master https://codecov.io/github/sbuss/py-multiaddr/coverage.svg?branch=master Documentation Status

Python implementation of jbenet’s multiaddr

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.2 (2016-5-4)

  • Fix a bug in decapsulate that threw an IndexError instead of a copy of the Multiaddr when the original multiaddr does not contain the multiaddr to decapsulate. [via fredthomsen #9]

  • Increase test coverage [via fredthomsen #9]

0.0.1 (2016-1-22)

  • First release on PyPI.

Metadata

Release files for py-multiaddr 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-multiaddr 0.0.3
File Size Uploaded
py-multiaddr-0.0.3.tar.gz 21.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for py-multiaddr 0.0.3
File Interpreter ABI Platform
py_multiaddr-0.0.3-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 31.4 kB

Release files / py-multiaddr-0.0.3.tar.gz

Download URL py-multiaddr-0.0.3.tar.gz
Size 21.4 kB
Tags Source
SHA-256 checksum
How to use checksums
89ed9f6556a9e7b114f76f801a8742ece35dc0ebbbdadb3b477e1495239c03ed
BLAKE2b-256 checksum
How to use checksums
f01f9dc7bb9fc5ffb0bb379291c8fd75249e69c67d549aab96ae065e378cd416
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

Release files / py_multiaddr-0.0.3-py2.py3-none-any.whl

Download URL py_multiaddr-0.0.3-py2.py3-none-any.whl
Size 10.0 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
dd1a9b957876e60e10b820ecc61f29ef298801af22098514e2cb321431c9bc10
BLAKE2b-256 checksum
How to use checksums
1f285aa4acb5a4258fb1b1c2d1de6015848a04ed44819246ea70f0260382017a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page