Skip to main content

BizAPI

A Lightweight Web Framework for Python

PyPI - License PyPI - Downloads PyPI - Status

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.

Metadata

Release files for BizAPI 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for BizAPI 0.1.1
File Size Uploaded
bizapi-0.1.1.tar.gz 7.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for BizAPI 0.1.1
File Interpreter ABI Platform
BizAPI-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 15.0 kB

Release files / bizapi-0.1.1.tar.gz

Download URL bizapi-0.1.1.tar.gz
Size 7.4 kB
Tags Source
SHA-256 checksum
How to use checksums
4ec314433e25c2e0e958fa1b0d4d3bf212cc70acb6449ce8c0ee0c0acc444723
BLAKE2b-256 checksum
How to use checksums
7ee1a1cddf039115dea63a23ea3a5e505208df6d3a51eb7fd187120eec74e1ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.5

Release files / BizAPI-0.1.1-py3-none-any.whl

Download URL BizAPI-0.1.1-py3-none-any.whl
Size 7.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
88e121c0a60db231d7cded939fb6f4c820700bfab0390db01fa31ee6e89268a9
BLAKE2b-256 checksum
How to use checksums
a3d0f10d169373bf5d6c509d5a55ee749d4fea2517f820c43754ade8b374690e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.5

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page