It is a simple and lightweight web framework built for learning and experimentation purposes.
Project description
from webob import Request
BizAPI
A Lightweight Web Framework for Python
Contents
A Simple Example
Installation using a Python package manager:
pip install 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'
gunicorn main:app
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
@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
# First 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")
# 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'
})
<!-- File: templates/hello.html -->
<html>
<head>
<title>{{title}}</title>
</head>
<body>
<p>Hello {{name}}</p>
</body>
</html>
Exception Handler
def on_exception(request: Request, response: Response, exc: Exception):
response.text = str(exc)
app.add_exception_handler(on_exception)
Custom Response
@app.route('/json')
def json(request: Request, response: Response):
response_data = {
'message': 'Hello World',
}
response.json = response_data
@app.route('/text')
def text(request: Request, response: Response):
response.text = "Hello World"
from bizapi import render_template
@app.route('/html')
def html(request: Request, response: Response):
response.html = render_template('index.html', text='Say Hello')
Middleware
from bizapi.middleware import Middleware
from bizapi.types import Request, Response
class ExampleMiddleware(Middleware):
def request(self, request: Request):
print(f'A request was received at the URL "{request.path}"')
def response(self, request: Request, response: Response):
print(f'A response was returned to the URL "{request.path}"')
app.add_middleware(ExampleMiddleware)
Features (To-Do)
Here's a list of upcoming features that will be included in BizAPI:
- Function-Based Routing
- Parameterized Routing
- Allowed Methods
- Class-Based Routing
- Simple Routes
- Templates
- Static Folder
- Exception Handler
- Custom Response
- Middleware
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.0.tar.gz.
File metadata
- Download URL: bizapi-0.1.0.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 |
70c16c7ca91902cbdf55fdb771ad0970cdda4a7d64889695ebed36e3b8b38004
|
|
| MD5 |
3d50c204f64a1678760f96b4877e2953
|
|
| BLAKE2b-256 |
1205767285467215dd720ad60b12805284857f31b258c783c628e6ecb3c07e67
|
File details
Details for the file BizAPI-0.1.0-py3-none-any.whl.
File metadata
- Download URL: BizAPI-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.5 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 |
ae49e06dafe032f28f56e687b05dcb9427046f063dcab67b2e2026ae2b996286
|
|
| MD5 |
0a10d12f3e5c65f48b89c0c1f93afa73
|
|
| BLAKE2b-256 |
665f8c027c0e6e37315cc6bcc6066574709b19bcc6954ccb250a47a7a42bcb4c
|