Skip to main content

Python implementation of jbenet's multiaddr

Project description

py-multiaddr

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

multiaddr implementation in Python

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

Maintainers

Original author: @sbuss.

Contribute

Contributions welcome. Please check out the issues.

Check out our contributing document for more information on how we work, and about contributing in general. Please be aware that all interactions related to multiformats are subject to the IPFS Code of Conduct.

License

Dual-licensed:

History

0.0.7 (2019-5-8)

  • include subpackage

  • refactor util and codec

0.0.5 (2019-5-7)

  • unhexilified bytes

  • new exceptions

  • miscellaneous improvements [via alexander255 #42]

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.

Project details


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.9.tar.gz (24.7 kB view details)

Uploaded Source

Built Distribution

multiaddr-0.0.9-py2.py3-none-any.whl (16.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file multiaddr-0.0.9.tar.gz.

File metadata

  • Download URL: multiaddr-0.0.9.tar.gz
  • Upload date:
  • Size: 24.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.8

File hashes

Hashes for multiaddr-0.0.9.tar.gz
Algorithm Hash digest
SHA256 30b2695189edc3d5b90f1c303abb8f02d963a3a4edf2e7178b975eb417ab0ecf
MD5 d5bb4acecd28cba4a52221fe0a7146b9
BLAKE2b-256 12f4fa5353022ad8e0fd364bfa8b474f9562c36ce1305fad31fe52b849e30795

See more details on using hashes here.

File details

Details for the file multiaddr-0.0.9-py2.py3-none-any.whl.

File metadata

  • Download URL: multiaddr-0.0.9-py2.py3-none-any.whl
  • Upload date:
  • Size: 16.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.8

File hashes

Hashes for multiaddr-0.0.9-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5c0f862cbcf19aada2a899f80ef896ddb2e85614e0c8f04dd287c06c69dac95b
MD5 78003181e10fcc4fc03b1e54426e7d54
BLAKE2b-256 5159df732566d951c33f00a4022fc5bf9c5d1661b1c2cdaf56e75a1a5fa8f829

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page