This submodule contains code for fetching/parsing URLs.


exception prance.util.url.ResolutionError[source]

Bases: exceptions.LookupError


prance.util.url.absurl(url, relative_to=None)[source]

Turn relative file URLs into absolute file URLs.

This is necessary, because while JSON pointers do not allow relative file URLs, Swagger/OpenAPI explicitly does. We need to make relative paths absolute before passing them off to jsonschema for verification.

Non-file URLs are left untouched. URLs without scheme are assumed to be file URLs.

  • url (str/tuple) – The input URL.
  • relative_to (str/tuple) – [optional] The URL to which the input URL is relative.

The output URL, parsed into components.

Return type:


prance.util.url.fetch_url(url, cache={})[source]

Fetch the URL and parse the contents.

Same as fetch_url_text(), but also parses the content and only returns the parse results.

  • url (tuple) – The url, parsed as returned by absurl above.
  • cache (Mapping) – An optional cache. If the URL can be found in the cache, return the cache contents.

The parsed file.

Return type:


prance.util.url.split_url_reference(base_url, reference)[source]

Return a normalized, parsed URL and object path.

The reference string is a JSON reference, i.e. a URL with a fragment that contains an object path into the referenced resource.

The base URL is used as a reference point for relative references.

  • base_url (mixed) – A parsed URL.
  • reference (str) – A JSON reference string.

The parsed absolute URL of the reference and the object path.


Return the resource part of a parsed URL.

The resource part is defined as the part without query, parameters or fragment. Just the scheme, netloc and path remains.

Parameters:url (tuple) – A parsed URL
Returns:The resource part of the URL
Return type:str