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 foo resource on local machine (IPv4 connection) foo resource on machine
remotehost/foo foo resource on remotehost machine foo resource on machine on port 9999
“[::1]:9999/foo” foo resource on ::1 machine on port 9999 (IPv6 connection)
:1234/foo 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.

Files for res-address, version 1.0.0b2
Filename, size File type Python version Upload date Hashes
Filename, size res_address-1.0.0b2-py3.6.egg (5.6 kB) File type Egg Python version 3.6 Upload date Hashes View
Filename, size res-address-1.0.0b2.tar.gz (17.4 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page