Trackbacks

This library includes support for Trackback URL Discovery and sending Trackbacks.

Trackback URL discovery

The IndieWeb Utils Trackback discovery performs the following steps:

  1. Checks for a trackback:ping attribute in an RDF comment. If one is found, this is returned.

  2. Checks for an EditURI <link> tag. If one is found, its contents are retrieved. If the contents contain a trackback:ping attribute, this is returned.

indieweb_utils.discover_trackback_url(url: str) str[source]

Discover the trackback URL from a URL.

Parameters:

url – The URL to discover the trackback URL from.

Returns:

The trackback URL.

Example:

from indieweb_utils import discover_trackback_url

discover_trackback_url('http://example.com/post/123')

Send a Trackback

The send_trackback function sends a Trackback to a given URL. Discovery is performed on the target_url to find its Trackback endpoint, to which a Trackback is sent.

indieweb_utils.send_trackback(target_url, source_url, title: str | None = None, excerpt: str | None = None, blog_name: str | None = None) None[source]

Send a trackback to a URL.

Parameters:
  • target_url – The URL to send the trackback to.

  • source_url – The URL of your post.

  • title – The title of your post.

  • excerpt – An excerpt of your post.

  • blog_name – The name of your blog.

Returns:

The status code and message from the server.

Raises:
  • ConnectionError – Raised when a connection error occurs.

  • InvalidStatusCodeError – Raised when the server returns an invalid status code.

  • TrackbackError – Raised when the server returns an invalid response.

Example:

from indieweb_utils import send_trackback

send_trackback(
    source_url='http://example.com/post/123#trackback',
    target_url='http://example.com/post/123',
    title='My Post',
    excerpt='This is my post',
    blog_name='My Blog'
)

Validate a Trackback

The process_trackback function validates data from a trackback response sent to an endpoint. You can use this function to:

  1. Make sure a request has the required content type and method. If an error is found, a string with an RDF error is returned that can be sent by the server back to the client;

  2. Send an error response if the source site is not in a list of allowed sites (optional) and;

  3. Send a success response if the Trackback is valid.

indieweb_utils.process_trackback(url: str, content_type: str | None = None, method: str | None = None, valid_domains: list | None = None) Tuple[str, bool][source]

Validate and process a trackback request.

Parameters:
  • url – The URL to send the trackback to.

  • content_type – The content type of the request.

  • method – The request method.

  • valid_domains – A list of valid domains to accept trackbacks from.

Returns:

The trackback response and whether the Trackback is valid.

Return type:

List[str, bool]

Example:

from indieweb_utils import process_trackback

process_trackback(
    'http://example.com/post/123',
    content_type='application/x-www-form-urlencoded',
    method='POST'
)