A lightweight and fast ASGI-based Python web framework for building APIs with automatic OpenAPI documentation.
Project description
MirAPI
MirAPI is a lightweight, fast, and easy-to-use ASGI-based Python web framework for building APIs. It's designed to be simple yet powerful, allowing developers to quickly create robust asynchronous web applications and RESTful APIs with automatic OpenAPI (Swagger) documentation.
Features
- ASGI-based for high performance and scalability
- Easy-to-use routing system
- Automatic OpenAPI (Swagger) documentation generation
- Built-in support for JSON responses
- Type hinting and Pydantic model integration
- Lightweight and fast asynchronous application
- Customizable error handling
- Support for all standard HTTP methods
Installation
You can install MirAPI using pip:
pip install mirapi
Quick Start
Here's a simple example to get you started with MirAPI:
from mirapi import MirAPI
from pydantic import BaseModel
app = MirAPI(title="My API", version="1.0.0")
class Item(BaseModel):
name: str
price: float
@app.get("/")
async def root():
return {"message": "Hello, World!"}
@app.post("/items")
async def create_item(item: Item):
return {"item": item, "message": "Item created successfully"}
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)
This example creates a simple asynchronous API with two endpoints: a GET route at the root path and a POST route for creating items.
Advanced Usage
Route Parameters
MirAPI supports path parameters in your routes:
@app.get("/items/{item_id}")
async def get_item(item_id: int):
return {"item_id": item_id}
Request Body Validation
Use Pydantic models to validate request bodies:
from pydantic import BaseModel
class User(BaseModel):
username: str
email: str
age: int
@app.post("/users")
async def create_user(user: User):
return {"user": user, "message": "User created successfully"}
Error Handling
MirAPI provides built-in error handling, but you can also customize error responses:
from starlette.exceptions import HTTPException
from starlette.responses import JSONResponse
@app.route("/custom_error")
async def custom_error(request):
raise HTTPException(status_code=400, detail="Custom error message")
@app.exception_handler(HTTPException)
async def http_exception_handler(request, exc):
return JSONResponse(
status_code=exc.status_code,
content={"message": exc.detail},
)
Documentation
MirAPI automatically generates OpenAPI (Swagger) documentation for your API. You can access the interactive API documentation by navigating to /docs
in your browser when running your application.
Dependencies
MirAPI depends on the following packages:
- starlette (0.39.2)
- parse (1.20.2)
- uvicorn (0.31.1)
- pydantic (2.9.2)
These dependencies will be automatically installed when you install MirAPI.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Inspired by modern ASGI-based Python web frameworks
- Built with love for the Python community
For more detailed information and advanced usage, please refer to the documentation.
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
File details
Details for the file mirapi-0.0.2.tar.gz
.
File metadata
- Download URL: mirapi-0.0.2.tar.gz
- Upload date:
- Size: 11.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39dd7513940aa221f52d460169a156067f0b6cb8545b6aba7f0bf5653b03568d |
|
MD5 | 528f04ecc571346e5d75f567dfa5c4ff |
|
BLAKE2b-256 | dd4e630e21a37c3dbf7e83a7472bed8834437873b8203cfeadeab0fe5a07d00c |
File details
Details for the file mirapi-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: mirapi-0.0.2-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a50c51f08b28800956649adac5e171e4448854d3016b80ece4bde5694e57885a |
|
MD5 | 6e6d730c791764ea0a6a9acfa6cc681d |
|
BLAKE2b-256 | 3e60cdbc186068028b4c3dc569fab2c7c51ad6f98b6b8b87c7f87fa15e1eaf93 |