werkzeug
¶
Werkzeug is the Swiss Army knife of Python web development.
It provides useful classes and functions for any WSGI application to make the life of a python web developer much easier. All of the provided classes are independent from each other so you can mix it with any other library.
Functions¶
append_slash_redirect (environ[, code]) |
Redirects to the same URL but with a slash appended. |
bind_arguments (func, args, kwargs) |
Bind the arguments provided into a dict. |
check_password_hash (pwhash, password) |
check a password against a given salted and hashed password value. |
cookie_date ([expires]) |
Formats the time to ensure compatibility with Netscape’s cookie standard. |
create_environ (*args, **kwargs) |
Create a new WSGI environ dict based on the values passed. |
dump_cookie (key[, value, max_age, expires, ...]) |
Creates a new Set-Cookie header without the Set-Cookie prefix The parameters are the same as in the cookie Morsel object in the Python standard library but it accepts unicode data, too. |
dump_header (iterable[, allow_token]) |
Dump an HTTP header again. |
dump_options_header (header, options) |
The reverse function to parse_options_header() . |
escape (s[, quote]) |
Replace special characters “&”, “<”, “>” and (”) to HTML-safe sequences. |
extract_path_info (environ_or_baseurl, ...[, ...]) |
Extracts the path info from the given URL (or WSGI environment) and path. |
find_modules (import_path[, ...]) |
Finds all the modules below a package. |
format_string (string, context) |
String-template format a string: |
generate_etag (data) |
Generate an etag for some data. |
generate_password_hash (password[, method, ...]) |
Hash a password with the given method and salt with with a string of the given length. |
get_current_url (environ[, root_only, ...]) |
A handy helper function that recreates the full URL as IRI for the current request or parts of it. |
get_host (environ[, trusted_hosts]) |
Return the real host for the given WSGI environment. |
http_date ([timestamp]) |
Formats the time to match the RFC1123 date format. |
import_string (import_name[, silent]) |
Imports an object based on a string. |
iri_to_uri (iri[, charset, errors, ...]) |
Converts any unicode based IRI to an acceptable ASCII URI. |
is_entity_header (header) |
Check if a header is an entity header. |
is_hop_by_hop_header (header) |
Check if a header is an HTTP/1.1 “Hop-by-Hop” header. |
is_resource_modified (environ[, etag, data, ...]) |
Convenience method for conditional requests. |
make_line_iter (stream[, limit, buffer_size, ...]) |
Safely iterates line-based over an input stream. |
parse_accept_header (value[, cls]) |
Parses an HTTP Accept-* header. |
parse_authorization_header (value) |
Parse an HTTP basic/digest authorization header transmitted by the web browser. |
parse_cache_control_header (value[, ...]) |
Parse a cache control header. |
parse_cookie (header[, charset, errors, cls]) |
Parse a cookie. |
parse_date (value) |
Parse one of the following date formats into a datetime object: |
parse_dict_header (value[, cls]) |
Parse lists of key, value pairs as described by RFC 2068 Section 2 and |
parse_etags (value) |
Parse an etag header. |
parse_form_data (environ[, stream_factory, ...]) |
Parse the form data in the environ and return it as tuple in the form (stream, form, files) . |
parse_list_header (value) |
Parse lists as described by RFC 2068 Section 2. |
parse_options_header (value[, multiple]) |
Parse a Content-Type like header into a tuple with the content |
parse_set_header (value[, on_update]) |
Parse a set-like header and return a |
parse_www_authenticate_header (value[, on_update]) |
Parse an HTTP WWW-Authenticate header into a WWWAuthenticate object. |
peek_path_info (environ[, charset, errors]) |
Returns the next segment on the PATH_INFO or None if there is none. |
pop_path_info (environ[, charset, errors]) |
Removes and returns the next segment of PATH_INFO, pushing it onto SCRIPT_NAME. |
quote_etag (etag[, weak]) |
Quote an etag. |
quote_header_value (value[, extra_chars, ...]) |
Quote a header value if necessary. |
redirect (location[, code, Response]) |
Returns a response object (a WSGI application) that, if called, redirects the client to the target location. |
release_local (local) |
Releases the contents of the local for the current context. |
remove_entity_headers (headers[, allowed]) |
Remove all entity headers from a list or Headers object. |
remove_hop_by_hop_headers (headers) |
Remove all HTTP/1.1 “Hop-by-Hop” headers from a list or Headers object. |
responder (f) |
Marks a function as responder. |
run_simple (hostname, port, application[, ...]) |
Start a WSGI application. |
run_wsgi_app (app, environ[, buffered]) |
Return a tuple in the form (app_iter, status, headers) of the application output. |
secure_filename (filename) |
Pass it a filename and it will return a secure version of it. |
test_app (environ, start_response) |
Simple test application that dumps the environment. |
unescape (s) |
The reverse function of escape. |
unquote_etag (etag) |
Unquote a single etag: |
unquote_header_value (value[, is_filename]) |
Unquotes a header value. |
uri_to_iri (uri[, charset, errors]) |
Converts a URI in a given charset to a IRI. |
url_decode (s[, charset, decode_keys, ...]) |
Parse a querystring and return it as MultiDict . |
url_encode (obj[, charset, encode_keys, ...]) |
URL encode a dict/MultiDict. |
url_fix (s[, charset]) |
Sometimes you get an URL by a user that just isn’t a real URL because it contains unsafe characters like ‘ ‘ and so on. |
url_quote (string[, charset, errors, safe, ...]) |
URL encode a single string with a given encoding. |
url_quote_plus (string[, charset, errors, safe]) |
URL encode a single string with the given encoding and convert whitespace to “+”. |
url_unquote (string[, charset, errors, unsafe]) |
URL decode a single string with a given encoding. |
url_unquote_plus (s[, charset, errors]) |
URL decode a single string with the given charset and decode “+” to whitespace. |
validate_arguments (func, args, kwargs[, ...]) |
Checks if the function accepts the arguments and keyword arguments. |
wrap_file (environ, file[, buffer_size]) |
Wraps a file. |
Classes¶
Aborter ([mapping, extra]) |
When passed a dict of code -> exception items it can be used as callable that raises exceptions. |
Accept ([values]) |
An Accept object is just a list subclass for lists of (value, quality) tuples. |
AcceptMixin |
A mixin for classes with an environ attribute to get all the HTTP accept headers as Accept objects (or subclasses thereof). |
Authorization (auth_type[, data]) |
Represents an Authorization header sent by the client. |
AuthorizationMixin |
Adds an authorization property that represents the parsed value of the Authorization header as Authorization object. |
BaseRequest (environ[, populate_request, shallow]) |
Very basic request object. |
BaseResponse ([response, status, headers, ...]) |
Base response class. |
CallbackDict ([initial, on_update]) |
A dict that calls a function passed every time something is changed. |
CharsetAccept ([values]) |
Like Accept but with normalization for charsets. |
Client (application[, response_wrapper, ...]) |
This class allows to send requests to a wrapped application. |
ClosingIterator (iterable[, callbacks]) |
The WSGI specification requires that all middlewares and gateways respect the close callback of an iterator. |
CombinedMultiDict ([dicts]) |
A read only MultiDict that you can pass multiple MultiDict |
CommonRequestDescriptorsMixin |
A mixin for BaseRequest subclasses. |
CommonResponseDescriptorsMixin |
A mixin for BaseResponse subclasses. |
DebuggedApplication (app[, evalex, ...]) |
Enables debugging support for a given application: |
DispatcherMiddleware (app[, mounts]) |
Allows one to mount middlewares or applications in a WSGI application. |
ETagRequestMixin |
Add entity tag and cache descriptors to a request object or object with a WSGI environment available as environ . |
ETagResponseMixin |
Adds extra functionality to a response object for etag and cache handling. |
ETags ([strong_etags, weak_etags, star_tag]) |
A set that can be used to check if one etag is present in a collection of etags. |
EnvironBuilder ([path, base_url, ...]) |
This class can be used to conveniently create a WSGI environment for testing purposes. |
EnvironHeaders (environ) |
Read only version of the headers from a WSGI environment. |
FileMultiDict ([mapping]) |
A special MultiDict that has convenience methods to add files to it. |
FileStorage ([stream, filename, name, ...]) |
The FileStorage class is a thin wrapper over incoming files. |
FileWrapper (file[, buffer_size]) |
This class can be used to convert a file -like object into an iterable. |
HTMLBuilder (dialect) |
Helper object for HTML generation. |
HeaderSet ([headers, on_update]) |
Similar to the ETags class this implements a set-like structure. |
Headers ([defaults]) |
An object that stores some headers. |
Href ([base, charset, sort, key]) |
Implements a callable that constructs URLs with the given base. |
ImmutableDict |
An immutable dict . |
ImmutableList |
An immutable list . |
ImmutableMultiDict ([mapping]) |
An immutable MultiDict . |
ImmutableOrderedMultiDict ([mapping]) |
An immutable OrderedMultiDict . |
ImmutableTypeConversionDict |
Works like a TypeConversionDict but does not support modifications. |
LanguageAccept ([values]) |
Like Accept but with normalization for languages. |
LimitedStream (stream, limit) |
Wraps a stream so that it doesn’t read more than n bytes. |
Local () |
|
LocalManager ([locals, ident_func]) |
Local objects cannot manage themselves. |
LocalProxy (local[, name]) |
Acts as a proxy for a werkzeug local. |
LocalStack () |
This class works similar to a Local but keeps a stack of objects instead. |
MIMEAccept ([values]) |
Like Accept but with special methods and behavior for mimetypes. |
MultiDict ([mapping]) |
A MultiDict is a dictionary subclass customized to deal with multiple values for the same key which is for example used by the parsing functions in the wrappers. |
OrderedMultiDict ([mapping]) |
Works like a regular MultiDict but preserves the order of the fields. |
Request (environ[, populate_request, shallow]) |
Full featured request object implementing the following mixins: |
RequestCacheControl ([values, on_update]) |
A cache control for requests. |
Response ([response, status, headers, ...]) |
Full featured response object implementing the following mixins: |
ResponseCacheControl ([values, on_update]) |
A cache control for responses. |
ResponseStreamMixin |
Mixin for BaseRequest subclasses. |
SharedDataMiddleware (app, exports[, ...]) |
A WSGI middleware that provides static content for development environments or simple server setups. |
TypeConversionDict |
Works like a regular dict but the get() method can perform type conversions. |
UserAgent (environ_or_string) |
Represents a user agent. |
UserAgentMixin |
Adds a user_agent attribute to the request object which contains the parsed user agent of the browser that triggered the request as a UserAgent object. |
WWWAuthenticate ([auth_type, values, on_update]) |
Provides simple access to WWW-Authenticate headers. |
WWWAuthenticateMixin |
Adds a www_authenticate property to a response object. |
cached_property (func[, name, doc]) |
A decorator that converts a function into a lazy property. |
environ_property (name[, default, load_func, ...]) |
Maps request attributes to environment variables. |
header_property (name[, default, load_func, ...]) |
Like environ_property but for headers. |
Exceptions¶
ArgumentValidationError ([missing, extra, ...]) |
Raised if validate_arguments() fails to validate |