Core

Note

The contents of this module are placed here for organisational reasons. They should be imported from yourls.

class yourls.core.YOURLSAPIMixin

Bases: object

Mixin 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=dQw4w9WgXcQ

Raises:
  • 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:

ShortenedURL

Raises:
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:

ShortenedURL

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.YOURLSClientBase

YOURLS client.

class yourls.core.YOURLSClientBase(apiurl, username=None, password=None, signature=None)

Bases: object

Base class for YOURLS client that provides initialiser and api request method.

Inheritance diagram

Inheritance diagram of yourls.core