Skip to main content

Tools extracts constant elements from url (for example version)

Project description

It’s is tiny package that provides one function split. Function takes two arguments: url and pattern, then attempts to parse the url according to the pattern. Returning result is new object that contains all matched variables + reminding part of the url. Package for most part uses standard urllib.parse with a bits added on top of it.

## Example usage:

>>> import url2vapi
>>> print(url2vapi.split('').as_dict())
{'domain': '', 'port': None, 'protocol': 'http', 'remainder': ''}
>>> print(url2vapi.split('').as_dict())
{'domain': '', 'port': None, 'protocol': 'http', 'remainder': 'dd/ff/'}
>>> print(url2vapi.split('').as_dict())
{'domain': '', 'port': None, 'protocol': 'http', 'remainder': '3.0/dd/ff/'}
>>> print(url2vapi.split('', pattern='<version:number>').as_dict())
{'domain': '', 'port': None, 'protocol': 'http', 'remainder': 'dd/ff/', 'version': {'prefix': '', 'suffix': '', 'value': 3}}
>>> print(url2vapi.split('', pattern='<version:double>').as_dict())
{'domain': '', 'port': None, 'protocol': 'http', 'remainder': 'dd/ff/', 'version': {'prefix': '', 'suffix': '', 'value': 3.0}}
>>> print(url2vapi.split('', pattern='<version:double>/<namespace>').as_dict())
{'port': None, 'namespace': {'prefix': '', 'suffix': '', 'value': 'letters'}, 'version': {'prefix': '', 'suffix': '', 'value': 3.0}, 'domain': '', 'protocol': 'http', 'remainder': 'c/'}

# or something more exotic:

>>> print(url2vapi.split(
{'port': None, 'version': {'prefix': 'v', 'suffix': '-b1', 'value': (3.0, 1.1, 0.1)}, 'domain': '', 'protocol': 'http', 'remainder': 'a/', 'namespace_number': {'prefix': '', 'suffix': '', 'value': 3}}

## Available patterns

Pattern is a string that should contain groups, each group is defined as follows:



  • optional_prefix - is any alphanumeric range of characters, defaults to ‘’ (with addition of some common characters like _-.,)
  • name_of_the_group - is mandatory alphanumeric range of one or more characters (underscores are available)
  • optional_type can be one of the following: number, double, string, bool or tuple, defaults to string
  • if type is set to tuple, we can specify delimiter (ie. characters .,|_-)
  • tuple can specify subtype in a form tuple[double] or tuple[bool] but not tuple[tuple]
  • optional_suffix - is any alphanumeric range of characters, defaults to ‘’ (with addition of some common characters like _-.,)

## Testing

Git clone repository, pip install dependency and then run nosetests by simply ./bin/ (this will open browser with coverage result)


python test

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 url2vapi, version 1.0
Filename, size File type Python version Upload date Hashes
Filename, size url2vapi-1.0.tar.gz (4.5 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page