api.rst
This file
Path
docs/api.rst
183 lines · 4.2 KiB
Last changed by
Merge pull request #1298 from Lukasa/adapter_docKenneth Reitzbefore adoption2426eeb
History of this fileTake it
The walk stopped after 200 commits: lines older than 4837900 point at it.
digest works!Kenneth Reitzbefore adoption4837900
lines 1–2why, one step back1.. _api:2developer interfaceKenneth Reitzbefore adoption911e8ae
lines 3–4why, one step back3Developer Interface4===================digest works!Kenneth Reitzbefore adoption4837900
lines 5–28why, one step back56.. module:: requests78This part of the documentation covers all the interfaces of Requests. For9parts where Requests depends on external libraries, we document the most10important right here and provide links to the canonical documentation.111213Main Interface14--------------1516All of Request's functionality can be accessed by these 7 methods.17They all return an instance of the :class:`Response <Response>` object.1819.. autofunction:: request2021.. autofunction:: head22.. autofunction:: get23.. autofunction:: post24.. autofunction:: put25.. autofunction:: patch26.. autofunction:: delete2728docs updateKenneth Reitzbefore adoption3ddcc99
lines 29–30why, one step back29Lower-Level Classes30~~~~~~~~~~~~~~~~~~~digest works!Kenneth Reitzbefore adoption4837900
line 31why, one step back31docs updateKenneth Reitzbefore adoption3ddcc99
lines 32–37why, one step back32.. autoclass:: requests.Request33 :inherited-members:3435.. autoclass:: Response36 :inherited-members:37request sessionsKenneth Reitzbefore adoption9f89ebe
lines 38–39why, one step back38Request Sessions39----------------digest works!Kenneth Reitzbefore adoption4837900
lines 40–43why, one step back4041.. autoclass:: Session42 :inherited-members:43Merge pull request #1298 from Lukasa/adapter_docKenneth Reitzbefore adoption2426eeb
lines 44–45why, one step back44.. autoclass:: requests.adapters.HTTPAdapter45 :inherited-members:digest works!Kenneth Reitzbefore adoption4837900
line 46why, one step back46Merge pull request #1298 from Lukasa/adapter_docKenneth Reitzbefore adoption2426eeb
line 47why, one step back47digest works!Kenneth Reitzbefore adoption4837900
lines 48–99why, one step back48Exceptions49~~~~~~~~~~5051.. module:: requests5253.. autoexception:: RequestException54.. autoexception:: ConnectionError55.. autoexception:: HTTPError56.. autoexception:: URLRequired57.. autoexception:: TooManyRedirects585960Status Code Lookup61~~~~~~~~~~~~~~~~~~6263.. autofunction:: requests.codes6465::6667 >>> requests.codes['temporary_redirect']68 3076970 >>> requests.codes.teapot71 4187273 >>> requests.codes['\o/']74 2007576Cookies77~~~~~~~7879.. autofunction:: dict_from_cookiejar80.. autofunction:: cookiejar_from_dict81.. autofunction:: add_dict_to_cookiejar828384Encodings85~~~~~~~~~8687.. autofunction:: get_encodings_from_content88.. autofunction:: get_encoding_from_headers89.. autofunction:: get_unicode_from_response90.. autofunction:: decode_gzip919293Classes94~~~~~~~9596.. autoclass:: requests.Response97 :inherited-members:9899.. autoclass:: requests.Requestno async anymoreKenneth Reitzbefore adoptionb3fbc81
lines 100–102why, one step back100 :inherited-members:101102.. autoclass:: requests.PreparedRequestdigest works!Kenneth Reitzbefore adoption4837900
lines 103–107why, one step back103 :inherited-members:104105.. _sessionapi:106107.. autoclass:: requests.SessionMerge pull request #1298 from Lukasa/adapter_docKenneth Reitzbefore adoption2426eeb
lines 108–110why, one step back108 :inherited-members:109110.. autoclass:: requests.adapters.HTTPAdapterdigest works!Kenneth Reitzbefore adoption4837900
lines 111–112why, one step back111 :inherited-members:112Merge pull request #1231 from davidfischer/docs-migration1.0Kenneth Reitzbefore adoption08cab48
lines 113–183why, one step back113114Migrating to 1.x115----------------116117This section details the main differences between 0.x and 1.x and is meant118to ease the pain of upgrading.119120121API Changes122~~~~~~~~~~~123124* ``Response.json`` is now a callable and not a property of a response.125126 ::127128 import requests129 r = requests.get('https://github.com/timeline.json')130 r.json() # This *call* raises an exception if JSON decoding fails131132* The ``Session`` API has changed. Sessions objects no longer take parameters.133 ``Session`` is also now capitalized, but it can still be134 instantiated with a lowercase ``session`` for backwards compatibility.135136 ::137138 s = requests.Session() # formerly, session took parameters139 s.auth = auth140 s.headers.update(headers)141 r = s.get('http://httpbin.org/headers')142143* All request hooks have been removed except 'response'.144145* Authentication helpers have been broken out into separate modules. See146 requests-oauthlib_ and requests-kerberos_.147148.. _requests-oauthlib: https://github.com/requests/requests-oauthlib149.. _requests-kerberos: https://github.com/requests/requests-kerberos150151* The parameter for streaming requests was changed from ``prefetch`` to152 ``stream`` and the logic was inverted. In addition, ``stream`` is now153 required for raw response reading.154155 ::156157 # in 0.x, passing prefetch=False would accomplish the same thing158 r = requests.get('https://github.com/timeline.json', stream=True)159 r.raw.read(10)160161* The ``config`` parameter to the requests method has been removed. Some of162 these options are now configured on a ``Session`` such as keep-alive and163 maximum number of redirects. The verbosity option should be handled by164 configuring logging.165166 ::167168 # Verbosity should now be configured with logging169 my_config = {'verbose': sys.stderr}170 requests.get('http://httpbin.org/headers', config=my_config) # bad!171172173Licensing174~~~~~~~~~175176One key difference that has nothing to do with the API is a change in the177license from the ISC_ license to the `Apache 2.0`_ license. The Apache 2.0178license ensures that contributions to requests are also covered by the Apache1792.0 license.180181.. _ISC: http://opensource.org/licenses/ISC182.. _Apache 2.0: http://opensource.org/licenses/Apache-2.0183