Code Monkey home page Code Monkey logo

fastapi-nano's Introduction

fastapi-nano's People

Contributors

ayr-ton avatar davidkimdy avatar dependabot[bot] avatar github-actions[bot] avatar guscardvs avatar kareemmahlees avatar rednafi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fastapi-nano's Issues

Uvicorn import paths different than main.py’s, difficulties debugging

(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:

  • Assume calling from the /app folder and change paths accordingly
  • Document another way to debug
  • Dont fix/not a significant problem

Update to Python 3.10

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.

Refactor tests to utilize pytest features

  • Use fixtures to patch objects at the module level. Here's an example:
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)
  • Use pytest.mark.parametrize to make the tests robust.

Counterproductive use of async routes in auth?

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.

Starlette Config

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.

ValueError: invalid literal for int() with base 10

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

Enable automerge

This project is kind of complete in a sense. I don't want to manually merge Dependabot PRs. Enable auto-merging via GitHub action.

Live reload Option

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

Add logging- Feature request

If we add how logging can be incorporated, when API calls are made, using middleware it will cover all facets.

Helmchart for Kubernetes

Would fit contributing with helm chart from Kubernetes workloads?

I have a very simple one that is very portable.

GitHub Actions publish

What about a GitHub Action that publishes the Docker container to the GitHub repository registry?

Upgrade to Python 3.12

  • Upgrade to Python 3.12
  • Drop Python 3.8 and 3.9 (Supporting only the last 3 Python versions)
  • Upgrade to Pydantic v2
  • Update FastAPI
  • Fix outdated instructions in the README
  • Build all the containers in the CI

real Database

how do I replace the fake Database with a real Database like the SQLite DB with the user models in it

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.