Skip to main content

Asynchronous web framework for building powerful web APIs and applications with Python

Project description

TezAPI

TezAPI is an asynchronous web framework for building powerful and efficient web APIs and applications with Python. It leverages the asyncio and aiohttp libraries to provide a seamless development experience for building high-performance web applications.

Key Features

  • Asynchronous by design: Built on top of asyncio and aiohttp, TezAPI allows you to write highly concurrent and efficient web applications.
  • Simple and intuitive API: With minimal boilerplate and sensible defaults, TezAPI provides a clean and intuitive API for defining routes and handling requests.
  • Error handling made easy: TezAPI simplifies error handling with support for both simple and class-based error responses, making it straightforward to handle exceptions and provide meaningful feedback to clients.
  • Schema validation with SchemaModel: TezAPI makes form validation easy with the SchemaModel class, allowing you to validate incoming request data against defined schemas effortlessly.
  • Template rendering with Jinja2Template: TezAPI includes built-in support for Jinja2Template, allowing you to render HTML templates seamlessly.

Installation

You can install TezAPI via pip:

pip install tezapi

Quick Start

import datetime
from tezapi import TezAPI
from tezapi.templating import Jinja2Template

app = TezAPI()
render = Jinja2Template('templates')


# Define routes and handlers
@app.get("/")
async def hello():
    return render('home.html', {'today': str(datetime.datetime.now())})


# Run the TezAPI application
app.run()

Advanced Features and Best Practices

In addition to the basic setup and usage, TezAPI offers advanced features and best practices for building robust web applications.

Advanced Routing Techniques

Route Parameters

In TezAPI, you can define routes with parameters that capture dynamic values from the URL. For example:

@app.get("/users/{user_id}")
async def get_user(request: Request, user_id: int):
    # Retrieve user data based on user_id
    return {'user_id': user_id}

Additional routes

from tezapi import Router

user_router = Router(prefix='/user')


@user_router.get('/get-me')
async def get_info(request):
    return {'name': 'John', 'surname': 'Doe'}
Include routers
from users import user_router

# including is very easy
app += user_router

Query Parameters

You can also handle query parameters in TezAPI routes. For example:

@app.get("/search")
async def search_users(request: Request):
    query = request.query.get('q')
    # Perform search based on query parameter
    return {'query': query}

Middleware

Middleware in TezAPI allows you to intercept and modify requests and responses before they reach the handler. You can use middleware for tasks such as authentication, logging, and request/response manipulation. Now optimized, you can install middleware filter selected request path and method

@app.middleware(path='/user', method='GET')
async def middleware_1(request: Request):
    print('Middleware started')
    return response

And removed call_next if you use return and call_next automatically work

@app.middleware()
async def middleware_2(request: Request):
    print('Middleware started')
    return response

If you empty middleware arguments, this means it work any methods and any paths

Router middleware

@my_router.middleware()
async def auth_filter(request):
    return check(auth)

Model Parameters

JSON Request models automatic filtering and validate

from tezapi.schemas import SchemaModel


class UserSchema(SchemaModel):
    username: str
    phone_number: str


@app.post("/")
async def hello(user: UserSchema):
    print(user)
    return user

Optimized SchemaModels -> coming soon

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tezapi-0.0.6.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

tezapi-0.0.6-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file tezapi-0.0.6.tar.gz.

File metadata

  • Download URL: tezapi-0.0.6.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.9

File hashes

Hashes for tezapi-0.0.6.tar.gz
Algorithm Hash digest
SHA256 b6d676408d771c76a35d2467b353a84dc0a3f7b8411dcf73fcbce4b9e1f69d93
MD5 684adddd42f9cca94a3d71df220c6e5e
BLAKE2b-256 17a9557564f8135e8e93c8838053772f0a7f703d18350a8c1aea424d7bbd28e8

See more details on using hashes here.

File details

Details for the file tezapi-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: tezapi-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.9

File hashes

Hashes for tezapi-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 13b69a8529d6d8e1e309dc73c5d20d660595c158f19d13431b27da162436e01b
MD5 0dfff95ab8491c37972bab6ec106ac46
BLAKE2b-256 368754fd2deeaab79f17ea6ecb2fa422f140bb19ce1c09303ae36d36e9031311

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page