API reference¶
Everything below is importable from curlify3. Modules and names starting with an underscore, the adapter classes included, are internal.
Functions¶
- curlify3.to_curl(request, shell='sh', pretty=False, long_options=False, include_headers=None, exclude_headers=(), mask_headers=()) str¶
Render a request object as a
curlcommand.Accepts the synchronous client-side request types —
requests.PreparedRequest,niquests.PreparedRequest,httpx.Request,httpx2.Request,urllib.request.Request,tornado.httpclient.HTTPRequest— and the server-side requests whose body the framework has already buffered:django.http.HttpRequest,werkzeug.wrappers.Request/flask.Request,tornado.httputil.HTTPServerRequest. See Supported request objects.:param request: the request object to render. :param shell: the output dialect,
SH(POSIX shells, the default) orPOWERSHELL(Windows PowerShell 5.1). See Windows PowerShell. :type shell: str :param pretty: put every option on its own line. :type pretty: bool :param long_options: spell the options out,--headerinstead of-H. :type long_options: bool :param include_headers: render only the named headers;Nonerenders all of them. :type include_headers: ~collections.abc.Iterable[str] | None :param exclude_headers: leave the named headers out, afterinclude_headers. :type exclude_headers: ~collections.abc.Iterable[str] :param mask_headers: keep the named headers but print***in place of their values, after the filters. See Filtering and masking headers. :type mask_headers: ~collections.abc.Iterable[str] :returns: the command. :rtype: str :raises UnsupportedRequestError: no adapter accepts the request. :raises ValueError: see Errors. :raises TypeError: a header option is astrrather than an iterable of names, or holds a name that is not astr.
- async curlify3.to_curl_async(request, shell='sh', pretty=False, long_options=False, include_headers=None, exclude_headers=(), mask_headers=()) str¶
Render a request object as a
curlcommand, awaiting the body.Accepts the request types whose body has to be awaited —
aiohttp.web.Request,aiohttp.ClientRequest,starlette.requests.Request(FastAPI) — andhttpx.Request/httpx2.Request, whose body may be an async stream. The parameters, the result and the errors are those ofto_curl().
Constants¶
Exceptions¶
- exception curlify3.UnsupportedRequestError¶
Bases:
TypeError,ValueErrorRaised by
to_curl()andto_curl_async()when no adapter accepts the request object. The message starts withunknown request object, names the type that was passed, and says when the other entrypoint accepts it:unknown request object: starlette.requests.Request, it is accepted by to_curl_async(), use that instead
An unsupported type is a type error, hence the
TypeErrorbase. TheValueErrorbase keepsexcept ValueErrorworking, which is what releases before 0.15 raised.
Errors¶
Both functions raise ValueError when:
shellis not one ofSHandPOWERSHELL;pretty=Trueis combined withshell="powershell";with
shell="powershell", the body or a multipart field value is not valid UTF-8, or any value contains a line break;the body or a multipart field value contains a NUL byte.
They raise TypeError when include_headers, exclude_headers or mask_headers is a str rather than an iterable of names, or holds a name that is not a str, and UnsupportedRequestError when no adapter accepts the request object.
A body that cannot be read without consuming it — a stream, a drained form — is not an error: the command carries the rest of the request and no -d.