rednafi / fastapi-nano Goto Github PK
View Code? Open in Web Editor NEW🐍 Simple FastAPI template employing divisional architecture pattern
License: MIT License
🐍 Simple FastAPI template employing divisional architecture pattern
License: MIT License
Hi, I was just browsing through this repo and noticed that the auth routes are declared using async def
, in https://github.com/rednafi/fastapi-nano/blob/master/app/core/auth.py#L125 but the underlying database access in the function that is also used as a dependency on line https://github.com/rednafi/fastapi-nano/blob/master/app/core/auth.py#L117 is synchronous. My understanding of FastAPI is such that in this case, it would be better to declare the route and dependency using a simple def
, so that the whole thing is handled in a thread and other requests can still be processed concurrently. The way it's currently implemented, I think the entire event loop might be blocked whenever the database is accessed in that route and the related dependency.
Just flagging out of interest, apologies if my understanding is incorrect here.
(I hope I describe this correctly, it is possible that I have a misunderstanding of how imports are resolved)
Problem: The FastAPI documentation on debugging suggests to call uvicorn directly from main via the IDE/Debugger. However, in this case, fastapi-nano’s imports do not seem to work, as the folder of main.py is the root folder for the module imports with this method of executing the code. So from app.core import auth
fails, , from core import auth
would work. The imports work when calling uvicorn directly since uvicorn app.main:app
(as documented in the readme) seems to make the module resolution uses the folder uvicorn was called from as its root (that is, the project’s main folder with the folder app in it)
Possible solutions:
Hi, I couldn't seem to find any documentation specifiying how to login with the access token instead of regular auth scheme?
Would fit contributing with helm chart from Kubernetes workloads?
I have a very simple one that is very portable.
import random
from unittest.mock import patch
import pytest
@pytest.fixture(scope="module")
def mock_randint():
"""Mock random.randint function."""
with patch("random.randint", return_value=42, auto=True) as m:
yield m
@pytest.mark.parametrize(
"seed, output",
[(1, 42), (100, 42), (589, 42), (444, 42)],
)
def test_randint(mock_randint, seed, output):
assert random.randint(0, seed) == output
mock_randint.assert_called_with(0, seed)
pytest.mark.parametrize
to make the tests robust.Would make sense to use starlette.config.Config
instead of os.environ
+ load_dotenv
?
Starlette Config does env validation and has builtin load dotenv which would remove the need for python-dotenv.
I could send a pull request if its fine.
Python 3.10 is now stable and the libraries have mostly caught up at this point. Update the docker container to use the latest Python version.
fastapi | File "/usr/local/lib/python3.8/site-packages/gunicorn/config.py", line 611, in Workers
fastapi | default = int(os.environ.get("WEB_CONCURRENCY", 1))
fastapi | ValueError: invalid literal for int() with base 10: '1
What about a GitHub Action that publishes the Docker container to the GitHub repository registry?
how do I replace the fake Database with a real Database like the SQLite DB with the user models in it
Private registry credentials can bleed into the requirements file if you run
pip-compile requirements.in -o requirements.txt
Add the proper flags to stop this.
If we add how logging can be incorporated, when API calls are made, using middleware it will cover all facets.
This project is kind of complete in a sense. I don't want to manually merge Dependabot PRs. Enable auto-merging via GitHub action.
Hi,
I am trying to use live reload for devlepement. I have added below code in Dockerfile as suggested in uvicorn-gunicorn-fastapi-docker. But when i check it still takes start.sh. Any idea? Thank you very much.
RUN pip install -r requirements.txt
# copy project
COPY . /code/
CMD [ "/start-reload.sh" ] # <-----
# expose port
EXPOSE 5000
Docker compose v2 has been stable for quite a while. Convert docker commands in the makefile
to be v2 compatible.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.