fastapiv2
uvicorn main:app --reload --host 0.0.0.0 --port 8080
- Python3.11.0
- Pip
- Poetry (Python Package Manager)
python -m venv venv
source venv/bin/activate
make install
make run
make deploy
make test
or
pytest
Files related to application are in the app
or tests
directories.
Application parts are:
app
|
| # Fast-API stuff
├── api - web related stuff.
│ └── routes - web routes.
├── core - application configuration, startup events, logging.
├── models - pydantic models for this application.
├── services - logic that is not just crud related.
├── main-aws-lambda.py - [Optional] FastAPI application for AWS Lambda creation and configuration.
└── main.py - FastAPI application creation and configuration.
|
├── data - where you persist data locally
│ ├── interim - intermediate data that has been transformed.
│ ├── processed - the final, canonical data sets for modeling.
│ └── raw - the original, immutable data dump.
│
└── tests - pytest
Deploying inference service to Cloud Run
- Install
gcloud
cli gcloud auth login
gcloud config set project <PROJECT_ID>
- Cloud Run API
- Cloud Build API
- IAM API
- Run
gcp-deploy.sh
- Delete Cloud Run
- Delete Docker image in GCR
Deploying inference service to AWS Lambda
- Install
awscli
andsam-cli
aws configure
- Run
sam build
- Run `sam deploy --guiChange this portion for other types of models
aws cloudformation delete-stack --stack-name <STACK_NAME_ON_CREATION>
Made by https://github.com/arthurhenrique/cookiecutter-fastapi/graphs/contributors with ❤️
Notes:
INSERT INTO notes (text, completed) VALUES ('first' , TRUE); INSERT INTO notes (text, completed) VALUES ('second' , TRUE);
docker exec test4-app-1 pytest
db_url = make_url(str(settings.db_url.with_path("/postgres"))) engine = create_async_engine(db_url, isolation_level="AUTOCOMMIT")
async with engine.connect() as conn:
database_existance = await conn.execute(
text(
f"SELECT 1 FROM pg_database WHERE datname='{settings.db_base}'", # noqa: E501, S608
),
)
database_exists = database_existance.scalar() == 1
if database_exists:
print("Deleting DB")
await drop_database()
async with engine.connect() as conn: # noqa: WPS440
await conn.execute(
text(
f'CREATE DATABASE "{settings.db_base}" ENCODING "utf8" TEMPLATE template1', # noqa: E501
),
)