apeye.requests_url

Extension of URL with support for interacting with the website using the Requests library.

New in version 0.2.0.

Classes:

RequestsURL(​[url])

Extension of URL with support for interacting with the website using the Requests library.

TrailingRequestsURL(​[url])

Extension of RequestsURL which adds a trailing slash to the end of the URL.

Data:

class RequestsURL(url='')[source]

Bases: URL

Extension of URL with support for interacting with the website using the Requests library.

The requests.Session used for this object – and all objects created using the / or .parent operations – can be accessed using the session attribute. If desired, this can be replaced with a different session object, such as one using caching.

Parameters

url (Union[str, URL]) – The url to construct the URL object from. Default ''.

Changed in version 0.3.0: The url parameter can now be a string or a URL.

Changed in version 1.1.0: When a RequestsURL object is deleted or garbage collected, the underlying requests.Session object it only closed if no objects hold references to the session. This prevents the session object of a global object from being inadvertently closed when one of its children is garbage collected.

Methods:

__del__(​)

Attempt to close session when garbage collected to avoid leaving connections open.

delete(​**kwargs)

Send a DELETE request using Requests.

get(​[params])

Perform a GET request using Requests.

head(​**kwargs)

Send a HEAD request using Requests.

options(​**kwargs)

Send an OPTIONS request using Requests.

patch(​[data, json])

Send a PATCH request using Requests.

post(​[data, json])

Send a POST request using Requests.

put(​[data, json])

Send a PUT request using Requests.

resolve(​[timeout])

Resolves the URL into its canonical form.

Attributes:

session

The underlying requests session.

__del__()[source]

Attempt to close session when garbage collected to avoid leaving connections open.

delete(**kwargs)[source]

Send a DELETE request using Requests.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/DELETE

Parameters

**kwargs – Optional arguments that requests.request() takes.

Return type

Response

get(params=None, **kwargs)[source]

Perform a GET request using Requests.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET

Parameters

Changed in version 0.7.0: If params is None but the URL has a query string, the query string will be parsed and used for params.

Return type

Response

head(**kwargs)[source]

Send a HEAD request using Requests.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD

Parameters

**kwargs – Optional arguments that requests.request() takes. If allow_redirects is not provided, it will be set to False (as opposed to the default requests.request() behavior).

Return type

Response

options(**kwargs)[source]

Send an OPTIONS request using Requests.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS

Parameters

**kwargs – Optional arguments that requests.request() takes.

Return type

Response

patch(data=None, json=None, **kwargs)[source]

Send a PATCH request using Requests.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PATCH

Parameters
Return type

Response

post(data=None, json=None, **kwargs)[source]

Send a POST request using Requests.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST

Parameters
Return type

Response

put(data=None, json=None, **kwargs)[source]

Send a PUT request using Requests.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUT

Parameters
Return type

Response

resolve(timeout=None)[source]

Resolves the URL into its canonical form.

This is done by making a HEAD request and following HTTP 302 redirects.

New in version 0.8.0.

Changed in version 1.1.0: Added the timeout argument.

Return type

~_R

session

Type:    Session

The underlying requests session.

class TrailingRequestsURL(url='')[source]

Bases: RequestsURL

Extension of RequestsURL which adds a trailing slash to the end of the URL.

New in version 0.5.0.

Parameters

url (Union[str, URL]) – The url to construct the URL object from. Default ''.

__str__()[source]

Returns the TrailingRequestsURL as a string.

Return type

str

_R = TypeVar(_R, bound=RequestsURL)

Type:    TypeVar

Invariant TypeVar bound to apeye.requests_url.RequestsURL.