Skip to main content

Machine Learning ASGI Server with FastAPI

Project description

FastApp

HTTP Apps Made Easier with FastApp

Installation

pip install fastapp

Using Out the Example Server

pip install fastapp[example]
fastapp serve-debug fastapp.app.example:app

Using FastApp to build an app

Create a Python File with Endpoints, we'll call this main.py:

from datetime import datetime

from fastapp.app import app


@app.get("/hello")
def custom_endpoint() -> dict:
    """"
    This is a Custom API Endpoint
    """
    return dict(timestamp=datetime.now(),
                hello="world")

Then, using the FastApp CLI we can serve this App:

fastapp serve-debug main:app

...or via docker:

docker run --rm -it \
    --publish 8080:8080 \
    --volume ${PWD}/main.py:/root/fastapp/main.py \
    juftin/fastapp:latest \
    serve-debug main:app

Test out our new endpoint:

curl \
  --request GET \
  --header "Content-Type: application/json" \
  http://localhost:8080/hello

Alternatively, if we want to serve this app using Gunicorn, Nginx, and the UvicornWorker we can use the serve command:

fastapp serve main:app

I prefer doing this within a docker container so you don't have to run Nginx on the host machine:

docker run --rm -it \
    --publish 8080:8080 \
    --volume ${PWD}/main.py:/root/fastapp/main.py \
    juftin/fastapp:latest \
    serve main:app

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

fastapp-0.1.7.tar.gz (12.1 kB view hashes)

Uploaded Source

Built Distribution

fastapp-0.1.7-py3-none-any.whl (16.0 kB view hashes)

Uploaded Python 3

Supported by

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