最終更新:2025-10-01 (水) 10:18:24 (338d)  

uvicorn
Top / uvicorn

uvicorn <モジュール名>:<変数名>

Usage

  • uvicorn [OPTIONS] APP

main.py

  • async def app(scope, receive, send):
        assert scope['type'] == 'http'
    
        await send({
            'type': 'http.response.start',
            'status': 200,
            'headers': [
                (b'content-type', b'text/plain'),
                (b'content-length', b'13'),
            ],
        })
        await send({
            'type': 'http.response.body',
            'body': b'Hello, world!',
        })

サーバの起動

  • uvicorn main:app

スクリプト内から起動