Single-File
If you want to work with Panther
in a single-file
structure, follow the steps below.
Steps#
-
Write your
APIs
as you likefrom panther.app import API @API() async def hello_world_api(): return {'detail': 'Hello World'}
-
Add your
APIs
to adict
(example:url_routing
)3. Create anfrom panther.app import API @API() async def hello_world_api(): return {'detail': 'Hello World'} url_routing = { '/': hello_world_api, }
app
and pass your currentmodule name
andurls
to it.4. Run the projectfrom panther import Panther from panther.app import API @API() async def hello_world_api(): return {'detail': 'Hello World'} url_routing = { '/': hello_world_api, } app = Panther(__name__, configs=__name__, urls=url_routing)
- If name of your file is
main.py
-->panther run
- else use
uvicorn
-->uvicorn file_name:app
- If name of your file is
Notes#
URLs
is a required config unless you pass theurls
directly to thePanther
- When you pass the
configs
to thePanther(configs=...)
, Panther is going to load the configs from this file, else it is going to loadcore/configs.py
file
from panther import Panther
from panther.app import API
@API()
async def hello_world_api():
return {'detail': 'Hello World'}
url_routing = {
'/': hello_world_api,
}
app = Panther(__name__, configs=__name__, urls=url_routing)