URI Submodule

class rfc3986.uri.URIReference

Immutable object representing a parsed URI Reference.


This class is not intended to be directly instantiated by the user.

This object exposes attributes for the following components of a URI:

  • scheme
  • authority
  • path
  • query
  • fragment

The scheme that was parsed for the URI Reference. For example, http, https, smtp, imap, etc.


Component of the URI that contains the user information, host, and port sub-components. For example, google.com,, username@[::1], username:password@example.com:443, etc.


The path that was parsed for the given URI Reference. For example, /, /index.php, etc.


The query component for a given URI Reference. For example, a=b, a=b%20c, a=b+c, a=b,c=d,e=%20f, etc.


The fragment component of a URI. For example, section-3.1.

This class also provides extra attributes for easier access to information like the subcomponents of the authority component.


The user information parsed from the authority.


The hostname, IPv4, or IPv6 adddres parsed from the authority.


The port parsed from the authority.

classmethod URIReference.from_string(uri_string, encoding='utf-8')

Parse a URI reference from the given unicode URI string.

  • uri_string (str) – Unicode URI to be parsed into a reference.
  • encoding (str) – The encoding of the string provided

URIReference or subclass thereof


Create a URI string from the components.

Returns:The URI Reference reconstituted as a string.
Return type:str
URIReference.resolve_with(base_uri, strict=False)

Use an absolute URI Reference to resolve this relative reference.

Assuming this is a relative reference that you would like to resolve, use the provided base URI to resolve it.

See http://tools.ietf.org/html/rfc3986#section-5 for more information.

Parameters:base_uri – Either a string or URIReference. It must be an absolute URI or it will raise an exception.
Returns:A new URIReference which is the result of resolving this reference using base_uri.
Return type:URIReference
Raises:rfc3986.exceptions.ResolutionError – If the base_uri is not an absolute URI.
URIReference.copy_with(scheme=<object object>, authority=<object object>, path=<object object>, query=<object object>, fragment=<object object>)

Create a copy of this reference with the new components.

  • scheme (str) – (optional) The scheme to use for the new reference.
  • authority (str) – (optional) The authority to use for the new reference.
  • path (str) – (optional) The path to use for the new reference.
  • query (str) – (optional) The query to use for the new reference.
  • fragment (str) – (optional) The fragment to use for the new reference.

New URIReference with provided components.

Return type:



Normalize this reference as described in Section 6.2.2.

This is not an in-place normalization. Instead this creates a new URIReference.

Returns:A new reference object with normalized components.
Return type:URIReference

Determine if this URI Reference is an absolute URI.

See http://tools.ietf.org/html/rfc3986#section-4.3 for explanation.

Returns:True if it is an absolute URI, False otherwise.
Return type:bool

Return a dictionary with the userinfo, host, and port.

If the authority is not valid, it will raise a InvalidAuthority Exception.

Returns:{'userinfo': 'username:password', 'host': 'www.example.com', 'port': '80'}
Return type:dict
Raises:rfc3986.exceptions.InvalidAuthority – If the authority is not None and can not be parsed.