Python hug.API Examples

The following are 3 code examples of hug.API(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module hug , or try the search function .
Example #1
Source File: api.py    From portray with MIT License 5 votes vote down vote up
def server(
    directory: str = "",
    config_file: str = "pyproject.toml",
    open_browser: bool = False,
    port: int = None,
    host: str = None,
    modules: list = None,
) -> None:
    """Runs a development webserver enabling you to browse documentation locally.

       - *directory*: The root folder of your project.
       - *config_file*: The [TOML](https://github.com/toml-lang/toml#toml) formatted
         config file you wish to use.
       - *open_browser*: If true a browser will be opened pointing at the documentation server
       - *port*: The port to expose your documentation on (defaults to: `8000`)
       - *host*: The host to expose your documentation on (defaults to `"127.0.0.1"`)
       - *modules*: One or more modules to render reference documentation for
    """
    directory = directory if directory else os.getcwd()
    api = hug.API("Doc Server")

    project_config = project_configuration(directory, config_file, modules=modules)
    with render.documentation_in_temp_folder(project_config) as doc_folder:

        @hug.static("/", api=api)
        def my_static_dirs():  # pragma: no cover
            return (doc_folder,)

        @hug.startup(api=api)
        def custom_startup(*args, **kwargs):  # pragma: no cover
            print(logo.ascii_art)
            if open_browser:
                webbrowser.open_new(f"http://{project_config['host']}:{project_config['port']}")

        api.http.serve(
            host=host or project_config["host"],
            port=port or project_config["port"],
            no_documentation=True,
            display_intro=False,
        ) 
Example #2
Source File: __main__.py    From BIGSI with MIT License 5 votes vote down vote up
def main():
    API.cli() 
Example #3
Source File: hug.py    From scout_apm_python with MIT License 5 votes vote down vote up
def integrate_scout(hug_module_name, config):
    http_interface = hug.API(hug_module_name).http
    scout_middleware = ScoutMiddleware(
        config=config, hug_http_interface=http_interface,
    )
    http_interface.add_middleware(scout_middleware)