pyodide.http#
Classes:
|
A wrapper for a Javascript fetch |
Functions:
|
Fetches a given URL synchronously. |
async |
Fetch the url and return the response. |
- class pyodide.http.FetchResponse(url, js_response)#
A wrapper for a Javascript fetch
Response
.- Parameters
url (
str
) – URL to fetchjs_response (
JsFetchResponse
) – AJsProxy
of the fetch response
- body_used: bool#
Has the response been used yet?
If so, attempting to retrieve the body again will raise an
OSError
. Useclone()
first to avoid this. SeeResponse.bodyUsed
.
- async buffer()#
Return the response body as a Javascript
ArrayBuffer
.- Return type
- clone()#
Return an identical copy of the
FetchResponse
.This method exists to allow multiple uses of
FetchResponse
objects. SeeResponse.clone()
.- Return type
- async json(**kwargs)#
Treat the response body as a JSON string and use
json.loads()
to parse it into a Python object.Any keyword arguments are passed to
json.loads()
.
- async memoryview()#
Return the response body as a
memoryview
object- Return type
- ok: bool#
Was the request successful?
See
Response.ok
.
- redirected: bool#
Was the request redirected?
See
Response.redirected
.
- status: int#
Response status code
See
Response.status
.
- status_text: str#
Response status text
See
Response.statusText
.
- type: str#
The type of the response.
See
Response.type
.
- async unpack_archive(*, extract_dir=None, format=None)#
Treat the data as an archive and unpack it into target directory.
Assumes that the file is an archive in a format that
shutil
has an unpacker for. The argumentsextract_dir
andformat
are passed directly on toshutil.unpack_archive
.- Parameters
extract_dir (
Optional
[str
]) – Directory to extract the archive into. If not provided, the current working directory is used.format (
Optional
[str
]) – The archive format: one of"zip"
,"tar"
,"gztar"
,"bztar"
. Or any other format registered withshutil.register_unpack_format()
. If not provided,unpack_archive()
will use the archive file name extension and see if an unpacker was registered for that extension. In case none is found, aValueError
is raised.
- Return type
- url: str#
The url of the response.
The value may be different than the url passed to fetch. See
Response.url
.
- pyodide.http.open_url(url)#
Fetches a given URL synchronously.
The download of binary files is not supported. To download binary files use
pyodide.http.pyfetch()
which is asynchronous.
- async pyodide.http.pyfetch(url, **kwargs)#
Fetch the url and return the response.
This functions provides a similar API to
fetch()
however it is designed to be convenient to use from Python. TheFetchResponse
has methods with the output types already converted to Python objects.- Parameters
url (
str
) – URL to fetch.**kwargs (
Any
) – keyword arguments are passed along as optional parameters to the fetch API.
- Return type