Skip to main content

This is a python backend framework for building REST applications. It is built on top of the ASGI specification and uses the uvicorn server.

Project description

Description

This is a python backend framework for building REST applications. It is built on top of the ASGI specification and uses the uvicorn server.

Installation

poetry install
poetry shell
python setup.py bdist_wheel
pip install dist/privatejet-0.0.3-py3-none-any.whl

Usage

"""
This is an example of how to use PrivateJet.
"""
from typing import Callable

from privatejet.main import PrivateJet
from privatejet.middlewares import CORSMiddleware
from privatejet.router import JetRouter


private_jet = PrivateJet()


async def app(scope: dict[str, str], receive: Callable, send: Callable) -> None:
    """
    This function is called by the ASGI server.
    """
    await private_jet.add_middleware(CORSMiddleware)
    await private_jet.add_router(router={"prefix": "/users", "router": UserRouter})
    await private_jet.start(scope=scope, receive=receive, send=send)


class UserRouter(JetRouter):
    """
    User Router
    """

    async def get(self, request: dict[str]) -> None:
        """
        When request method is GET and the path is like this:
            - /users
        """
        await self.send_message(
            [
                {"name": "alex", "age": 20},
                {"name": "john", "age": 30},
            ]
        )

    async def get_one(self, request: dict[str]) -> None:
        """
        When request method is GET and the path is like this:
            - /users/1
        """
        await self.send_message({"name": "alex", "age": 20})

    async def post(self, request: dict[str]) -> None:
        """
        When request method is POST and the path is like this:
            - /users
        """
        await self.send_message(
            {
                "message": "User created successfully",
                "user": {
                    "name": request["body"]["name"],
                    "age": request["body"]["age"],
                },
            }
        )

    async def put(self, request: dict[str]) -> None:
        """
        When request method is PUT and the path is like this:
            - /users/1
        """
        await self.send_message(
            {
                "message": "User updated successfully",
                "user": {
                    "name": request["body"]["name"],
                    "age": request["body"]["age"],
                },
            }
        )

    async def patch(self, request: dict[str]) -> None:
        """
        When request method is PATCH and the path is like this:
            - /users/1
        """
        await self.send_message(
            {
                "message": "User patched successfully",
                "user": {
                    "name": request["body"]["name"],
                    "age": request["body"]["age"],
                },
            }
        )

    async def delete(self, request: dict[str]) -> None:
        """
        When request method is DELETE and the path is like this:
            - /users/1
        """
        await self.send_message(
            {
                "message": "User deleted successfully",
            }
        )

License

This project is licensed under the terms of the MIT license.

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

privatejet-0.0.3.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

privatejet-0.0.3-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file privatejet-0.0.3.tar.gz.

File metadata

  • Download URL: privatejet-0.0.3.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for privatejet-0.0.3.tar.gz
Algorithm Hash digest
SHA256 aa4612b865e187d2fa4a4c80f9e1f15c996ac6b772a127d494f8f74b9117515e
MD5 d401de02f4f5721255edc83e6b184d12
BLAKE2b-256 01b12fdafeece82ba1229cd1ac3366f3d33b159ee12aff00c5a3dd7c459bbff0

See more details on using hashes here.

File details

Details for the file privatejet-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: privatejet-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for privatejet-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0350f55baa9a97b8c988edb3360eeba8e9873366c6fd756041dc78507a88ac3e
MD5 936c3f761b4096f31dca7445aa5e8b0e
BLAKE2b-256 044edb727c5e94341c06c7dcdc922a95900c711a4d19fb1678d76d979c15fd23

See more details on using hashes here.

Supported by

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