update readme for new sessionbackend class

Commit 70c5d97 · patx · 2025-02-13T23:26:21-05:00

Changeset
70c5d97ab6ec9775366affca00da7a9ab7736f20
Parents
6f8f06ae6e1c0be6c250f85e4ff15abdc95b4d27

View source at this commit

Comments

No comments yet.

Log in to comment

Diff

diff --git a/MicroPie.py b/MicroPie.py
index 913c0f8..119b379 100644
--- a/MicroPie.py
+++ b/MicroPie.py
@@ -97,6 +97,11 @@ current_request: contextvars.ContextVar[Any] = contextvars.ContextVar("current_r
 class Request:
     """Represents an HTTP request in the MicroPie framework."""
     def __init__(self, scope: Dict[str, Any]) -> None:
+        """
+        Initialize a new Request instance.
+        Args:
+            scope: The ASGI scope dictionary for the request.
+        """
         self.scope: Dict[str, Any] = scope
         self.method: str = scope["method"]
         self.path_params: List[str] = []
@@ -131,6 +136,11 @@ class App:
 
     @property
     def request(self) -> Request:
+        """
+        Retrieve the current request from the context variable.
+        Returns:
+            The current Request instance.
+        """
         return current_request.get()
 
     async def __call__(
diff --git a/README.md b/README.md
index 99ab148..ae945b6 100644
--- a/README.md
+++ b/README.md
@@ -19,7 +19,7 @@
 - **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**
@@ -154,6 +154,8 @@ class MyApp(App):
         return f"You have visited {self.request.session['visits']} times."
 ```
 
+You also can use the `SessionBackend` class to create your own session middleware. You can see an example of this in [examples/sessions](https://github.com/patx/micropie/tree/main/examples/sessions).
+
 ### **8. 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
@@ -168,6 +170,7 @@ The best way to get an idea of how MicroPie works is to see it in action! Check
 - File uploads
 - Serving static content with ServeStatic
 - Session usage
+- Sessions
 - Websockets with Socket.io
 - Async Streaming
 - Form handling and POST requests
@@ -238,6 +241,30 @@ We welcome suggestions, bug reports, and pull requests!
 
 * `scope` (Dict\[str, Any\]): The ASGI scope dictionary for the request.
 
+## Class: SessionBackend
+
+An abstract base class for session backends in MicroPie. It provides an interface for loading and saving session data.
+
+### Methods
+
+#### `load(self, session_id: str) -> Dict[str, Any]`
+**Description:** Load session data given a session ID.
+
+**Parameters:**
+
+* `session_id (str)`: The unique session identifier.
+
+**Returns:** A dictionary containing the loaded session data.
+
+#### `save(self, session_id: str, data: Dict[str, Any], timeout: int) -> None`
+**Description:** Save session data given a session ID, session data, and a timeout in seconds.
+
+**Parameters:**
+
+* session_id (str): The unique session identifier.
+* data (Dict[str, Any]): Session data to be saved.
+*  timeout (int): Session timeout in seconds.
+
 ## **Class: App**
 
 **Description:** ASGI application for handling HTTP requests and WebSocket connections in MicroPie.
diff --git a/setup.py b/setup.py
index 25ec1ec..b57d7e9 100644
--- a/setup.py
+++ b/setup.py
@@ -25,7 +25,7 @@ Links
 from distutils.core import setup
 
 setup(name="MicroPie",
-    version="0.9.7.1",
+    version="0.9.8",
     description="A ultra micro web framework w/ Jinja2.",
     long_description=__doc__,
     author="Harrison Erd",