pyshorteners package

class pyshorteners.Shortener(**kwargs)

Bases: object

Base Factory class to create shoreteners instances

>>> s = Shortener(**kwargs)
>>> instance = s.shortener_name
>>> instance.short('http://www.google.com')
'http://short.url/'

Available Shorteners can be seen with:

>>> s = Shortener()
>>> print(s.available_shorteners)

Submodules

pyshorteners.base module

class pyshorteners.base.BaseShortener(**kwargs)

Bases: object

Base Class for all shorteners.

Keyword Arguments
  • proxies (dict, optional) – Web proxy configuration for Requests Proxies.

  • timeout (int, optional) – Seconds before request is killed.

  • verify (bool, str, optional) – SSL Certificate verification for Requests Verification.

Example

>>> class NewShortener(BaseShortener):
...     api_url = 'http://the/link/for/the/api'
...     def short(self, url):
...         pass
...     def expand(self, url):
...         pass
...     def custom_method(self):
...         pass
static clean_url(url)

URL validation.

Parameters

url (str) – URL to shorten.

Raises

BadURLException – URL is not valid.

expand(url)

Expand URL using a shortening service.

Only visits the link, and returns the response url.

Parameters

url (str) – URL to shorten.

Raises

ExpandingErrorException – URL failed to expand.

short(url)

Shorten URL using a shortening service.

Parameters

url (str) – URL to shorten.

Raises

NotImplementedError – Subclass must override.

pyshorteners.exceptions module

exception pyshorteners.exceptions.BadAPIResponseException(message)

Bases: Exception

exception pyshorteners.exceptions.BadURLException(message)

Bases: Exception

exception pyshorteners.exceptions.ExpandingErrorException(message=None)

Bases: Exception

exception pyshorteners.exceptions.ShorteningErrorException(message=None)

Bases: Exception