Skip to main content

Python implementation of jbenet's multiaddr

Project description

py-multiaddr
############

.. image:: https://img.shields.io/pypi/v/multiaddr.svg
:target: https://pypi-hypernode.com/pypi/multiaddr

.. image:: https://travis-ci.org/multiformats/py-multiaddr.svg?branch=master
:target: https://travis-ci.org/multiformats/py-multiaddr

.. image:: https://codecov.io/github/multiformats/py-multiaddr/coverage.svg?branch=master
:target: https://codecov.io/github/multiformats/py-multiaddr?branch=master

.. image:: https://readthedocs.org/projects/multiaddr/badge/?version=latest
:target: https://readthedocs.org/projects/multiaddr/?badge=latest
:alt: Documentation Status
..

multiaddr_ implementation in Python 🐍

.. _multiaddr: https://github.com/multiformats/multiaddr

..


.. contents:: :local:

Usage
=====

Simple
------

.. code-block:: python

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
---------

.. code-block:: python

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
--------------

.. code-block:: python

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.


.. code-block:: python

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:

- `MIT`_ © 2014 Steven Buss
- `Apache 2`_ © 2014 Steven Buss

.. _the issues: https://github.com/multiformats/py-multiaddr/issues
.. _contributing document: https://github.com/multiformats/multiformats/blob/master/contributing.md
.. _Code of Conduct: https://github.com/ipfs/community/blob/master/code-of-conduct.md
.. _standard-readme: https://github.com/RichardLitt/standard-readme
.. _MIT: LICENSE-MIT
.. _Apache 2: LICENSE-APACHE2


=======
History
=======

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`_]

.. _fredthomsen: https://github.com/fredthomsen
.. _`#9`: https://github.com/multiformats/py-multiaddr/pull/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.5.tar.gz (22.3 kB view details)

Uploaded Source

Built Distribution

multiaddr-0.0.5-py2.py3-none-any.whl (13.5 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: multiaddr-0.0.5.tar.gz
  • Upload date:
  • Size: 22.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.20.1 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.1

File hashes

Hashes for multiaddr-0.0.5.tar.gz
Algorithm Hash digest
SHA256 8a6811d6b238858880884774ff3902e4cc2517459ca9c7cafd0d45d0b25af308
MD5 321291c79361e0964558e1b0289c0898
BLAKE2b-256 f2c1b5b7ea1b470f4c12892851f7715e6b122955a3edc4da4537402bdd7cdbb6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: multiaddr-0.0.5-py2.py3-none-any.whl
  • Upload date:
  • Size: 13.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.20.1 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.1

File hashes

Hashes for multiaddr-0.0.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 acffe4d8001160547549c1898ee37417274a8e8becc2cf9837a1e4f8dbc70328
MD5 91d9e505bcbdeed9ad734c81754252ab
BLAKE2b-256 7567ffd1040d721cfcdd57fee4e1d794915fdfcca5e1b73ff62316179148c839

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