AsadStack: Python Web Framework
Description
AsadStack is a Python Web Framework
It's a WSGI framework and can be used with any WSGI application server such as Gunicorn.
Installation
pip install AsadStack
How to use it
Basic Usage
from Asad_Stack.app import AsadStackApp
app = AsadStackApp()
@app.route("/home", allowed_methods=["get"])
def home(request, response):
response.text = "That is home page"
@app.route("/about", allowed_methods=["put"])
def about(request, response):
response.text = "That is about page"
@app.route("/hello/{name}")
def greeting(request, response, name):
response.text = f"Hello {name}"
@app.route("/books")
class Books:
def get(self, request, response):
response.text = "That is books page"
def post(self, request, response):
response.text = "That is books post page"
def new_handler(request, response):
response.text = "That is new handler"
@app.route("/template")
def template_handler(request, response):
response.html = app.template(
"home.html",
context={"new_title": "Best Title", "new_body": "Best Body Asadbek"}
)
@app.route("/json")
def json_handler(req, resp):
response_data = {"name": "Asadbek", "type": "json"}
resp.json = response_data
Unit Tests
The recommended way of writing unit tests is with pytest.
There are two built in fixtures
that you may want to use when writing unit tests with AsadStack.
The first one is app which is an instance of AsadStackApp.
def test_route_overlap_throws_exception(app):
@app.route("/")
def home(req, resp):
resp.text = "That is home page"
with pytest.raises(AssertionError):
app.route("/")
def home2(req, resp):
resp.text = "That is home2 page"
The other one is test_client that you can use to sen HTTP requests to your
handlers.It is based on the famous requests and
it should feel very familiar:
def test_parameterized_route(app, test_client):
@app.route("/hello/{name}")
def greeting(req, resp, name):
resp.text = f"Hello {name}"
assert test_client.get("http://testserver/hello/Asadtopchik").text == "Hello Asadtopchik"
Templates
The default folder for templates is templates. You can change it when
initializing the main AsadStackApp() class:
app = AsadStackApp(template_dir="template_dir_name")
Then you can use HTML files in that folder like so in a handler:
@app.route("/template")
def template_handler(request, response):
response.html = app.template(
"home.html",
context={"new_title": "Best Title", "new_body": "Best Body Asadbek"}
)
Static Files
You can use static folder in your project to serve static files.
app = AsadStackApp(static_dir="static")
Then you can use HTML files in that folder like so in a handler:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{{new_title}}</title>
<link rel="stylesheet" href="/static/home.css">
</head>
<body>
<h1>{{new_body}}</h1>
<p>This a paragraph</p>
</body>
</html>
Middleware
You can create custom middleware by extending the Middleware class.
from Asad_Stack.middleware import Middleware
from Asad_Stack.app import AsadStackApp
app = AsadStackApp()
class MyMiddleware(Middleware):
def process_request(self, req):
print("request is being called", req.url)
def process_response(self, req, resp):
print("response has been generated", resp.url)
app.add_middleware(MyMiddleware)
Metadata
Release files for AsadStack 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| AsadStack-0.1.2.tar.gz | 5.6 kB | Without provenance | Details for AsadStack-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| AsadStack-0.1.2-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for AsadStack-0.1.2-py2.py3-none-any.whl |
Total release size: 10.6 kB
Release files / AsadStack-0.1.2.tar.gz
| Download URL | AsadStack-0.1.2.tar.gz |
|---|---|
| Size | 5.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9847739431c95085dae265765e776d1e85a180eef8a4773c120931c190944b7a
|
|
BLAKE2b-256 checksum How to use checksums |
984a29df6719fc2279d9a2c44b2e2099a20049c5fba85b8189fc13cd185b027e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.11.9
|
Release files / AsadStack-0.1.2-py2.py3-none-any.whl
| Download URL | AsadStack-0.1.2-py2.py3-none-any.whl |
|---|---|
| Size | 5.0 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
8720e7288f45b69456addf1d69b3a1ddd3a2b57b8e06f253b8f8b6dfd7f9cab1
|
|
BLAKE2b-256 checksum How to use checksums |
fe412ef88c721f680af7ea6976db631b6ec78e6f5f941a4059e9c3a599d37f2e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.11.9
|
Security for AsadStack 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.