Python implementation of jbenet's multiaddr
Project description
py-multiaddr
############
.. image:: https://img.shields.io/pypi/v/multiaddr.svg
:target: https://pypi.python.org/pypi/multiaddr
.. image:: https://travis-ci.org/sbuss/py-multiaddr.svg?branch=master
:target: https://travis-ci.org/sbuss/py-multiaddr
.. image:: https://codecov.io/github/sbuss/py-multiaddr/coverage.svg?branch=master
:target: https://codecov.io/github/sbuss/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/jbenet/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
.. _@sbuss: https://github.com/sbuss
.. _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.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/sbuss/py-multiaddr/pull/9
0.0.1 (2016-1-22)
------------------
* First release on PyPI.
############
.. image:: https://img.shields.io/pypi/v/multiaddr.svg
:target: https://pypi.python.org/pypi/multiaddr
.. image:: https://travis-ci.org/sbuss/py-multiaddr.svg?branch=master
:target: https://travis-ci.org/sbuss/py-multiaddr
.. image:: https://codecov.io/github/sbuss/py-multiaddr/coverage.svg?branch=master
:target: https://codecov.io/github/sbuss/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/jbenet/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
.. _@sbuss: https://github.com/sbuss
.. _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.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/sbuss/py-multiaddr/pull/9
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.3.tar.gz
(21.2 kB
view details)
Built Distribution
File details
Details for the file multiaddr-0.0.3.tar.gz
.
File metadata
- Download URL: multiaddr-0.0.3.tar.gz
- Upload date:
- Size: 21.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca074aa39d93292916ff737d687990380ea58bee898f3eb0ab7dfefeef6f0212 |
|
MD5 | 8c93a75eff6f5e1ca278562d152f279b |
|
BLAKE2b-256 | fb03652c5e2d61bc6a2db5c1d16437e81e524b1a60e2edb3e7f89ad753984a84 |
File details
Details for the file multiaddr-0.0.3-py2.py3-none-any.whl
.
File metadata
- Download URL: multiaddr-0.0.3-py2.py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8139825b94ecf0af059140487792ea02b2ebc69f12ba23880c65fa105fd297f3 |
|
MD5 | 35b41264ff854136f645c66918c77cec |
|
BLAKE2b-256 | 41c09b29d96391617d2e08aec3c7a8025adcf883405536224f46d1cd0cfbb7a2 |