Skip to content

A small api project with fastapi to try creating a full async http request lifecycle with python

Notifications You must be signed in to change notification settings

fvlima/sample-fast-api

Repository files navigation

Build Status codecov

sample-fast-api

A project to test a full async http request lifecycle with fastapi + gino + asyncpg

next steps

  • improve insert and update operations with db
  • configurations to deal with postgres pool
  • others...

setting up for local development

We use poetry to manage dependencies, so make sure you have it installed. Create database and set on .env file

cp default.env .env
make install

how to run locally

make run

how to test

create database test and set on .env file

make test

some benchmarks

all tests were ran in a database with 1M users registereds

  • 1000 requests with concurrency 10 retrieving 100 results per page
ab -n 1000 -c 10 -H "Authorization: Token a2a18886-d3a2-4774-8e5f-69f7e1057a7d" "http://127.0.0.1:8000/users/?q=User%20Name&limit=100&offset=0"

Complete requests: 1000
Failed requests: 0
Time per request: 64.130 [ms]
  • 1000 requests with concurrency 10 retrieving 10 results per page
ab -n 1000 -c 10 -H "Authorization: Token a2a18886-d3a2-4774-8e5f-69f7e1057a7d" "http://127.0.0.1:8000/users/?q=User%20Name&limit=10&offset=0"

Complete requests: 1000
Failed requests: 0
Time per request: 14.512 [ms]
  • 1000 requests with concurrency 10 fetching user
ab -n 1000 -c 10 -H "Authorization: Token a2a18886-d3a2-4774-8e5f-69f7e1057a7d" "http://127.0.0.1:8000/users/24ca2936-5044-4d3e-bafe-904a68b0194f


Complete requests: 1000
Failed requests: 0
Time per request: 6.266 [ms]
  • 1000 request with concurrency 10 posting users data
ab -n 1000 -c 10 -p user.json -m POST -H "Authorization: Token a2a18886-d3a2-4774-8e5f-69f7e1057a7d" http://127.0.0.1:8000/users/

Complete requests: 1000
Failed requests: 0
Time per request: 129.519 [ms]

About

A small api project with fastapi to try creating a full async http request lifecycle with python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages