It is a simple and lightweight web framework built for learning and experimentation purposes.
Project description
A Lightweight Web Framework for Python
Source Code and Information about BizAPI
Contents
Installation
To install BizAPI, use the following command:
pip install BizAPI
Quick Start
Create a simple application using BizAPI:
from bizapi import BizAPI
from bizapi.types import Request, Response
app = BizAPI()
@app.route('/')
def home(request: Request, response: Response):
response.text = 'This is the home page'
Run the application using Gunicorn:
gunicorn main:app
Routing
Function-Based Routing
@app.route('/')
def index(request: Request, response: Response):
response.text = "Hello World!"
Parameterized Routing
@app.route('/say-hello/{name}')
def sayhello(request: Request, response: Response, name: str):
response.text = f"Assalawma áleykum {name}"
Allowed Methods
@app.route('/article', methods=['POST'])
def create_article(request: Request, response: Response):
# Create a new article
pass
@app.route('/article', methods=['GET'])
def get_article(request: Request, response: Response):
# Get an article
pass
You can also use the method-specific decorators:
@app.post('/article')
def create_product(request: Request, response: Response):
# Create a new article
pass
@app.get('/article')
def get_product(request: Request, response: Response):
# Get an article
pass
Class-Based Routing
@app.route('/article')
class Article:
def get(request: Request, response: Response):
# Get an article
pass
def post(request: Request, response: Response):
# Create a new article
pass
Simple Router
def create_article(request: Request, response: Response):
response.text = "A new article has been created"
app.register_route('/article', create_article, ['POST'])
Templates
from bizapi import render_template
@app.route('/hello')
def hello_page(request: Request, response: Response):
response.html = render_template('hello.html', name="John")
# Second way
@app.route('/say-hello', methods=['GET'])
def home_page(request: Request, response: Response):
response.html = render_template('hello.html', {
'title': 'Say Hello!',
'name': 'John'
})
templates/hello.txt
<html>
<head><title>Hello</title></head>
<body><p>Hello, {{name}}</p></body>
</html>
Exception Handler
Add a custom exception handler to manage errors:
def on_exception(request: Request, response: Response, exc: Exception):
response.text = str(exc)
app.add_exception_handler(on_exception)
Custom Response
BizAPI allows returning different types of responses:
@app.route('/json')
def json(request: Request, response: Response):
response.json = {'message': 'Hello, World'}
@app.route('/text')
def text(request: Request, response: Response):
response.text = "Hello World"
@app.route('/html')
def html(request: Request, response: Response):
response.html = "<h1>Hello, World</h1>"
Middleware
You can add middleware to process requests and responses:
from bizapi.middleware import Middleware
class CustomMiddleware(Middleware):
def request(self, request: Request):
print(f"Request received: {request.path}")
def response(self, request: Request, response: Response):
print(f"Response sent for: {request.path}")
app.add_middleware(CustomMiddleware)
License
This project is licensed under the MIT License.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bizapi-0.1.1.tar.gz.
File metadata
- Download URL: bizapi-0.1.1.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ec314433e25c2e0e958fa1b0d4d3bf212cc70acb6449ce8c0ee0c0acc444723
|
|
| MD5 |
32acd72dde62a595868728f07451655e
|
|
| BLAKE2b-256 |
7ee1a1cddf039115dea63a23ea3a5e505208df6d3a51eb7fd187120eec74e1ab
|
File details
Details for the file BizAPI-0.1.1-py3-none-any.whl.
File metadata
- Download URL: BizAPI-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
88e121c0a60db231d7cded939fb6f4c820700bfab0390db01fa31ee6e89268a9
|
|
| MD5 |
a95c81e6b4558367a68e9b2508e1f4be
|
|
| BLAKE2b-256 |
a3d0f10d169373bf5d6c509d5a55ee749d4fea2517f820c43754ade8b374690e
|