API Reference¶
The following section documents every class and function in the baguette module.
Application¶
-
class
baguette.Baguette(*, config=None, debug=False, default_headers=None, static_url_path='static', static_directory='static', templates_directory='static', error_response_type='plain', error_include_description=True, middlewares=[])[source]¶ Implements an ASGI application.
This class is the main class for any application written with the baguette framework.
- Keyword Arguments
config (
Config) – Config to use for the application. This replaces the other keyword arguments exceptmiddlewares. Default: seeConfigdefaults.debug (
bool) – Whether to run the application in debug mode. Default:False.default_headers (
listof(str, str)tuples,dictorHeaders) – Default headers to include in every response. Default: No headers.static_url_path (
str) – URL path for the static file handler. Default:"static".static_directory (
str) – Path to the folder containing static files. Default:"static".templates_directory (
str) – Path to the folder containing the HTML templates. Default:"templates".error_response_type (
str) – Type of response to use in case of error. One of:"plain","json","html". Default:"plain".error_include_description (
bool) – Whether to include the error description in the response in case of error. If debug isTrue, this will also beTrue. Default:True.middlewares (
listof middleware classes) – The middlewares to add to the application. Default:[].
-
error_response_type¶ Type of response to use in case of error. One of:
"plain","json","html"- Type
-
error_include_description¶ Whether the error description is included in the response in case of error. If debug is
True, this will also beTrue.- Type
-
async
startup()[source]¶ Runs on application startup.
This will be executed when you start the application. For example, you can connect to a database.
New in version 0.1.0.
-
async
shutdown()[source]¶ Runs on application shutdown.
This will be executed when you stop the application. For example, you can disconnect from a database.
New in version 0.1.0.
-
async
dispatch(request)[source]¶ Dispatches a request to the correct handler and return its result.
- Parameters
request (
Request) – The request to handle.- Returns
The handler response.
- Return type
Changed in version 0.3.0: The return value isn’t the handler return value anymore, but instead a
Response.- Return type
Response
-
add_route(path, handler, methods=None, name=None, defaults=None)[source]¶ Adds a route to the application router.
- Parameters
path (
str) – The path that the handler will handle. Can be dynamic, see Dynamic Routing.handler (Async callable) – An asynchronous callable (function or class) that can handle a request.
methods (
listofstr) – Allowed methods for this path. Default:["GET", "HEAD"].name (
str) – Name of the route. Default: handler function name.defaults (Optional
dict) – Default arguments to give to your handler. Default:{}.
- Returns
The created route.
- Return type
- Return type
-
route(path, methods=None, name=None, defaults=None)[source]¶ Decorator to add a handler function to the router with the given path.
- Parameters
path (
str) – The path that the handler will handle. Can be dynamic, see Dynamic Routing.methods (Optional
listofstr) – Allowed methods for this path. Default:["GET", "HEAD"].name (Optional
str) – Name of the route. Default: handler function name.defaults (Optional
dict) – Default arguments to give to your handler. Default:{}.
Changed in version 0.0.3: Renamed from
Baguette.endpointtoBaguette.route()
-
build_middlewares(middlewares=[])[source]¶ Builds the middleware stack from a list of middleware classes.
Note
The first middleware in the list will be the first called on a request.
See also
There are middlewares included by default. See Default middlewares.
- Parameters
middlewares (
listofMiddleware) – The middlewares to add.
New in version 0.3.0.
-
add_middleware(middleware, index=1)[source]¶ Adds a middleware to the middleware stack.
- Parameters
middleware (
Middleware) – The middleware to add.index (Optional
int) – The index to add the middlware to. Default:1(second middleware, called afterErrorMiddleware)
New in version 0.3.0.
-
remove_middleware(middleware)[source]¶ Removes a middleware from the middleware stack.
- Parameters
middleware (
Middleware) – The middleware to remove.
New in version 0.3.0.
-
middleware(index=1)[source]¶ Decorator to add a middleware to the app.
- Parameters
index (Optional
int) – The index to add the middlware to. Default:1(second middleware, called afterErrorMiddleware)
New in version 0.3.0.
-
async
handle_websocket(websocket)[source]¶ Handles a webhook.
- Parameters
webhook (
Webhook) – The webhook to handle.
-
async
route_websocket(scope)[source]¶ Returns the correct route for the websocket.
- Parameters
scope (ASGI scope) – The ASGI scope of the websocket connection.
- Returns
The websocket route.
- Return type
- Raises
NotFound – The websocket route.
- Return type
-
add_websocket_route(path, websocket, name=None)[source]¶ Adds a websocket route to the application websocket router.
- Parameters
- Returns
The created route.
- Return type
- Return type
-
run(*, host='127.0.0.1', port=8000, uds=None, fd=None, debug=None, headers=None, loop='auto', http='auto', ws='auto', env_file=None, log_config=None, log_level=None, access_log=True, use_colors=None, workers=None, proxy_headers=True, forwarded_allow_ips=None, root_path='', limit_concurrency=None, limit_max_requests=None, backlog=2048, timeout_keep_alive=5, timeout_notify=30, callback_notify=None, ssl_keyfile=None, ssl_certfile=None, ssl_keyfile_password=None, ssl_version=None, ssl_cert_reqs=<VerifyMode.CERT_NONE: 0>, ssl_ca_certs=None, ssl_ciphers='TLSv1')[source]¶ Runs the server with uvicorn.
Warning
You need
uvicorninstalled in order to use this. See Installing ASGI server.- Keyword Arguments
host (Optional
str) – Bind socket to this host. IPv6 addresses are supported. Default:127.0.0.1port (Optional
int) – Bind to a socket with this port. Default:8000.uds (Optional
str) – Bind to a UNIX domain socket. Default:None.fd (Optional
int) – Bind to socket from this file descriptor. Default:None.debug (Optional
bool) – Update the app.debug variable while the app is running. Default:None.headers (Optional
listof(str, str)tuples,dictorHeaders) – Add headers to every response while the app is running. Default:None.loop (Optional
"auto","asyncio"or"uvloop") – Event loop implementation. The uvloop implementation provides greater performance, but is not compatible with Windows or PyPy. Default:"auto"http (Optional
"auto","h11"or"httptools") – HTTP protocol implementation. The httptools implementation provides greater performance, but it not compatible with PyPy, and requires compilation on Windows. Default:"auto"ws (Optional
"auto","none","websockets"or"wsproto") – WebSocket protocol implementation. Either of thewebsocketsandwsprotopackages are supported. Use"none"to deny all websocket requests. Default:"auto"env_file (Optional
str(path to file)) – Environment configuration file. Loaded with python-dotenv Default:Nonelog_config (Optional
dictConfig()formats,.jsonand.yamlfile paths orfileConfig()formats.) – Logging configuration. Default: uvicorn.config.LOGGING_CONFIGlog_level (
"critical","error","warning","info","debug"or"trace") – Application log level. Default:"info"access_log (Optional
bool) – Whether to log every request. Default:Trueuse_colors (Optional
bool) – Whether to enable colorized formatting of the log records, in case this is not set it will be auto-detected. This option is ignored iflog_configis given. Default:Noneworkers (Optional
int) – Number of worker processes to use. Default:WEB_CONCURRENCYenvironment variable if available, or1proxy_headers (Optional
bool) – Whether to enableX-Forwarded-Proto,X-Forwarded-ForandX-Forwarded-Portheaders to populate remote address info. Restricted to only trusting connecting IPs in theforwarded_allow_ipsparameter. Default:Trueforwarded_allow_ips (Optional
str) – Comma separated list of IPs to trust with proxy headers. A wildcard"*"means always trust. Default:FORWARDED_ALLOW_IPSenvironment variable if available, or127.0.0.1ssl_keyfile (Optional
str(path to file)) – SSL key file Default:Nonessl_certfile (Optional
str(path to file)) – SSL certificate file Default:Nonessl_keyfile_password (Optional
str) – Password to decrypt the ssl key Default:Nonessl_version (Optional
int) – SSL version to use. Seesslmodule. Default:ssl.PROTOCOL_TLSssl_cert_reqs (Optional
int) – Whether client certificate is required. One ofssl.VerifyModevalues, a constant of thesslmodule that starts withCERT_. Default:ssl.CERT_NONEssl_ca_certs (Optional
str(path to file)) – CA certificates file Default:Nonessl_ciphers (Optional
str) – Ciphers to use. Seesslmodule. Default:"TLSv1"
Note
Doesn’t support reloading, if you want reloading, run the application from the console with uvicorn and add the
--reloadflag.New in version 0.1.2.
Configuration¶
-
class
baguette.Config(*, debug=False, default_headers=None, static_url_path='static', static_directory='static', templates_directory='static', error_response_type='plain', error_include_description=True)[source]¶ Baguette application configuration.
- Keyword Arguments
debug (
bool) – Whether to run the application in debug mode. Default:False.default_headers (
listof(str, str)tuples,dictorHeaders) – Default headers to include in every response. Default: No headers.static_url_path (
str) – URL path for the static file handler. Default:"static".static_directory (
str) – Path to the folder containing static files. Default:"static".templates_directory (
str) – Path to the folder containing the HTML templates. Default:"templates".error_response_type (
str) – Type of response to use in case of error. One of:"plain","json","html". Default:"plain".error_include_description (
bool) – Whether to include the error description in the response in case of error. If debug isTrue, this will also beTrue. Default:True.
-
error_response_type¶ Type of response to use in case of error. One of:
"plain","json","html"- Type
-
error_include_description¶ Whether the error description is included in the response in case of error. If debug is
True, this will also beTrue.- Type
View¶
Request¶
-
class
baguette.Request(app, scope, receive)[source]¶ Request class that is passed to the view functions.
- Parameters
app (ASGI App) – The application that handles the request.
scope (
dict) – ASGI scope of the request. See HTTP scope ASGI specifications.receive (Asynchronous callable) – Awaitable callable that will yield a new event dictionary when one is available. See applications ASGI specifications.
-
path¶ HTTP request target excluding any query string, with percent-encoded sequences and UTF-8 byte sequences decoded into characters.
"/"at the end of the path is striped.- Type
-
querystring¶ URL querystring decoded by
urllib.parse.parse_qs().
-
server¶ Adress and port of the server. The first element can be the path to the UNIX socket running the application, in that case the second element is
None.
-
client¶ Adress and port of the client. The adress can be either IPv4 or IPv6.
-
async
json()[source]¶ Parses the request body to JSON.
- Returns
Parsed body.
- Return type
Anything that can be decoded from JSON
- Raises
BadRequest – If the JSON body is not JSON. You can usually not handle this error as it will be handled by the app and converted to a response with a
400status code.- Return type
Responses¶
Base Response¶
Plain Text Response¶
HTML Response¶
JSON Response¶
-
class
baguette.JSONResponse(data, status_code=200, headers=None)[source]¶ JSON response class.
- Parameters
-
JSON_ENCODER¶ The JSON encoder to use in
json.dumps()with theclskeyword argument. This is a class attribute. Default: the encoder from ujson- Type
JSON encoder
Empty Response¶
Redirect Response¶
-
class
baguette.RedirectResponse(location, body='', status_code=301, headers=None)[source]¶ Redirect response class.
- Parameters
location (
strorbytes) – The location to redirect the request to.status_code (
int) – Status code of the redirect response. Default:301.headers (
listof(str, str)tuples,dictorHeaders) – Headers to include in the response. Any location header will be overwritten with the location parameter. Default:None.
-
property
location¶ The location to redirect the request to.
There’s an alias to create this class, it’s the redirect() function.
-
baguette.redirect(location, status_code=301, headers=None)[source]¶ Redirect the request to location.
- Parameters
location (
strorbytes) – The location to redirect the request to.status_code (
int) – Status code of the redirect response. Default:301.headers (
listof(str, str)tuples,dictorHeaders) – Headers to include in the response. Any location header will be overwritten with the location parameter. Default:None.
- Returns
The created redirect response.
- Return type
- Return type
RedirectResponse
File Response¶
Make Response¶
-
baguette.make_error_response(http_exception, type_='plain', include_description=True, traceback=None)[source]¶ Convert an
HTTPExceptionto aResponse.- Parameters
http_exception (
HTTPException) – The HTTP exception to convert to a response.type (
str) – Type of response. Must be one of: ‘plain’, ‘json’, ‘html’.include_description (
bool) – Whether to include the description in the response.traceback (Optional[
str]) – Error traceback, usually only included in debug mode.
- Raises
ValueError –
type_isn’t one of: ‘plain’, ‘json’, ‘html’.- Returns
Response that describes the error.
- Return type
- Return type
Response
Headers¶
Headers class¶
-
class
baguette.Headers[source]¶ Headers implementation for handling
strorbytesnames and values.Tip
Use
make_headers()to easily make a header from alistor adict.-
keys()[source]¶ Returns an iterator over the headers names.
- Returns
Iterator over the headers names.
- Return type
Iterator of
str
-
Forms¶
Form parsers¶
-
class
baguette.forms.URLEncodedForm(fields=None, files=None)[source]¶
Routing¶
Routers¶
-
class
baguette.router.Router(routes=None)[source]¶ Class for routing a
Requestto the correctRoute.-
add_route(handler, path, methods=None, name=None, defaults=None)[source]¶ Adds a route to the router.
- Parameters
handler (Async callable) – The function/class that handles requests.
path (
str) – The path that the route will be at.methods (
listofstr) – The methods that the route can handle.name (Optional
str) – The name of the route.defaults (Optional
dict) – Default URL parameters to provide to the handler, if none in the URL.
- Returns
The added route.
- Return type
- Return type
-
Routes¶
-
class
baguette.router.Route(path, name, handler, methods, defaults=None)[source]¶ Class for storing info about a route and setting up converters.
- Parameters
path (
str) – The path that the route will be at.name (Optional
str) – The name of the route.handler (Async callable) – The function/class that handles requests.
methods (
listofstr) – The methods that the route can handle.defaults (Optional
dict) – Default URL parameters to provide to the handler, if none in the URL.
-
build_converters()[source]¶ Sets up converters for the route URL parameters.
- Raises
ValueError – The converter type isn’t one of
PARAM_CONVERTERS.
-
convert(path)[source]¶ Converts the URL parameters from the path.
- Parameters
path (
str) – The path that has the parameters.- Returns
The converted parameters.
- Return type
- Raises
ValueError – The path doesn’t match the route regex.
ValueError – Failed a conversion
- Return type
Path parameters converters¶
-
class
baguette.converters.StringConverter(length=None, allow_slash=False)[source]¶ Converter for string URL parameters.
- Parameters
-
REGEX¶ Regex for the route
build_regex().- Type
-
convert(string)[source]¶ Converts the string of the URL parameter and validates the value.
- Parameters
string (
str) – URL parameter to convert.- Returns
Converted URL parameter.
- Return type
- Raises
ValueError –
lengthis specified and the URL parameter has a different length thanlength.ValueError –
allow_slashisFalseand the URL parameter contains slashes.
-
class
baguette.converters.PathConverter(allow_empty=False)[source]¶ Converter for string URL parameters.
- Parameters
allow_empty (Optional
bool) – Whether to allow empty paths. Default:False
-
REGEX¶ Regex for the route
build_regex().- Type
-
convert(string)[source]¶ Converts the string of the URL parameter and validates the value.
- Parameters
string (
str) – URL parameter to convert.- Returns
Converted URL parameter.
- Return type
- Raises
ValueError –
allow_emptyisTrueand the path is empty.
-
class
baguette.converters.IntegerConverter(signed=False, min=None, max=None)[source]¶ Converter for integer URL parameters.
- Parameters
-
REGEX¶ Regex for the route
build_regex().- Type
-
convert(string)[source]¶ Converts the string of the URL parameter and validates the value.
- Parameters
string (
str) – URL parameter to convert.- Returns
Converted URL parameter.
- Return type
- Raises
ValueError –
signedisFalseand the URL parameter starts with+or-.ValueError – Couldn’t convert the URL parameter to an integer.
ValueError –
minis specified and the URL parameter is lower thenmin.ValueError –
maxis specified and the URL parameter is higher thenmax.
-
class
baguette.converters.FloatConverter(signed=False, min=None, max=None, allow_infinity=False, allow_nan=False)[source]¶ Converter for float URL parameters.
- Parameters
signed (Optional
bool) – Whether to accept floats starting with+or-. Default:Falsemin (Optional
float) – Minimum value of the float. Default:Nonemax (Optional
float) – Maximum value of the float. Default:Noneallow_infinity (Optional
bool) – Whether to accept floats that areinfor-inf. Default:Falseallow_nan (Optional
bool) – Whether to accept floats that areNaN. Default:False
-
REGEX¶ Regex for the route
build_regex().- Type
-
convert(string)[source]¶ Converts the string of the URL parameter and validates the value.
- Parameters
string (
str) – URL parameter to convert.- Returns
Converted URL parameter.
- Return type
- Raises
ValueError –
signedisFalseand the URL parameter starts with+or-.ValueError – Couldn’t convert the URL parameter to an float.
ValueError –
minis specified and the URL parameter is lower thenmin.ValueError –
maxis specified and the URL parameter is higher thenmax.ValueError –
allow_infinityisFalseand the URL parameter isinfor-inf.ValueError –
allow_nanisFalseand the URL parameter isnan.
HTTP Exceptions¶
Exceptions for HTTP status code over 400 (4xx client errors and 5xx server errors) from the http module.
Status code |
Name |
Exception class |
Description |
RFC Link |
|---|---|---|---|---|
400 |
Bad Request |
Bad request syntax or unsupported method. |
||
401 |
Unauthorized |
No permission – see authorization schemes. |
||
402 |
Payment Required |
No payment – see charging schemes. |
||
403 |
Forbidden |
Request forbidden – authorization will not help. |
||
404 |
Not Found |
Nothing matches the given URI. |
||
405 |
Method Not Allowed |
Specified method is invalid for this resource. |
||
406 |
Not Acceptable |
URI not available in preferred format. |
||
407 |
Proxy Authentication Required |
You must authenticate with this proxy before proceeding. |
||
408 |
Request Timeout |
Request timed out; try again later. |
||
409 |
Conflict |
Request conflict. |
||
410 |
Gone |
URI no longer exists and has been permanently removed. |
||
411 |
Length Required |
Client must specify Content-Length header. |
||
412 |
Precondition Failed |
Precondition in headers is false. |
||
413 |
Request Entity Too Large |
Entity is too large. |
||
414 |
Request-URI Too Long |
URI is too long. |
||
415 |
Unsupported Media Type |
Entity body in unsupported format. |
||
416 |
Requested Range Not Satisfiable |
Cannot satisfy request range. |
||
417 |
Expectation Failed |
Expect condition could not be satisfied. |
||
418 |
I’m a Teapot |
Server refuses to brew coffee because it is a teapot (1998 April Fools’). |
||
421 |
Misdirected Request |
Server is not able to produce a response. |
||
422 |
Unprocessable Entity |
Server understands the content but was unable to process the contained instructions.. |
||
423 |
Locked |
Source or destination resource of a method is locked. |
||
424 |
Failed Dependency |
Request method could not be performed on the resource because the requested action depended on another action that failed. |
||
425 |
Too Early |
Server is unwilling to risk processing a request that might be replayed. |
||
426 |
Upgrade Required |
Server refuses to perform the request using the current protocol but might be willing to do so after the client upgrades to a different protocol. |
||
428 |
Precondition Required |
Origin server requires the request to be conditional. |
||
429 |
Too Many Requests |
User has sent too many requests in a given amount of time (“rate limiting”). |
||
431 |
Request Header Fields Too Large |
Server is unwilling to process the request because its header fields are too large. |
||
451 |
Unavailable For Legal Reasons |
Server is denying access to the resource as a consequence of a legal demand. |
||
500 |
Internal Server Error |
Server got itself in trouble. |
||
501 |
Not Implemented |
Server does not support this operation. |
||
502 |
Bad Gateway |
Invalid responses from another server/proxy. |
||
503 |
Service Unavailable |
Server cannot process the request due to a high load. |
||
504 |
Gateway Timeout |
Gateway server did not receive a timely response. |
||
505 |
HTTP Version Not Supported |
Cannot fulfill request. |
||
506 |
Variant Also Negotiates |
Server configuration error in which the chosen variant is itself configured to engage in content negotiation, so is not a proper negotiation endpoint. |
||
507 |
Insufficient Storage |
Method could not be performed on the resource because the server is unable to store the representation needed to successfully complete the request. |
||
508 |
Loop Detected |
Server terminated an operation because it encountered an infinite loop while processing a request. |
||
510 |
Not Extended |
Server terminated an operation because it encountered an infinite loop while processing a request. |
||
511 |
Network Authentication Required |
Client needs to authenticate to gain network access. |
-
exception
baguette.httpexceptions.HTTPException(status_code, name=None, description=None)[source]¶ Base class for HTTP exceptions.
-
exception
baguette.httpexceptions.RequestedRangeNotSatisfiable(name=None, description=None)[source]¶
Websocket¶
-
class
baguette.Websocket(app, scope, receive, send)[source]¶ Base websocket class.
You usually only need to overwrite the
on_connect(),on_message(),on_disconnect()andon_close()when subclassing.-
async
connect()[source]¶ Connects to the websocket.
Warning
This method must be called before
handle_messages().- Returns
Whether the websocket is connected.
- Return type
- Raises
RuntimeError – Websocket is already connected
- Return type
-
async
accept(headers=None, subprotocol=None)[source]¶ Accepts the websocket connection.
If you want to accept with your own headers or subprotocol, call this in
on_connect(). If you don’t, it will be called inconnect()ifon_connect()doesn’t error.
-
async
receive()[source]¶ Receives a message from the websocket.
Note
You don’t need to call this method in
on_message().
-
async
close(code=1000, reason='')[source]¶ Closes the websocket connection.
- Parameters
- Raises
RuntimeError – The connection is already closed.
-
async
handle_messages()[source]¶ Handles the received messages, calls
on_message()and puts them in queue.- Raises
RuntimeError – The websocket isn’t connected.
-
async
on_connect()[source]¶ Called on websocket connection.
If this function raises an exception, the websocket connection wont be accepted.
-
async
on_message(message)[source]¶ Called on every websocket message.
- Parameters
message (
str) – The websocket message
-
async
on_disconnect(code)[source]¶ Called on websocket disconnection.
If the server closed the connection, this is called before
on_close().- Parameters
code (
int) – The websocket close status code.
-
async
Middlewares¶
Base middleware¶
-
class
baguette.Middleware(next_middleware, config)[source]¶ Base class for middlewares.
- Parameters
next_middleware (
Middleware) – The next middleware to call.config (
Config) – The application configuration.
-
next_middleware¶ The next middleware to call.
- Type
-
nexte¶ The next middleware to call. (Alias for
next_middleware)- Type
Included middlewares¶
-
class
baguette.middlewares.DefaultHeadersMiddleware(next_middleware, config)[source]¶ Middleware to add the
app.config.default_headersto every response.
-
class
baguette.middlewares.ErrorMiddleware(next_middleware, config)[source]¶ Middleware to handle errors in request handling. Can be
HTTPExceptionor other exceptions.If
app.config.debugand the HTTP status code is higher than 500, then the error traceback is included.
Testing¶
-
class
baguette.TestClient(app, default_headers=None)[source]¶ Test client for a
Baguetteapplication.This class works like a
requests.Session.- Parameters
-
default_headers¶ Default headers included in every request.
-
async
request(method, path, *, params=None, body=None, json=None, headers=None)[source]¶ Creates and sends a request to
app.- Parameters
- Keyword Arguments
- Return type
Response
-
async
get(path, *, params=None, body=None, json=None, headers=None)[source]¶ Sends a GET request to
app.- Parameters
path (
str) – The path of the request.- Keyword Arguments
- Return type
Response
-
async
head(path, *, params=None, body=None, json=None, headers=None)[source]¶ Sends a HEAD request to
app.- Parameters
path (
str) – The path of the request.- Keyword Arguments
- Return type
Response
-
async
post(path, *, params=None, body=None, json=None, headers=None)[source]¶ Sends a POST request to
app.- Parameters
path (
str) – The path of the request.- Keyword Arguments
- Return type
Response
-
async
put(path, *, params=None, body=None, json=None, headers=None)[source]¶ Sends a PUT request to
app.- Parameters
path (
str) – The path of the request.- Keyword Arguments
- Return type
Response
-
async
delete(path, *, params=None, body=None, json=None, headers=None)[source]¶ Sends a DELETE request to
app.- Parameters
path (
str) – The path of the request.- Keyword Arguments
- Return type
Response
-
async
connect(path, *, params=None, body=None, json=None, headers=None)[source]¶ Sends a CONNECT request to
app.- Parameters
path (
str) – The path of the request.- Keyword Arguments
- Return type
Response
-
async
options(path, *, params=None, body=None, json=None, headers=None)[source]¶ Sends a OPTIONS request to
app.- Parameters
path (
str) – The path of the request.- Keyword Arguments
- Return type
Response
-
async
trace(path, *, params=None, body=None, json=None, headers=None)[source]¶ Sends a TRACE request to
app.- Parameters
path (
str) – The path of the request.- Keyword Arguments
- Return type
Response
-
async
patch(path, *, params=None, body=None, json=None, headers=None)[source]¶ Sends a PATCH request to
app.- Parameters
path (
str) – The path of the request.- Keyword Arguments
- Return type
Response
Utils¶
-
baguette.utils.get_encoding_from_content_type(content_type)[source]¶ Returns encodings from given Content-Type Header.
-
baguette.utils.get_encoding_from_headers(headers)[source]¶ Returns encodings from given HTTP Headers.
-
baguette.utils.file_path_to_path(*paths)[source]¶ Convert a list of paths into a pathlib.Path.
- Return type
-
baguette.utils.safe_join(directory, *paths)[source]¶ Safely join the paths to the known directory to return a full path.
-
baguette.utils.address_to_str(address)[source]¶ Converts a
(host, port)tuple into ahost:portstring.- Return type
-
baguette.utils.to_bytes(str_or_bytes, encoding='utf-8')[source]¶ Makes sure that the argument is a
bytes.