Skip to main content

A robust connection URI parser/stringifier - for Python.

Project description

connection-uri Build Status PyPI version

A robust connection URI parser/stringifier - for Python.

Introduction

This connection URI library was implemented in lack of robust Python alternatives. This one supports absolute/relative multi-host connection URIs with smart fallbacks.

Install

Install using pip:

$ pip install connection-uri

Use

Very basic example:

import connection_uri

basic_connection_uri = 'localhost:3000/namespace/foo/'
basic_connection_options = connection_uri.unpack(basic_connection_uri)

print('\nconnection_uri.unpack({0})\n\n{1}\n'.format(basic_connection_uri, basic_connection_options))
#
# {
#     'protocol': 'http',
#     'auth': None,
#
#     'endpoint': 'localhost:3000',
#     'endpoints': ['localhost:3000'],
#
#     'host': 'localhost',
#     'hosts': ['localhost'],
#
#     'port': 3000,
#     'ports': [3000],

#     'path': '/namespace/foo/',
#     'query': {},
#
#     'credentials': {
#         'username': None,
#         'password': None,
#     },
#     'key': 'namespace/foo',
#     'namespace': 'namespace/foo',
#
#     'url': 'http://localhost:3000/namespace/foo/',
#     'urls': [
#         'http://localhost:3000/namespace/foo/'
#     ],
# }
#

basic_connection_uri = connection_uri.pack(basic_connection_options)

print('\nconnection_uri.pack({0})\n\n{1}\n'.format(basic_connection_options, basic_connection_uri))
#
# 'http://localhost:3000/namespace/foo/'
#

print('---')

complex_multihost_uri = 'foo://m+4.gTe~5e^(:m+4.gTe~5e^(@ds143144-a0.mlab.com:43144,ds143144-a1.mlab.com:43145/bar-baz'
complex_multihost_options = connection_uri.unpack(complex_multihost_uri)

print('\nconnection_uri.unpack({0})\n\n{1}\n'.format(complex_multihost_uri, complex_multihost_options))
#
# {
#     'protocol': 'foo',
#     'auth': 'm+4.gTe~5e^(:m+4.gTe~5e^(',
#
#     'host': 'ds143144-a0.mlab.com',
#     'port': 43144,
#
#     'endpoint': 'ds143144-a0.mlab.com:43144',
#     'endpoints': ['ds143144-a0.mlab.com:43144', 'ds143144-a1.mlab.com:43145'],
#
#     'host': 'ds143144-a0.mlab.com',
#     'hosts': ['ds143144-a0.mlab.com', 'ds143144-a1.mlab.com'],
#
#     'port': 43144,
#     'ports': [43144, 43145],
#
#     'path': '/bar-baz',
#     'query': {},
#
#     'credentials': {
#         'username': 'm+4.gTe~5e^(',
#         'password': 'm+4.gTe~5e^(',
#     },
#     'key': 'bar-baz',
#     'namespace': 'bar-baz',
#
#     'url': 'foo://m+4.gTe~5e^(:m+4.gTe~5e^(@ds143144-a0.mlab.com:43144,ds143144-a1.mlab.com:43145/bar-baz',
#     'urls': [
#         'foo://m+4.gTe~5e^(:m+4.gTe~5e^(@ds143144-a0.mlab.com:43144/bar-baz',
#         'foo://m+4.gTe~5e^(:m+4.gTe~5e^(@ds143144-a1.mlab.com:43145/bar-baz'
#     ],
# }
#

complex_multihost_uri = connection_uri.pack(complex_multihost_options)

print('\nconnection_uri.pack({0})\n\n{1}\n'.format(complex_multihost_options, complex_multihost_uri))
#
# 'foo://m+4.gTe~5e^(:m+4.gTe~5e^(@ds143144-a0.mlab.com:43144,ds143144-a1.mlab.com:43145/bar-baz'
#

# NOTE: see tests for more advanced examples, e.g. the library handles absolute and relative URIs, etc.

Test

Clone down source code:

$ make install

Run colorful tests, with only native environment (dependency sandboxing up to you):

$ make test

Run less colorful tests, with multi-environment (using tox):

$ make test-tox

About

This project was mainly initiated - in lack of solid existing alternatives - to be used at our work at Markable.ai to have common code conventions between various programming environments where Python (research, CV, AI) is heavily used.

License

Released under the MIT license.

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

connection_uri-0.1.0.tar.gz (15.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

connection_uri-0.1.0-py2-none-any.whl (16.0 kB view details)

Uploaded Python 2

File details

Details for the file connection_uri-0.1.0.tar.gz.

File metadata

  • Download URL: connection_uri-0.1.0.tar.gz
  • Upload date:
  • Size: 15.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.7.3 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/2.7.13

File hashes

Hashes for connection_uri-0.1.0.tar.gz
Algorithm Hash digest
SHA256 68a1cbd7c0753504977456c2ce1a92327166e3ccac69d855f32ca4606119e5fa
MD5 2679b4e387fd12c5a368bf0721844752
BLAKE2b-256 6ec8a05fae94d2ae11d341e4ae0a6b6db5d070b180f7efbae6ceefcae8591619

See more details on using hashes here.

File details

Details for the file connection_uri-0.1.0-py2-none-any.whl.

File metadata

  • Download URL: connection_uri-0.1.0-py2-none-any.whl
  • Upload date:
  • Size: 16.0 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.7.3 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/2.7.13

File hashes

Hashes for connection_uri-0.1.0-py2-none-any.whl
Algorithm Hash digest
SHA256 97e47eb7f3ac166e16fcb9ac6b8fa74f21514d44ac3d7fca275d4c05e1acd70f
MD5 dbbfb2e3f08961c3677c52501533b9c3
BLAKE2b-256 641cb2b541950abf48cd5fa5cba95306a42268138fbdf0dbfefc9ca332229dbe

See more details on using hashes here.

Supported by

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