Hammal
Hammal is a fast, minimalist Python web framework inspired by Echo. It is designed to be simple and easy to embed within other applications, providing the bare minimum router functionality.
Installation
Install Hammal using pip:
pip install hammal
Quick Start
Here's how you can get started with Hammal:
Example: Hello World
import json
from hammal import Hammal, RequestContext
def hello_handler(context: RequestContext) -> None:
context.response.body = json.dumps({"message": "Hello, World!"})
router = Hammal()
router.get("/", hello_handler)
router.start()
Run the script and visit http://localhost:8000 in your browser to see "Hello, World!".
Example: Handling Parameters
def greet_handler(context: RequestContext) -> None:
name = context.path_params.get("name", "Guest")
context.response.body = json.dumps({"message": f"Hello, {name}!"})
router.get("/greet/:name", greet_handler)
Accessing http://localhost:8080/greet/Pikachu will return "Hello, Pikachu!".
Example: Middleware
import logging
def logging_middleware(context: RequestContext) -> bool:
logging.info(f"{context.method} request for {context.path} with body: {context.body}")
return True
def auth_middleware(context: RequestContext) -> bool:
token = context.headers.get("Authorization")
if not token == MONITORING_API_KEY:
context.response.status = 401
return False
return True
router.use(logging_middleware)
router.use(auth_middleware)
Example: Extensibility
Hammal is designed to be extensible, allowing you to integrate it into other applications seamlessly. Here's an example of extending Hammal:
from hammal import Hammal
class BotWithHammal(Hammal):
def __init__(self, bot, *args, **kwargs):
self.bot = bot
super().__init__(*args, **kwargs)
def start_async(self, *args, **kwargs):
super().start_async(*args, **kwargs)
self.bot.polling(none_stop=True, timeout=60)
app = BotWithHammal(bot)
# add routes and middlewares
app.start_async()
More Examples
The examples directory.
Contributing
Contributions are welcome! Feel free to fork the project and submit a pull request.
License
Hammal is open-source software licensed under the MIT License.
Metadata
Release files for hammal 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| hammal-0.1.3.tar.gz | 5.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| hammal-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.0 kB
Release files / hammal-0.1.3.tar.gz
| Download URL | hammal-0.1.3.tar.gz |
|---|---|
| Size | 5.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7761875e795997e6c70182913a38d77c100dca986123f65f8ef745c801d80c6a
|
|
BLAKE2b-256 checksum How to use checksums |
e697dbd79c404aa0e6722bd8e7f48fa6bced1d083d8ac1615e2d344def11293b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.13
|
Release files / hammal-0.1.3-py3-none-any.whl
| Download URL | hammal-0.1.3-py3-none-any.whl |
|---|---|
| Size | 5.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
73a9360043f31ecd16257f32b1969e2e2e387bf9d2b86d99f36c801d87017abb
|
|
BLAKE2b-256 checksum How to use checksums |
e443898c787eff846dc94419bef1cacc5099f7bb905cc1c7df5a94e261076bfa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.13
|