Core¶
Note
The contents of this module are placed here for organisational reasons.
They should be imported from yourls.
-
class
yourls.core.YOURLSAPIMixin¶ Bases:
objectMixin to provide default YOURLS API methods.
-
db_stats()¶ Get database statistics.
Returns: Total clicks and links statistics. Return type: DBStats Raises: requests.exceptions.HTTPError– Generic HTTP Error
-
expand(short)¶ Expand short URL or keyword to long URL.
Parameters: short – Short URL (
http://example.com/abc) or keyword (abc).Returns: Expanded/long URL, e.g.
https://www.youtube.com/watch?v=dQw4w9WgXcQRaises: YOURLSHTTPError– HTTP error with response from YOURLS API.requests.exceptions.HTTPError– Generic HTTP error.
-
shorten(url, keyword=None, title=None)¶ Shorten URL with optional keyword and title.
Parameters: - url – URL to shorten.
- keyword – Optionally choose keyword for short URL, otherwise automatic.
- title – Optionally choose title, otherwise taken from web page.
Returns: Shortened URL and associated data.
Return type: Raises: YOURLSKeywordExistsError– The passed keyword already exists.Note
This exception has a
keywordattribute.YOURLSURLExistsError– The URL has already been shortened.Note
This exception has a
urlattribute, which is an instance ofShortenedURLfor the existing short URL.YOURLSNoURLError– URL missing.YOURLSNoLoopError– Cannot shorten a shortened URL.YOURLSAPIError– Unhandled API error.YOURLSHTTPError– HTTP error with response from YOURLS API.requests.exceptions.HTTPError– Generic HTTP error.
-
stats(filter, limit, start=None)¶ Get stats about links.
Parameters: - filter – ‘top’, ‘bottom’, ‘rand’, or ‘last’.
- limit – Number of links to return from filter.
- start – Optional start number.
Returns: Tuple containing list of ShortenedURLs and DBStats.
Example
links, stats = yourls.stats(filter='top', limit=10)
Raises: ValueError– Incorrect value for filter parameter.requests.exceptions.HTTPError– Generic HTTP Error
-
url_stats(short)¶ Get stats for short URL or keyword.
Parameters: short – Short URL (http://example.com/abc) or keyword (abc).
Returns: Shortened URL and associated data.
Return type: Raises: YOURLSHTTPError– HTTP error with response from YOURLS API.requests.exceptions.HTTPError– Generic HTTP error.
-
-
class
yourls.core.YOURLSClient(apiurl, username=None, password=None, signature=None)¶ Bases:
yourls.core.YOURLSAPIMixin,yourls.core.YOURLSClientBaseYOURLS client.
-
class
yourls.core.YOURLSClientBase(apiurl, username=None, password=None, signature=None)¶ Bases:
objectBase class for YOURLS client that provides initialiser and api request method.
Inheritance diagram¶