Using Panther in a Single-File Structure#
If you prefer to work with Panther
in a single Python file, follow the steps below to quickly set up and run your API.
Step 1: Define Your APIs#
Write your API endpoints as usual using the @API()
decorator or inheriting from GenericAPI
:
main.py | |
---|---|
1 2 3 4 5 |
|
Step 2: Create a URL Routing Dictionary#
Map your endpoints to their respective URLs in a dictionary (commonly named url_routing
):
main.py | |
---|---|
6 7 8 |
|
Step 3: Initialize the Panther App#
Create an instance of the Panther
app, passing your current module name and the URL routing dictionary:
main.py | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Step 4: Run Your Project#
Use the following command to start your application:
panther run main:app
Additional Notes#
- The
urls
parameter is required unless you provide the URLs via configuration. - When you pass
configs=__name__
to thePanther
constructor, Panther will load the configuration from the current file. If you omit this, Panther defaults to loading configuration fromcore/configs.py
.