Useful Methods¶
If you started your server in Python code, the following methods are available to you.
-
class
minipyp.
MiniPyP
(config)[source]¶ -
add_site
(site: dict)[source]¶ Add a site after initialization.
Parameters: site – the same dict as in the configuration
-
get_directory
(dir: str)[source]¶ Get the options for any given directory, defaulting if no options were set.
Parameters: dir – OS-specific directory path Returns: dict
-
get_error_page
(code: int, directory: str = None)[source]¶ Get the error page for any HTTP code.
Parameters: - code – HTTP status
- directory – OS-specific path to get custom error pages for
Returns: dict
-
get_handler
(extension: str)[source]¶ Get a file handler by the extension.
Parameters: extension – the file extension (e.g. ‘py’) Returns: Handler object or None
-
get_mime_type
(extension)[source]¶ Get the MIME type for any file extension.
Parameters: extension – the file extension Returns: MIME type or None if one is not set
-
get_path
(path: str, site: dict = None)[source]¶ Get the options for any given path, defaulting if no options were set. If a site is given, it will be applied after any global options for the path.
Parameters: - path – URI (e.g. ‘/mypath’)
- site – site object (see MiniPyP.get_site)
Returns: dict
-
get_site
(host: str)[source]¶ Get a site by its hostname.
Parameters: host – the hostname to look for Returns: dict or None
-
load_config
(config=None)[source]¶ Load new config values from the provided dict. If None, and a previously loaded file exists, it will be reloaded.
Parameters: config – the new config
-
set_directory
(dir: str, options: dict = None)[source]¶ Set the options for a directory. If options is None, all options will be removed. Otherwise, any options not provided will stay as-is in the configuration.
Parameters: - dir – OS-specific directory path
- options – the options to set
-
set_error_page
(code: int, page: dict)[source]¶ Set the error page for any HTTP code. Page should include either html for plain HTML or file to render a file instead.
Parameters: - code – HTTP status
- page – dict
-
set_handler
(extension: str, mime_type: str, handler: minipyp.minipyp.Handler)[source]¶ Add a file handler after initialization.
Parameters: - extension – the file extension (e.g. ‘py’)
- mime_type – the MIME type to serve with this file
- handler – a Handler subclass (see Handler docs)
-
set_mime_type
(mime_type, *extensions)[source]¶ Set the MIME type of a file extension.
Parameters: - mime_type – MIME type (e.g. ‘application/html’
- extensions – File extensions (e.g. ‘py’, ‘pyc’, …)
-
set_path
(path: str, options: dict = None)[source]¶ Set the options for a path. If options is None, all options will be removed. Otherwise, any options not provided will stay as-is in the configuration.
Parameters: - path – URI path
- options – the options to set
-
static
test_config
(config: dict, part: str = None)[source]¶ Test the provided configuration, or a part of it.
Parameters: - config – dict of config
- part – part of the config to test (or None)
Raise: ConfigError if invalid
-
write_config
(to: str = None)[source]¶ Writes the current configuration to the config file. If to is None (default), the config will be written to the real config file or a ConfigError will be thrown. If to is False, nothing will be written.
Parameters: to – the file to write to Returns: YAML-encoded configuration
-