Skip to main content

connection-uri PyPI version Build Status Coverage Status

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.

Metadata

Release files for connection-uri 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for connection-uri 0.1.1
File Size Uploaded
connection_uri-0.1.1.tar.gz 16.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for connection-uri 0.1.1
File Interpreter ABI Platform
connection_uri-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 32.2 kB

Release files / connection_uri-0.1.1.tar.gz

Download URL connection_uri-0.1.1.tar.gz
Size 16.1 kB
Tags Source
SHA-256 checksum
How to use checksums
49788ef903b29276d400b5911d8b2a8cc9b2eb78b6fd67443b4f7bf0de131b91
BLAKE2b-256 checksum
How to use checksums
e9aca1e0b957e7096e7b0ea685b503af30ee978f908e29105f8543cab30c44a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.4.2 requests/2.20.1 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.5

Release files / connection_uri-0.1.1-py3-none-any.whl

Download URL connection_uri-0.1.1-py3-none-any.whl
Size 16.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
36b099b7aa2b3c831ef867bbd1d08f12247dd72aa8f6a22560c5f5d05937a257
BLAKE2b-256 checksum
How to use checksums
dd5f55b839cb2cf28c7e4401ad80ee7c9aa5c0bb3d9a114f1ff0b3329ee31774
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.4.2 requests/2.20.1 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.5

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page