[](https://patx.github.io/micropie)
## **Introduction**
**MicroPie** is a fast, lightweight, modern Python web framework that supports asynchronous web applications. Designed with **flexibility** and **simplicity** in mind, MicroPie enables you to handle high-concurrency applications with ease while allowing natural integration with external tools like Socket.IO for real-time communication.
### **Key Features**
- 🔄 **Routing:** Automatic mapping of URLs to functions with support for dynamic and query parameters.
- đź”’ **Sessions:** Simple, plugable, session management using cookies.
- 🎨 **Templates:** Jinja2, if installed, for rendering dynamic HTML pages.
- ⚙️ **Middleware:** Support for custom request middleware enabling functions like rate limiting, authentication, logging, and more.
- ✨ **ASGI-Powered:** Built w/ asynchronous support for modern web servers like Uvicorn and Daphne, enabling high concurrency.
- 🛠️ **Lightweight Design:** Only optional dependencies for flexibility and faster development/deployment.
- ⚡ **Blazing Fast:** Check out how MicroPie compares to other popular ASGI frameworks below!
### **Useful Links**
- **Homepage**: [patx.github.io/micropie](https://patx.github.io/micropie)
- **API Reference**: [README.md#api-documentation](https://github.com/patx/micropie/blob/main/README.md#api-documentation)
- **PyPI Page**: [pypi.org/project/MicroPie](https://pypi.org/project/MicroPie/)
- **GitHub Project**: [github.com/patx/micropie](https://github.com/patx/micropie)
- **File Issue/Request**: [github.com/patx/micropie/issues](https://github.com/patx/micropie/issues)
- **Example Applications**: [github.com/patx/micropie/tree/main/examples](https://github.com/patx/micropie/tree/main/examples)
## **Installing MicroPie**
### **Installation**
Install MicroPie with all optional dependencies via pip:
```bash
pip install micropie[all]
```
This will install MicroPie along with `jinja2` for template rendering and `multipart`/`aiofiles` for parsing multipart form data.
### **Minimal Setup**
You can also install MicroPie without ANY dependencies via pip:
```bash
pip install micropie
```
For an ultra-minimalistic approach, download the standalone script:
[MicroPie.py](https://raw.githubusercontent.com/patx/micropie/refs/heads/main/MicroPie.py)
Place it in your project directory, and you are good to go. Note that `jinja2` must be installed separately to use the `_render_template` method and/or `multipart` & `aiofiles` for handling file uploads (the `_parse_multipart` method), but this *is* optional and you can use MicroPie without them. To install the optional dependencies use:
```bash
pip install jinja2 multipart aiofiles
```
### **Install an ASGI Web Server**
In order to test and deploy your apps you will need a ASGI web server like Uvicorn, Hypercorn or Daphne. Install `uvicorn` with:
```bash
pip install uvicorn
```
## **Getting Started**
### **Create Your First ASGI App**
Save the following as `app.py`:
```python
from MicroPie import App
class MyApp(App):
async def index(self):
return "Welcome to MicroPie ASGI."
app = MyApp()
```
Run the server with:
```bash
uvicorn app:app
```
Access your app at [http://127.0.0.1:8000](http://127.0.0.1:8000).
## **Core Features**
### **1. Flexible HTTP Routing for GET Requests**
MicroPie automatically maps URLs to methods within your `App` class. Routes can be defined as either synchronous or asynchronous functions, offering good flexibility.
For GET requests, pass data through query strings or URL path segments, automatically mapped to method arguments.
```python
class MyApp(App):
async def greet(self, name="Guest"):
return f"Hello, {name}!"
async def hello(self):
name = self.request.query_params.get("name", None)[0]
return f"Hello {name}!"
```
**Access:**
- [http://127.0.0.1:8000/greet?name=Alice](http://127.0.0.1:8000/greet?name=Alice) returns `Hello, Alice!`, same as [http://127.0.0.1:8000/greet/Alice](http://127.0.0.1:8000/greet/Alice) returns `Hello, Alice!`.
- [http://127.0.0.1:8000/hello/Alice](http://127.0.0.1:8000/hello/Alice) returns a `500 Internal Server Error` because it is expecting [http://127.0.0.1:8000/hello?name=Alice](http://127.0.0.1:8000/hello?name=Alice), which returns `Hello Alice!`
### **2. Flexible HTTP POST Request Handling**
MicroPie also supports handling form data submitted via HTTP POST requests. Form data is automatically mapped to method arguments. It is able to handle default values and raw/JSON POST data:
```python
class MyApp(App):
async def submit_default_values(self, username="Anonymous"):
return f"Form submitted by: {username}"
async def submit_catch_all(self):
username = self.request.body_params.get("username", ["Anonymous"])[0]
return f"Submitted by: {username}"
```
By default, MicroPie's route handlers can accept any request method, it's up to you how to handle any incoming requests! You can check the request method (and an number of other things specific to the current request state) in the handler with`self.request.method`. You can see how to handle POST JSON data at [examples/api](https://github.com/patx/micropie/tree/main/examples/api).
### **3. Real-Time Communication with Socket.IO**
Because of its designed simplicity, MicroPie does not handle WebSockets out of the box. While the underlying ASGI interface can theoretically handle WebSocket connections, MicroPie’s routing and request-handling logic is designed primarily for HTTP. While MicroPie does not natively support WebSockets, you can easily integrate dedicated Websockets libraries like **Socket.IO** alongside Uvicorn to handle real-time, bidirectional communication. Check out [examples/socketio](https://github.com/patx/micropie/tree/main/examples/socketio) to see this in action.
### **4. Jinja2 Template Rendering**
Dynamic HTML generation is supported via Jinja2. This happens asynchronously using Pythons `asyncio` library, so make sure to use the `async` and `await` with this method.
#### **`app.py`**
```python
class MyApp(App):
async def index(self):
return await self._render_template("index.html", title="Welcome", message="Hello from MicroPie!")
```
#### **`templates/index.html`**
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{{ title }}</title>
</head>
<body>
<h1>{{ message }}</h1>
</body>
</html>
```
### **5. Static File Serving**
Here again, like Websockets, MicroPie does not have a built in static file method. While MicroPie does not natively support static files, if you need them, you can easily integrate dedicated libraries like **ServeStatic** or **Starlette’s StaticFiles** alongside Uvicorn to handle async static file serving. Check out [examples/static_content](https://github.com/patx/micropie/tree/main/examples/static_content) to see this in action.
### **6. Streaming Responses**
Support for streaming responses makes it easy to send data in chunks.
```python
class MyApp(App):
async def stream(self):
async def generator():
for i in range(1, 6):
yield f"Chunk {i}\n"
return generator()
```
### **7. Sessions and Cookies**
Built-in session handling simplifies state management:
```python
class MyApp(App):
async def index(self):
if "visits" not in self.session:
self.request.session["visits"] = 1
else:
self.request.session["visits"] += 1
return f"You have visited {self.request.session['visits']} times."
```
You also can use the `SessionBackend` class to create your own session backend. You can see an example of this in [examples/sessions](https://github.com/patx/micropie/tree/main/examples/sessions).
### **8. Middleware**
MicroPie allows you to create pluggable middleware to hook into the request lifecycle. Take a look a trivial example using `HttpMiddleware` to send the console messages before and after the request is processed.
```python
from MicroPie import App, HttpMiddleware
class MiddlewareExample(HttpMiddleware):
async def before_request(self, request):
print("Hook before request")
async def after_request(self, request, status_code, response_body, extra_headers):
print("Hook after request")
class Root(App):
async def index(self):
return "Hello, World!"
app = Root()
app.middlewares.append(MiddlewareExample())
```
### **9. Deployment**
MicroPie apps can be deployed using any ASGI server. For example, using Uvicorn if our application is saved as `app.py` and our `App` subclass is assigned to the `app` variable we can run it with:
```bash
uvicorn app:app --workers 4 --port 8000
```
## **Learn by Examples**
The best way to get an idea of how MicroPie works is to see it in action! Check out the [examples folder](https://github.com/patx/micropie/tree/main/examples) for more advanced usage, including:
- Template rendering
- Custom HTTP request handling
- File uploads
- Serving static content with ServeStatic
- Session usage
- JSON Requests and Responses
- Websockets with Socket.io
- Async Streaming
- Middleware
- Form handling and POST requests
- And more
## **Why ASGI?**
ASGI is the future of Python web development, offering:
- **Concurrency**: Handle thousands of simultaneous connections efficiently.
- **WebSockets**: Use tools like Socket.IO for real-time communication.
- **Scalability**: Ideal for modern, high-traffic applications.
MicroPie allows you to take full advantage of these benefits while maintaining simplicity and ease of use you're used to with your WSGI apps and it lets you choose what libraries you want to work with instead of forcing our ideas onto you!
## **Comparisons**
### **Features vs Other Popular Frameworks**
| Feature | MicroPie | Flask | CherryPy | Bottle | Django | FastAPI |
|---------------------|---------------|--------------|------------|--------------|--------------|-----------------|
| **Ease of Use** | Very Easy | Easy | Easy | Easy | Moderate | Moderate |
| **Routing** | Automatic | Manual | Manual | Manual | Views | Manual |
| **Template Engine** | Jinja2 (Opt.) | Jinja2 | None | SimpleTpl | Django | Jinja2 |
| **Middleware** | Yes | Yes | Yes | Yes | Yes | Yes |
| **Session Handling**| Simple | Extension | Built-in | Plugin | Built-in | Extension |
| **Async Support** | Yes (ASGI) | No (Quart) | No | No | Limited | Yes (ASGI) |
| **Built-in Server** | No | No | Yes | Yes | Yes | No |
## Benchmark Results
Below is a performance comparison of various ASGI frameworks using their "Hello World" examples from each framework's website. Ran with `uvicorn` with 4 workers and `wrk -t12 -c1000 -d30s http://127.0.0.1:8000/`:
| Framework | Requests/sec | Transfer/sec | Avg Latency | Stdev Latency | Max Latency | Socket Errors (timeouts) |
|-----------------|--------------|--------------|-------------|---------------|-------------|--------------------------|
| **Muffin** | 6508.80 | 0.90MB | 132.62ms | 69.71ms | 2.00s | 533 |
| **Starlette** | 6340.40 | 0.86MB | 130.72ms | 75.55ms | 2.00s | 621 |
| **BlackSheep** | 5928.99 | 0.98MB | 142.48ms | 73.61ms | 1.99s | 526 |
| **MicroPie** | 5447.04 | 0.85MB | 157.04ms | 71.55ms | 2.00s | 470 |
| **Litestar** | 5088.38 | 730.46KB | 151.59ms | 81.75ms | 2.00s | 662 |
| **Sanic** | 4236.29 | 682.61KB | 196.80ms | 80.56ms | 2.00s | 452 |
| **FastAPI** | 2352.53 | 326.23KB | 396.95ms | 112.41ms | 2.00s | 516 |
## **Suggestions or Feedback?**
We welcome suggestions, bug reports, and pull requests!
- File issues or feature requests [here](https://github.com/patx/micropie/issues).
- Security issues that should not be public, email `harrisonerd [at] gmail.com`.
# **API Documentation**
## Session Backend Abstraction
MicroPie provides an abstraction for session backends, allowing you to define custom session storage mechanisms.
### `SessionBackend` Class
#### Methods
- `load(session_id: str) -> Dict[str, Any]`
- Abstract method to load session data given a session ID.
- `save(session_id: str, data: Dict[str, Any], timeout: int) -> None`
- Abstract method to save session data.
### `InMemorySessionBackend` Class
An in-memory implementation of the `SessionBackend`.
#### Methods
- `__init__()`
- Initializes the in-memory session backend.
- `load(session_id: str) -> Dict[str, Any]`
- Loads session data for the given session ID.
- `save(session_id: str, data: Dict[str, Any], timeout: int) -> None`
- Saves session data for the given session ID.
## Middleware Abstraction
MicroPie allows you to create pluggable middleware to hook into the request lifecycle.
### `HttpMiddleware` Class
#### Methods
- `before_request(request: Request) -> None`
- Abstract method called before the request is processed.
- `after_request(request: Request, status_code: int, response_body: Any, extra_headers: List[Tuple[str, str]]) -> None`
- Abstract method called after the request is processed but before the final response is sent to the client.
## Request Object
### `Request` Class
Represents an HTTP request in the MicroPie framework.
#### Attributes
- `scope`: The ASGI scope dictionary for the request.
- `method`: The HTTP method of the request.
- `path_params`: List of path parameters.
- `query_params`: Dictionary of query parameters.
- `body_params`: Dictionary of body parameters.
- `get_json`: JSON request body object.
- `session`: Dictionary of session data.
- `files`: Dictionary of uploaded files.
- `headers`: Dictionary of headers.
## Application Base
### `App` Class
The main ASGI application class for handling HTTP requests in MicroPie.
#### Methods
- `__init__(session_backend: Optional[SessionBackend] = None) -> None`
- Initializes the application with an optional session backend.
- `request -> Request`
- Retrieves the current request from the context variable.
- `__call__(scope: Dict[str, Any], receive: Callable[[], Awaitable[Dict[str, Any]]], send: Callable[[Dict[str, Any]], Awaitable[None]]) -> None`
- ASGI callable interface for the server. Checks `scope` type.
- `_asgi_app_http(scope: Dict[str, Any], receive: Callable[[], Awaitable[Dict[str, Any]]], send: Callable[[Dict[str, Any]], Awaitable[None]]) -> None`
- ASGI application entry point for handling HTTP requests.
- `request(self) -> Request`
- Accessor for the current request object. - Returns the current request from the context variable.
- `_parse_cookies(cookie_header: str) -> Dict[str, str]`
- Parses the Cookie header and returns a dictionary of cookie names and values.
- `_parse_multipart(reader: asyncio.StreamReader, boundary: bytes)`
- Parses multipart/form-data from the given reader using the specified boundary.
- *Requires*: `multipart` and `aiofiles`
- `_send_response(send: Callable[[Dict[str, Any]], Awaitable[None]], status_code: int, body: Any, extra_headers: Optional[List[Tuple[str, str]]] = None) -> None`
- Sends an HTTP response using the ASGI send callable.
- `_redirect(location: str) -> Tuple[int, str]`
- Generates an HTTP redirect response.
- `_render_template(name: str, **kwargs: Any) -> str`
- Renders a template asynchronously using Jinja2.
- *Requires*: `jinja2`
The `App` class is the main entry point for creating MicroPie applications. It implements the ASGI interface and handles HTTP requests.
## Response Formats
Handlers can return responses in the following formats:
1. String or bytes or JSON
2. Tuple of (status_code, body)
3. Tuple of (status_code, body, headers)
4. Async or sync generator for streaming responses
## Error Handling
MicroPie provides built-in error handling for common HTTP status codes:
- `404 Not Found`: Automatically returned for non-existent routes
- `400 Bad Request`: Returned for missing required parameters
- `500 Internal Server Error`: Returned for unhandled exceptions
Custom error handling can be implemented through middleware.
----
© 2025 Harrison Erd
Raw data
{
"_id": null,
"home_page": null,
"name": "MicroPie",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "micropie, asgi, microframework, http",
"author": null,
"author_email": "Harrison Erd <harrisonerd@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/a1/07/4642ca77df388a44af63628b2807ac9f87bef60d3af7fe2a69d88dca237d/micropie-0.9.9.7.2.tar.gz",
"platform": null,
"description": "[](https://patx.github.io/micropie)\n\n## **Introduction**\n\n**MicroPie** is a fast, lightweight, modern Python web framework that supports asynchronous web applications. Designed with **flexibility** and **simplicity** in mind, MicroPie enables you to handle high-concurrency applications with ease while allowing natural integration with external tools like Socket.IO for real-time communication.\n\n### **Key Features**\n- \ud83d\udd04 **Routing:** Automatic mapping of URLs to functions with support for dynamic and query parameters.\n- \ud83d\udd12 **Sessions:** Simple, plugable, session management using cookies.\n- \ud83c\udfa8 **Templates:** Jinja2, if installed, for rendering dynamic HTML pages.\n- \u2699\ufe0f **Middleware:** Support for custom request middleware enabling functions like rate limiting, authentication, logging, and more.\n- \u2728 **ASGI-Powered:** Built w/ asynchronous support for modern web servers like Uvicorn and Daphne, enabling high concurrency.\n- \ud83d\udee0\ufe0f **Lightweight Design:** Only optional dependencies for flexibility and faster development/deployment.\n- \u26a1 **Blazing Fast:** Check out how MicroPie compares to other popular ASGI frameworks below!\n\n### **Useful Links**\n- **Homepage**: [patx.github.io/micropie](https://patx.github.io/micropie)\n- **API Reference**: [README.md#api-documentation](https://github.com/patx/micropie/blob/main/README.md#api-documentation)\n- **PyPI Page**: [pypi.org/project/MicroPie](https://pypi.org/project/MicroPie/)\n- **GitHub Project**: [github.com/patx/micropie](https://github.com/patx/micropie)\n- **File Issue/Request**: [github.com/patx/micropie/issues](https://github.com/patx/micropie/issues)\n- **Example Applications**: [github.com/patx/micropie/tree/main/examples](https://github.com/patx/micropie/tree/main/examples)\n\n## **Installing MicroPie**\n\n### **Installation**\nInstall MicroPie with all optional dependencies via pip:\n```bash\npip install micropie[all]\n```\nThis will install MicroPie along with `jinja2` for template rendering and `multipart`/`aiofiles` for parsing multipart form data.\n\n### **Minimal Setup**\nYou can also install MicroPie without ANY dependencies via pip:\n```bash\npip install micropie\n```\n\nFor an ultra-minimalistic approach, download the standalone script:\n\n[MicroPie.py](https://raw.githubusercontent.com/patx/micropie/refs/heads/main/MicroPie.py)\n\nPlace it in your project directory, and you are good to go. Note that `jinja2` must be installed separately to use the `_render_template` method and/or `multipart` & `aiofiles` for handling file uploads (the `_parse_multipart` method), but this *is* optional and you can use MicroPie without them. To install the optional dependencies use:\n```bash\npip install jinja2 multipart aiofiles\n```\n\n### **Install an ASGI Web Server**\nIn order to test and deploy your apps you will need a ASGI web server like Uvicorn, Hypercorn or Daphne. Install `uvicorn` with:\n```bash\npip install uvicorn\n```\n\n## **Getting Started**\n\n### **Create Your First ASGI App**\n\nSave the following as `app.py`:\n```python\nfrom MicroPie import App\n\nclass MyApp(App):\n async def index(self):\n return \"Welcome to MicroPie ASGI.\"\n\napp = MyApp()\n```\nRun the server with:\n```bash\nuvicorn app:app\n```\nAccess your app at [http://127.0.0.1:8000](http://127.0.0.1:8000).\n\n## **Core Features**\n\n### **1. Flexible HTTP Routing for GET Requests**\nMicroPie automatically maps URLs to methods within your `App` class. Routes can be defined as either synchronous or asynchronous functions, offering good flexibility.\n\nFor GET requests, pass data through query strings or URL path segments, automatically mapped to method arguments.\n```python\nclass MyApp(App):\n async def greet(self, name=\"Guest\"):\n return f\"Hello, {name}!\"\n\n async def hello(self):\n name = self.request.query_params.get(\"name\", None)[0]\n return f\"Hello {name}!\"\n```\n**Access:**\n- [http://127.0.0.1:8000/greet?name=Alice](http://127.0.0.1:8000/greet?name=Alice) returns `Hello, Alice!`, same as [http://127.0.0.1:8000/greet/Alice](http://127.0.0.1:8000/greet/Alice) returns `Hello, Alice!`.\n- [http://127.0.0.1:8000/hello/Alice](http://127.0.0.1:8000/hello/Alice) returns a `500 Internal Server Error` because it is expecting [http://127.0.0.1:8000/hello?name=Alice](http://127.0.0.1:8000/hello?name=Alice), which returns `Hello Alice!`\n\n### **2. Flexible HTTP POST Request Handling**\nMicroPie also supports handling form data submitted via HTTP POST requests. Form data is automatically mapped to method arguments. It is able to handle default values and raw/JSON POST data:\n```python\nclass MyApp(App):\n async def submit_default_values(self, username=\"Anonymous\"):\n return f\"Form submitted by: {username}\"\n\n async def submit_catch_all(self):\n username = self.request.body_params.get(\"username\", [\"Anonymous\"])[0]\n return f\"Submitted by: {username}\"\n```\n\nBy default, MicroPie's route handlers can accept any request method, it's up to you how to handle any incoming requests! You can check the request method (and an number of other things specific to the current request state) in the handler with`self.request.method`. You can see how to handle POST JSON data at [examples/api](https://github.com/patx/micropie/tree/main/examples/api).\n\n### **3. Real-Time Communication with Socket.IO**\nBecause of its designed simplicity, MicroPie does not handle WebSockets out of the box. While the underlying ASGI interface can theoretically handle WebSocket connections, MicroPie\u2019s routing and request-handling logic is designed primarily for HTTP. While MicroPie does not natively support WebSockets, you can easily integrate dedicated Websockets libraries like **Socket.IO** alongside Uvicorn to handle real-time, bidirectional communication. Check out [examples/socketio](https://github.com/patx/micropie/tree/main/examples/socketio) to see this in action.\n\n\n### **4. Jinja2 Template Rendering**\nDynamic HTML generation is supported via Jinja2. This happens asynchronously using Pythons `asyncio` library, so make sure to use the `async` and `await` with this method.\n\n#### **`app.py`**\n```python\nclass MyApp(App):\n async def index(self):\n return await self._render_template(\"index.html\", title=\"Welcome\", message=\"Hello from MicroPie!\")\n```\n\n#### **`templates/index.html`**\n```html\n<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <title>{{ title }}</title>\n</head>\n<body>\n <h1>{{ message }}</h1>\n</body>\n</html>\n```\n\n### **5. Static File Serving**\nHere again, like Websockets, MicroPie does not have a built in static file method. While MicroPie does not natively support static files, if you need them, you can easily integrate dedicated libraries like **ServeStatic** or **Starlette\u2019s StaticFiles** alongside Uvicorn to handle async static file serving. Check out [examples/static_content](https://github.com/patx/micropie/tree/main/examples/static_content) to see this in action.\n\n\n### **6. Streaming Responses**\nSupport for streaming responses makes it easy to send data in chunks.\n\n```python\nclass MyApp(App):\n async def stream(self):\n async def generator():\n for i in range(1, 6):\n yield f\"Chunk {i}\\n\"\n return generator()\n```\n\n### **7. Sessions and Cookies**\nBuilt-in session handling simplifies state management:\n\n```python\nclass MyApp(App):\n async def index(self):\n if \"visits\" not in self.session:\n self.request.session[\"visits\"] = 1\n else:\n self.request.session[\"visits\"] += 1\n return f\"You have visited {self.request.session['visits']} times.\"\n```\n\nYou also can use the `SessionBackend` class to create your own session backend. You can see an example of this in [examples/sessions](https://github.com/patx/micropie/tree/main/examples/sessions).\n\n### **8. Middleware**\nMicroPie allows you to create pluggable middleware to hook into the request lifecycle. Take a look a trivial example using `HttpMiddleware` to send the console messages before and after the request is processed.\n```python\nfrom MicroPie import App, HttpMiddleware\n\nclass MiddlewareExample(HttpMiddleware):\n async def before_request(self, request):\n print(\"Hook before request\")\n\n async def after_request(self, request, status_code, response_body, extra_headers):\n print(\"Hook after request\")\n\n\nclass Root(App):\n async def index(self):\n return \"Hello, World!\"\n\napp = Root()\napp.middlewares.append(MiddlewareExample())\n```\n\n### **9. Deployment**\nMicroPie apps can be deployed using any ASGI server. For example, using Uvicorn if our application is saved as `app.py` and our `App` subclass is assigned to the `app` variable we can run it with:\n```bash\nuvicorn app:app --workers 4 --port 8000\n```\n\n\n## **Learn by Examples**\nThe best way to get an idea of how MicroPie works is to see it in action! Check out the [examples folder](https://github.com/patx/micropie/tree/main/examples) for more advanced usage, including:\n- Template rendering\n- Custom HTTP request handling\n- File uploads\n- Serving static content with ServeStatic\n- Session usage\n- JSON Requests and Responses\n- Websockets with Socket.io\n- Async Streaming\n- Middleware\n- Form handling and POST requests\n- And more\n\n## **Why ASGI?**\nASGI is the future of Python web development, offering:\n- **Concurrency**: Handle thousands of simultaneous connections efficiently.\n- **WebSockets**: Use tools like Socket.IO for real-time communication.\n- **Scalability**: Ideal for modern, high-traffic applications.\n\nMicroPie allows you to take full advantage of these benefits while maintaining simplicity and ease of use you're used to with your WSGI apps and it lets you choose what libraries you want to work with instead of forcing our ideas onto you!\n\n\n## **Comparisons**\n\n### **Features vs Other Popular Frameworks**\n| Feature | MicroPie | Flask | CherryPy | Bottle | Django | FastAPI |\n|---------------------|---------------|--------------|------------|--------------|--------------|-----------------|\n| **Ease of Use** | Very Easy | Easy | Easy | Easy | Moderate | Moderate |\n| **Routing** | Automatic | Manual | Manual | Manual | Views | Manual |\n| **Template Engine** | Jinja2 (Opt.) | Jinja2 | None | SimpleTpl | Django | Jinja2 |\n| **Middleware** | Yes | Yes | Yes | Yes | Yes | Yes |\n| **Session Handling**| Simple | Extension | Built-in | Plugin | Built-in | Extension |\n| **Async Support** | Yes (ASGI) | No (Quart) | No | No | Limited | Yes (ASGI) |\n| **Built-in Server** | No | No | Yes | Yes | Yes | No |\n\n## Benchmark Results\n\nBelow is a performance comparison of various ASGI frameworks using their \"Hello World\" examples from each framework's website. Ran with `uvicorn` with 4 workers and `wrk -t12 -c1000 -d30s http://127.0.0.1:8000/`:\n\n| Framework | Requests/sec | Transfer/sec | Avg Latency | Stdev Latency | Max Latency | Socket Errors (timeouts) |\n|-----------------|--------------|--------------|-------------|---------------|-------------|--------------------------|\n| **Muffin** | 6508.80 | 0.90MB | 132.62ms | 69.71ms | 2.00s | 533 |\n| **Starlette** | 6340.40 | 0.86MB | 130.72ms | 75.55ms | 2.00s | 621 |\n| **BlackSheep** | 5928.99 | 0.98MB | 142.48ms | 73.61ms | 1.99s | 526 |\n| **MicroPie** | 5447.04 | 0.85MB | 157.04ms | 71.55ms | 2.00s | 470 |\n| **Litestar** | 5088.38 | 730.46KB | 151.59ms | 81.75ms | 2.00s | 662 |\n| **Sanic** | 4236.29 | 682.61KB | 196.80ms | 80.56ms | 2.00s | 452 |\n| **FastAPI** | 2352.53 | 326.23KB | 396.95ms | 112.41ms | 2.00s | 516 |\n\n## **Suggestions or Feedback?**\nWe welcome suggestions, bug reports, and pull requests!\n- File issues or feature requests [here](https://github.com/patx/micropie/issues).\n- Security issues that should not be public, email `harrisonerd [at] gmail.com`.\n\n# **API Documentation**\n\n## Session Backend Abstraction\n\nMicroPie provides an abstraction for session backends, allowing you to define custom session storage mechanisms.\n\n### `SessionBackend` Class\n\n#### Methods\n\n- `load(session_id: str) -> Dict[str, Any]`\n - Abstract method to load session data given a session ID.\n\n- `save(session_id: str, data: Dict[str, Any], timeout: int) -> None`\n - Abstract method to save session data.\n\n### `InMemorySessionBackend` Class\n\nAn in-memory implementation of the `SessionBackend`.\n\n#### Methods\n\n- `__init__()`\n - Initializes the in-memory session backend.\n\n- `load(session_id: str) -> Dict[str, Any]`\n - Loads session data for the given session ID.\n\n- `save(session_id: str, data: Dict[str, Any], timeout: int) -> None`\n - Saves session data for the given session ID.\n\n## Middleware Abstraction\n\nMicroPie allows you to create pluggable middleware to hook into the request lifecycle.\n\n### `HttpMiddleware` Class\n\n#### Methods\n\n- `before_request(request: Request) -> None`\n - Abstract method called before the request is processed.\n\n- `after_request(request: Request, status_code: int, response_body: Any, extra_headers: List[Tuple[str, str]]) -> None`\n - Abstract method called after the request is processed but before the final response is sent to the client.\n\n## Request Object\n\n### `Request` Class\n\nRepresents an HTTP request in the MicroPie framework.\n\n#### Attributes\n\n- `scope`: The ASGI scope dictionary for the request.\n- `method`: The HTTP method of the request.\n- `path_params`: List of path parameters.\n- `query_params`: Dictionary of query parameters.\n- `body_params`: Dictionary of body parameters.\n- `get_json`: JSON request body object.\n- `session`: Dictionary of session data.\n- `files`: Dictionary of uploaded files.\n- `headers`: Dictionary of headers.\n\n## Application Base\n\n### `App` Class\n\nThe main ASGI application class for handling HTTP requests in MicroPie.\n\n#### Methods\n\n- `__init__(session_backend: Optional[SessionBackend] = None) -> None`\n - Initializes the application with an optional session backend.\n\n- `request -> Request`\n - Retrieves the current request from the context variable.\n\n- `__call__(scope: Dict[str, Any], receive: Callable[[], Awaitable[Dict[str, Any]]], send: Callable[[Dict[str, Any]], Awaitable[None]]) -> None`\n - ASGI callable interface for the server. Checks `scope` type.\n\n- `_asgi_app_http(scope: Dict[str, Any], receive: Callable[[], Awaitable[Dict[str, Any]]], send: Callable[[Dict[str, Any]], Awaitable[None]]) -> None`\n - ASGI application entry point for handling HTTP requests.\n\n- `request(self) -> Request`\n - Accessor for the current request object. - Returns the current request from the context variable.\n\n- `_parse_cookies(cookie_header: str) -> Dict[str, str]`\n - Parses the Cookie header and returns a dictionary of cookie names and values.\n\n- `_parse_multipart(reader: asyncio.StreamReader, boundary: bytes)`\n - Parses multipart/form-data from the given reader using the specified boundary.\n - *Requires*: `multipart` and `aiofiles`\n\n- `_send_response(send: Callable[[Dict[str, Any]], Awaitable[None]], status_code: int, body: Any, extra_headers: Optional[List[Tuple[str, str]]] = None) -> None`\n - Sends an HTTP response using the ASGI send callable.\n\n- `_redirect(location: str) -> Tuple[int, str]`\n - Generates an HTTP redirect response.\n\n- `_render_template(name: str, **kwargs: Any) -> str`\n - Renders a template asynchronously using Jinja2.\n - *Requires*: `jinja2`\n\nThe `App` class is the main entry point for creating MicroPie applications. It implements the ASGI interface and handles HTTP requests.\n\n## Response Formats\n\nHandlers can return responses in the following formats:\n\n1. String or bytes or JSON\n2. Tuple of (status_code, body)\n3. Tuple of (status_code, body, headers)\n4. Async or sync generator for streaming responses\n\n## Error Handling\n\nMicroPie provides built-in error handling for common HTTP status codes:\n\n- `404 Not Found`: Automatically returned for non-existent routes\n- `400 Bad Request`: Returned for missing required parameters\n- `500 Internal Server Error`: Returned for unhandled exceptions\n\nCustom error handling can be implemented through middleware.\n\n----\n\n\u00a9 2025 Harrison Erd\n",
"bugtrack_url": null,
"license": null,
"summary": "An ultra micro ASGI web framework",
"version": "0.9.9.7.2",
"project_urls": {
"Homepage": "https://patx.github.io/micropie",
"Repository": "https://github.com/patx/micropie"
},
"split_keywords": [
"micropie",
" asgi",
" microframework",
" http"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "ae244ab3de6bac40180b8f48aefa9c842b3f93bf0ff30e2c48476c5425eac2dc",
"md5": "e88edac845b0e20da42a9ae23e6f6b94",
"sha256": "adfa81ec0f17b17c8dc64c70bf954ed8c0f87633dde7559932ea5af90f58fffd"
},
"downloads": -1,
"filename": "micropie-0.9.9.7.2-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "e88edac845b0e20da42a9ae23e6f6b94",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 13785,
"upload_time": "2025-02-25T03:41:59",
"upload_time_iso_8601": "2025-02-25T03:41:59.504307Z",
"url": "https://files.pythonhosted.org/packages/ae/24/4ab3de6bac40180b8f48aefa9c842b3f93bf0ff30e2c48476c5425eac2dc/micropie-0.9.9.7.2-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "a1074642ca77df388a44af63628b2807ac9f87bef60d3af7fe2a69d88dca237d",
"md5": "3e02202d5b991ae060f29cfe1a50c599",
"sha256": "63550a94daabb7180c247ee7c048edda11f84aa78b8c5bf99292c09d9df2964e"
},
"downloads": -1,
"filename": "micropie-0.9.9.7.2.tar.gz",
"has_sig": false,
"md5_digest": "3e02202d5b991ae060f29cfe1a50c599",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 170731,
"upload_time": "2025-02-25T03:42:01",
"upload_time_iso_8601": "2025-02-25T03:42:01.877191Z",
"url": "https://files.pythonhosted.org/packages/a1/07/4642ca77df388a44af63628b2807ac9f87bef60d3af7fe2a69d88dca237d/micropie-0.9.9.7.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-25 03:42:01",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "patx",
"github_project": "micropie",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "micropie"
}