Skip to main content

Simple Resource Address Parser.

Project description

Python module to parse simple network resource addresses, like the ones used in many database systems to represent a database URI.

res_address will be used by Mongotail to parse the address passed through command line (migration in progress), but can be used by any other Python application that needs to parse a MongoDB database address, or any other network resource like [[HOST OR IP][:PORT]/]RESOURCE.


>>> from res_address import get_res_address
>>> host, port, resource = get_res_address("localhost:27017/test")
>>> print(host, port, resource)
localhost 27017 test
>>> host, port, resource = get_res_address("my_db")
>>> print(host, port, resource)
None None my_db
>>> ipv6, port, resource = get_res_address("[::1]:9999/foo")
>>> print(ipv6, port, resource)
[::1] 9999 foo

The address can be:


foo resource on local machine (IPv4 connection)

foo resource on machine


foo resource on remotehost machine

foo resource on machine on port 9999


foo resource on ::1 machine on port 9999 (IPv6 connection)


foo resource on port 1234

Some validations over the host, port and resource strings are performed, and an exception is launched if some of the checks fails, but take into account that invalid range IPs or incompatible resource names may pass.:

>>> host, port, resource = get_res_address("localhost:INVALIDport/test")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "res_address/", line 74, in get_res_address
    raise InvalidPortError('Invalid port number "%s"' % port, address, port)
res_address.InvalidPortError: Invalid port number "INVALIDport"

All the validation exceptions inherit from AddressError:

  • InvalidHostError

  • InvalidPortError

  • InvalidResourceError

  • NotResourceProvidedError

Run the test

Just execute (Python 2 or 3):

$ python test


$ python -m unittest -v tests



Authors: (2018-2019) Mariano Ruiz <>

License: LGPL-3

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

res-address-1.0.0b2.tar.gz (17.4 kB view hashes)

Uploaded source

Built Distribution

res_address-1.0.0b2-py3.6.egg (5.6 kB view hashes)

Uploaded 3 6

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