當前位置: 首頁>>代碼示例>>Python>>正文


Python hug.API屬性代碼示例

本文整理匯總了Python中hug.API屬性的典型用法代碼示例。如果您正苦於以下問題:Python hug.API屬性的具體用法?Python hug.API怎麽用?Python hug.API使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在hug的用法示例。


在下文中一共展示了hug.API屬性的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: server

# 需要導入模塊: import hug [as 別名]
# 或者: from hug import API [as 別名]
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,
        ) 
開發者ID:timothycrosley,項目名稱:portray,代碼行數:42,代碼來源:api.py

示例2: main

# 需要導入模塊: import hug [as 別名]
# 或者: from hug import API [as 別名]
def main():
    API.cli() 
開發者ID:Phelimb,項目名稱:BIGSI,代碼行數:4,代碼來源:__main__.py

示例3: integrate_scout

# 需要導入模塊: import hug [as 別名]
# 或者: from hug import API [as 別名]
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) 
開發者ID:scoutapp,項目名稱:scout_apm_python,代碼行數:8,代碼來源:hug.py


注:本文中的hug.API屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。