api

This module implements the Requests API.

copyright:
  1. 2012 by Kenneth Reitz.
license:

Apache2, see LICENSE for more details.

Module Contents

Functions

request(method,url,**kwargs) Constructs and sends a Request.
get(url,params=None,**kwargs) Sends a GET request.
options(url,**kwargs) Sends a OPTIONS request.
head(url,**kwargs) Sends a HEAD request.
post(url,data=None,json=None,**kwargs) Sends a POST request.
put(url,data=None,**kwargs) Sends a PUT request.
patch(url,data=None,**kwargs) Sends a PATCH request.
delete(url,**kwargs) Sends a DELETE request.
request(method, url, **kwargs)

Constructs and sends a Request.

Parameters:
  • method – method for the new Request object.
  • url – URL for the new Request object.
  • params – (optional) Dictionary or bytes to be sent in the query string for the Request.
  • data – (optional) Dictionary, bytes, or file-like object to send in the body of the Request.
  • json – (optional) json data to send in the body of the Request.
  • headers – (optional) Dictionary of HTTP Headers to send with the Request.
  • cookies – (optional) Dict or CookieJar object to send with the Request.
  • files – (optional) Dictionary of 'name': file-like-objects (or {'name': file-tuple}) for multipart encoding upload. file-tuple can be a 2-tuple ('filename', fileobj), 3-tuple ('filename', fileobj, 'content_type') or a 4-tuple ('filename', fileobj, 'content_type', custom_headers), where 'content-type' is a string defining the content type of the given file and custom_headers a dict-like object containing additional headers to add for the file.
  • auth – (optional) Auth tuple to enable Basic/Digest/Custom HTTP Auth.
  • timeout (float or tuple) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) tuple.
  • allow_redirects (bool) – (optional) Boolean. Set to True if POST/PUT/DELETE redirect following is allowed.
  • proxies – (optional) Dictionary mapping protocol to the URL of the proxy.
  • verify – (optional) whether the SSL cert will be verified. A CA_BUNDLE path can also be provided. Defaults to True.
  • stream – (optional) if False, the response content will be immediately downloaded.
  • cert – (optional) if String, path to ssl client cert file (.pem). If Tuple, (‘cert’, ‘key’) pair.
Returns:

Response object

Return type:

requests.Response

Usage:

>>> import requests
>>> req = requests.request('GET', 'http://httpbin.org/get')
<Response [200]>
get(url, params=None, **kwargs)

Sends a GET request.

Parameters:
  • url – URL for the new Request object.
  • params – (optional) Dictionary or bytes to be sent in the query string for the Request.
  • **kwargs – Optional arguments that request takes.
Returns:

Response object

Return type:

requests.Response

options(url, **kwargs)

Sends a OPTIONS request.

Parameters:
  • url – URL for the new Request object.
  • **kwargs – Optional arguments that request takes.
Returns:

Response object

Return type:

requests.Response

head(url, **kwargs)

Sends a HEAD request.

Parameters:
  • url – URL for the new Request object.
  • **kwargs – Optional arguments that request takes.
Returns:

Response object

Return type:

requests.Response

post(url, data=None, json=None, **kwargs)

Sends a POST request.

Parameters:
  • url – URL for the new Request object.
  • data – (optional) Dictionary, bytes, or file-like object to send in the body of the Request.
  • json – (optional) json data to send in the body of the Request.
  • **kwargs – Optional arguments that request takes.
Returns:

Response object

Return type:

requests.Response

put(url, data=None, **kwargs)

Sends a PUT request.

Parameters:
  • url – URL for the new Request object.
  • data – (optional) Dictionary, bytes, or file-like object to send in the body of the Request.
  • **kwargs – Optional arguments that request takes.
Returns:

Response object

Return type:

requests.Response

patch(url, data=None, **kwargs)

Sends a PATCH request.

Parameters:
  • url – URL for the new Request object.
  • data – (optional) Dictionary, bytes, or file-like object to send in the body of the Request.
  • **kwargs – Optional arguments that request takes.
Returns:

Response object

Return type:

requests.Response

delete(url, **kwargs)

Sends a DELETE request.

Parameters:
  • url – URL for the new Request object.
  • **kwargs – Optional arguments that request takes.
Returns:

Response object

Return type:

requests.Response