Fast & Friendly, Web Framework For Building Async APIs
Project description
🐾 Why Choose Panther?
Panther is designed to be fast, simple, and powerful. Here's what makes it special:
- One of the fastest Python frameworks available (Benchmark)
- File-based database (PantherDB) - No external database setup required
- Document-oriented ODM - Supports MongoDB & PantherDB with familiar syntax
- API caching system - In-memory and Redis support
- OpenAPI - Auto-generated API documentation with multiple UI options
- WebSocket support - Real-time communication out of the box
- Authentication & Permissions - Built-in security features
- Background tasks - Handle long-running operations
- Middleware & Throttling - Extensible and configurable
Quick Start
Installation
pip install panther
- Create a
main.pyfile with one of the examples below.
Your First API
Here's a simple REST API endpoint that returns a "Hello World" message:
from datetime import datetime, timedelta
from panther import status, Panther
from panther.app import GenericAPI
from panther.openapi.urls import url_routing as openapi_url_routing
from panther.response import Response
class HelloAPI(GenericAPI):
# Cache responses for 10 seconds
cache = timedelta(seconds=10)
def get(self):
current_time = datetime.now().isoformat()
return Response(
data={'message': f'Hello from Panther! 🐾 | {current_time}'},
status_code=status.HTTP_200_OK
)
# URL routing configuration
url_routing = {
'/': HelloAPI,
'docs/': openapi_url_routing, # Auto-generated API docs
}
# Create your Panther app
app = Panther(__name__, configs=__name__, urls=url_routing)
WebSocket Echo Server
Here's a simple WebSocket echo server that sends back any message it receives:
from panther import Panther
from panther.app import GenericAPI
from panther.response import HTMLResponse
from panther.websocket import GenericWebsocket
class EchoWebsocket(GenericWebsocket):
async def connect(self, **kwargs):
await self.accept()
await self.send("Connected to Panther WebSocket!")
async def receive(self, data: str | bytes):
# Echo back the received message
await self.send(f"Echo: {data}")
class WebSocketPage(GenericAPI):
def get(self):
template = """
<h2>🐾 Panther WebSocket Echo Server</h2>
<input id="msg"><button onclick="s.send(msg.value)">Send</button>
<ul id="log"></ul>
<script>
const s = new WebSocket('ws://127.0.0.1:8000/ws');
s.onmessage = e => log.innerHTML += `<li><- ${msg.value}</li><li>-> ${e.data}</li>`;
</script>
"""
return HTMLResponse(template)
url_routing = {
'': WebSocketPage,
'ws': EchoWebsocket,
}
app = Panther(__name__, configs=__name__, urls=url_routing)
Run Your Application
-
Start the development server
$ panther run main:app
-
Test your application
- For the API example: Visit http://127.0.0.1:8000/ to see the "Hello World" response
- For the WebSocket example: Visit http://127.0.0.1:8000/ and send a message.
🙏 Acknowledgments
⭐️ If you find Panther useful, please give it a star!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file panther-5.2.1.tar.gz.
File metadata
- Download URL: panther-5.2.1.tar.gz
- Upload date:
- Size: 132.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
210ba944544a7b142e7fd41e49d7b4cde0a086643e59c927534b39cd2fb682a4
|
|
| MD5 |
cbe5be6912bbdaec1fc9161025b4ec6b
|
|
| BLAKE2b-256 |
05af60775ddc590db4c8abaa8155bf418ed87fd0f0f7c17d67a4641dbb1218c2
|
File details
Details for the file panther-5.2.1-py3-none-any.whl.
File metadata
- Download URL: panther-5.2.1-py3-none-any.whl
- Upload date:
- Size: 111.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
636015b4adabb99cdb14fb1c682bbc725d1c92d861f2f73a23a81a3bc63d2986
|
|
| MD5 |
66e6e576e7bff17df045220cbdd3af77
|
|
| BLAKE2b-256 |
64715e550a367db8f22941143b6ecbdf46dc5f3231e881723fae28039d6c9ba1
|