pyshorteners.shorteners package¶
Submodules¶
pyshorteners.shorteners.adfly module¶
-
class
pyshorteners.shorteners.adfly.
Shortener
(**kwargs)¶ Bases:
pyshorteners.base.BaseShortener
Adf.ly implementation.
- Parameters
api_key (str) – adf.ly API key.
user_id (str) – adf.ly user id.
domain (str, optional) –
Domain used upon shortening, options are:
ad.fly
(default)q.gs
custom.com
0
(Random domain)
type (int, optional) –
For advertising on the shortened link, options are:
1
,int
,interstitial
- Interstitial advertising2
- No advertising3
,banner
- Framed Banner
group_id (int, optional) – API parameter group_id.
Example
>>> import pyshorteners >>> s = pyshorteners.Shortener(api_key='YOUR_KEY', user_id='USER_ID', domain='test.us', group_id=12, type='int') >>> s.adfly.short('http://www.google.com') 'http://test.us/TEST'
-
api_url
= 'http://api.adf.ly/v1'¶
-
expand
(url)¶ Expand implementation for Adf.ly.
- Parameters
url (str) – The URL you want to expand.
- Returns
The expanded URL.
- Return type
str
- Raises
BadAPIResponseException – If the data is malformed or we got a bad status code on API response.
ExpandingErrorException – If the API Returns an error as response.
-
short
(url)¶ Short implementation for Adf.ly.
- Parameters
url (str) – The URL you want to shorten.
- Returns
The shortened URL.
- Return type
str
- Raises
BadAPIResponseException – If the data is malformed or we got a bad status code on API response.
ShorteningErrorException – If the API Returns an error as response.
pyshorteners.shorteners.bitly module¶
-
class
pyshorteners.shorteners.bitly.
Shortener
(**kwargs)¶ Bases:
pyshorteners.base.BaseShortener
Bit.ly shortener Implementation
- Parameters
api_key (str) – bit.ly API key
Example
>>> import pyshorteners >>> s = pyshorteners.Shortener(api_key='YOUR_KEY') >>> s.bitly.short('http://www.google.com') 'http://bit.ly/TEST' >>> s.bitly.expand('https://bit.ly/TEST') 'http://www.google.com' >>> s.bitly.total_clicks('https://bit.ly/TEST') 10
-
api_url
= 'https://api-ssl.bit.ly/v4'¶
-
expand
(url)¶ Expand implementation for Bit.ly :param url: The URL you want to expand. :type url: str
- Returns
The expanded URL.
- Return type
str
- Raises
ExpandingErrorException – If the API Returns an error as response.
BadAPIResponseException – If the API response can’t be decoded.
-
short
(url)¶ Short implementation for Bit.ly :param url: the URL you want to shorten :type url: str
- Returns
The shortened URL.
- Return type
str
- Raises
BadAPIResponseException – If the data is malformed or we got a bad status code on API response.
ShorteningErrorException – If the API Returns an error as response
-
total_clicks
(url)¶ Total clicks implementation for Bit.ly :param url: the URL you want to get the total clicks count :type url: str
- Returns
The total clicks count
- Return type
int
- Raises
BadAPIResponseException – If the API Returns an error as response
pyshorteners.shorteners.chilpit module¶
-
class
pyshorteners.shorteners.chilpit.
Shortener
(**kwargs)¶ Bases:
pyshorteners.base.BaseShortener
Chilp.it shortener implementation
Example
>>> import pyshorteners >>> s = pyshorteners.Shortener() >>> s.chilpit.short('http://www.google.com') 'http://chilp.it/TEST' >>> s.chilpit.expand('http://chilp.it/TEST') 'http://www.google.com'
-
api_url
= 'http://chilp.it/api.php'¶
-
short
(url)¶ Short implementation for Chilp.it
- Parameters
url – the URL you want to shorten
- Returns
A string containing the shortened URL
- Raises
ShorteningErrorException – If the API returns an error as response
-
pyshorteners.shorteners.clckru module¶
-
class
pyshorteners.shorteners.clckru.
Shortener
(**kwargs)¶ Bases:
pyshorteners.base.BaseShortener
Clck.ru shortener implementation
Example
>>> import pyshorteners >>> s = pyshorteners.Shortener() >>> s.clckru.short('http://www.google.com') 'http://clck.ru/TEST' >>> s.clckru.expand('http://clck.ru/TEST') 'http://www.google.com'
-
api_url
= 'https://clck.ru/--'¶
-
short
(url)¶ Short implementation for Clck.ru
- Parameters
url – the URL you want to shorten
- Returns
A string containing the shortened URL
- Raises
ShorteningErrorException – If the API returns an error as response
-
pyshorteners.shorteners.cuttly module¶
-
class
pyshorteners.shorteners.cuttly.
Shortener
(**kwargs)¶ Bases:
pyshorteners.base.BaseShortener
Cutt.ly shortener implementation
- Parameters
api_key (str) – cutt.ly API key
Example
>>> import pyshorteners >>> s = pyshorteners.Shortener(api_key='YOUR_KEY') >>> s.cuttly.short('http://www.google.com') 'http://cutt.ly/TEST' >>> s.cuttly.expand('https://cutt.ly/TEST') 'http://www.google.com'
-
STATUS_INVALID
= 4¶
-
api_url
= 'https://cutt.ly/api/api.php'¶
-
short
(url)¶ Short implementation for Cutt.ly :param url: the URL you want to shorten :type url: str
- Returns
The shortened URL.
- Return type
str
- Raises
BadAPIResponseException – If the data is malformed or we got a bad status code on API response.
ShorteningErrorException – If the API Returns an error as response
pyshorteners.shorteners.dagd module¶
-
class
pyshorteners.shorteners.dagd.
Shortener
(**kwargs)¶ Bases:
pyshorteners.base.BaseShortener
Da.gd shortener implementation
Example
>>> import pyshorteners >>> s = pyshorteners.Shortener() >>> s.dagd.short('http://www.google.com') 'http://da.gd/TEST' >>> s.dagd.expand('http://da.gd/TEST') 'http://www.google.com'
-
api_url
= 'https://da.gd/'¶
-
expand
(url)¶ Expand implementation for Da.gd :param url: The URL you want to expand. :type url: str
- Returns
The expanded URL.
- Return type
str
- Raises
ExpandingErrorException – If the API Returns an error as response.
-
short
(url)¶ Short implementation for Da.gd :param url: the URL you want to shorten :type url: str
- Returns
The shortened URL.
- Return type
str
- Raises
ShorteningErrorException – If the API Returns an error as response
-
pyshorteners.shorteners.gitio module¶
-
class
pyshorteners.shorteners.gitio.
Shortener
(**kwargs)¶ Bases:
pyshorteners.base.BaseShortener
Git.io shortener Implementation
Example
>>> import pyshorteners >>> s = pyshorteners.Shortener(code='12345') >>> s.gitio.short('https://github.com/TEST') 'https://git.io/12345' >>> s.gitio.expand('https://git.io/12345') 'https://github.com/TEST'
-
api_url
= 'https://git.io'¶
-
short
(url)¶ Short implementation for Git.io Only works for github urls
- Parameters
url (str) – the URL you want to shorten
code (str) – (Optional) Custom permalink code: Eg.: test
- Returns
The shortened URL
- Return type
str
- Raises
ShorteningErrorException – If the API returns an error as response
-
pyshorteners.shorteners.isgd module¶
-
class
pyshorteners.shorteners.isgd.
Shortener
(**kwargs)¶ Bases:
pyshorteners.base.BaseShortener
Is.gd shortener implementation
Example
>>> import pyshorteners >>> s = pyshorteners.Shortener() >>> s.isgd.short('http://www.google.com') 'http://is.gd/TEST' >>> s.isgd.expand('http://is.gd/TEST') 'http://www.google.com'
-
api_url
= 'https://is.gd/create.php'¶
-
short
(url)¶ Short implementation for Is.gd
- Parameters
url – the URL you want to shorten
- Returns
A string containing the shortened URL
- Raises
ShorteningErrorException – If the API returns an error as response
-
pyshorteners.shorteners.nullpointer module¶
-
class
pyshorteners.shorteners.nullpointer.
Shortener
(**kwargs)¶ Bases:
pyshorteners.base.BaseShortener
The Null Pointer implementation
- Parameters
domain (str) –
Optional string for the null pointer instance to use. Default is ‘https://0x0.st’. Any URL to a Null Pointer instance is supported, for example:
https://0x0.st
https://ttm.sh
Example
>>> import pyshorteners >>> s = pyshorteners.Shortener(domain='https://0x0.st') >>> s.nullpointer.short('https://www.google.com') 'https://0x0.st/jU'
-
short
(url)¶ Short implementation for The Null Pointer :param url: the URL you want to shorten :type url: str
- Returns
The shortened URL
- Return type
str
- Raises
ShorteningErrorException – If the data is malformed or we got a bad
status code on API response –
pyshorteners.shorteners.osdb module¶
-
class
pyshorteners.shorteners.osdb.
OHTMLParser
¶ Bases:
html.parser.HTMLParser
-
handle_data
(data)¶
-
handle_starttag
(tag, attrs)¶
-
-
class
pyshorteners.shorteners.osdb.
Shortener
(**kwargs)¶ Bases:
pyshorteners.base.BaseShortener
Os.db shortener implementation
Example
>>> import pyshorteners >>> s = pyshorteners.Shortener() >>> s.osdb.short('http://www.google.com') 'https://osdb.link/TEST' >>> s.osdb.expand('http://osdb.link/TEST') 'https://www.google.com'
-
api_url
= 'https://osdb.link/'¶
-
short
(url)¶ Short implementation for Os.db
- Parameters
url – the URL you want to shorten
- Returns
A string containing the shortened URL
- Raises
ShorteningErrorException – If the API returns an error as response
-
pyshorteners.shorteners.owly module¶
-
class
pyshorteners.shorteners.owly.
Shortener
(**kwargs)¶ Bases:
pyshorteners.base.BaseShortener
Ow.ly url shortner api implementation
Example
>>> import pyshorteners >>> s = pyshorteners.Shortener() >>> s.owly.short('http://www.google.com') 'http://ow.ly/TEST' >>> s.owly.expand('http://ow.ly/TEST') 'http://www.google.com'
-
api_url
= 'http://ow.ly/api/1.1/url/'¶
-
expand
(url)¶ Expand implementation for ow.ly.
- Parameters
url (str) – The URL you want to expand.
- Returns
The expanded URL.
- Return type
str
- Raises
BadAPIResponseException – Bad response from the API.
ExpandingErrorException – If the API Returns an error as response.
-
short
(url)¶ Short implementation for ow.ly.
- Parameters
url (str) – The URL you want to shorten.
- Returns
The shortened URL.
- Return type
str
- Raises
BadAPIResponseException – If the api response data could not get parsed.
ShorteningErrorException – If the API Returns an error as response.
-
pyshorteners.shorteners.post module¶
-
class
pyshorteners.shorteners.post.
Shortener
(**kwargs)¶ Bases:
pyshorteners.base.BaseShortener
Po.st Shortener implementation
- Parameters
api_key (str) – adf.ly API key.
Example
>>> import pyshorteners >>> s = pyshorteners.Shortener(api_key='YOUR_KEY') >>> s.post.short('http://www.google.com') 'http://po.st/TEST' >>> s.post.expand('http://po.st/TEST') 'http://www.google.com'
-
api_url
= 'http://po.st/api/shorten'¶
-
short
(url)¶ Short implementation for Po.st.
- Parameters
url (str) – The URL you want to shorten.
- Returns
The shortened URL.
- Return type
str
- Raises
BadAPIResponseException – If the data is malformed or we got a bad status code on API response.
ShorteningErrorException – If the API Returns an error as response.
pyshorteners.shorteners.qpsru module¶
-
class
pyshorteners.shorteners.qpsru.
Shortener
(**kwargs)¶ Bases:
pyshorteners.base.BaseShortener
Qps.ru shortener implementation
Example
>>> import pyshorteners >>> s = pyshorteners.Shortener() >>> s.qpsru.short('http://www.google.com') 'http://qps.ru/TEST' >>> s.qpsru.expand('http://qps.ru/TEST') 'http://www.google.com'
-
api_url
= 'http://qps.ru/api'¶
-
short
(url)¶ Short implementation for Qps.ru
- Parameters
url – the URL you want to shorten
- Returns
A string containing the shortened URL
- Raises
ShorteningErrorException – If the API returns an error as response
-
pyshorteners.shorteners.shortcm module¶
-
class
pyshorteners.shorteners.shortcm.
Shortener
(**kwargs)¶ Bases:
pyshorteners.base.BaseShortener
Short.cm shortener Implementation
- Parameters
api_key (str) – short.cm API key
domain (str) – which registered domain to create the link on
Example
>>> import pyshorteners >>> s = pyshorteners.Shortener(api_key='YOUR_KEY') >>> s.shortcm.short('http://www.google.com') 'http://short.cm/TEST' >>> s.shortcm.expand('https://short.cm/test') 'http://www.google.com' >>> s.shortcm.expand('https://short.cm/test') 10
-
api_key
= ''¶
-
api_url
= 'https://api.short.cm/links/'¶
-
domain
= ''¶
-
expand
(url)¶ Expand implementation for Short.cm :param url: the short URL you want to expand
- Returns
The expanded URL
- Return type
str
- Raises
ExpandingErrorException – If the API Returns an error as response
-
short
(url)¶ Short implementation for Short.cm :param url: the URL you want to shorten :type url: str
- Returns
The shortened URL
- Return type
str
- Raises
BadAPIResponseException – If the data is malformed or we got a bad
status code on API response –
ShorteningErrorException – If the API Returns an error as response
pyshorteners.shorteners.tinycc module¶
-
class
pyshorteners.shorteners.tinycc.
Shortener
(**kwargs)¶ Bases:
pyshorteners.base.BaseShortener
Tiny.cc implementation.
- Parameters
api_key (str) – Tiny.cc API key.
login (str) – Tiny.cc username.
Example
>>> import pyshorteners >>> s = pyshorteners.Shortener(api_key='12345', login='user') >>> s.tinycc.short('http://www.google.com') 'http://tiny.cc/6lbsez'
-
api_url
= 'http://tiny.cc/'¶
-
expand
(url)¶ Expand implementation for Tiny.cc.
- Parameters
url (str) – The URL you want to expand.
- Returns
The expanded URL.
- Return type
str
- Raises
ExpandingErrorException – If the API Returns an error as response.
-
headers
= {'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux) Gecko/20100101 Firefox/61.0'}¶
-
params
= {'c': 'rest_api', 'format': 'json', 'version': '2.0.3'}¶
-
short
(url)¶ Short implementation for Tiny.cc.
- Parameters
url (str) – The URL you want to shorten.
- Returns
The shortened URL.
- Return type
str
- Raises
BadAPIResponseException – If the data is malformed or we got a bad status code on API response.
ShorteningErrorException – If the API Returns an error as response.
-
total_clicks
(url)¶ How many times the shortened URL has been clicked on.
- Parameters
url (str) – The shortened URL to examine.
- Returns
The number of times the shortened URL has been used.
- Return type
int
- Raises
BadAPIResponseException – If the data is malformed or we got a bad status code on API response.
pyshorteners.shorteners.tinyurl module¶
-
class
pyshorteners.shorteners.tinyurl.
Shortener
(**kwargs)¶ Bases:
pyshorteners.base.BaseShortener
TinyURL.com shortener implementation
Example
>>> import pyshorteners >>> s = pyshorteners.Shortener() >>> s.tinyurl.short('http://www.google.com') 'http://tinyurl.com/TEST' >>> s.tinyurl.expand('http://tinyurl.com/test') 'http://www.google.com'
-
api_url
= 'http://tinyurl.com/api-create.php'¶
-
short
(url)¶ Short implementation for TinyURL.com
- Parameters
url – the URL you want to shorten
- Returns
A string containing the shortened URL
- Raises
ShorteningErrorException – If the API returns an error as response
-