Git Product home page Git Product logo

fastapi_production_template's Introduction

📍 about me

  • co-founder at dappSheriff
  • previously co-founded peerlink
    • 🔨 simple website builder for coaches, which has been pivoted from all-in-one platform for creators
    • 💸 raised a decent pre-seed round
    • 🍀 built a great team & vibes
    • 💔 couldn't reach product-market fit, though we were loved at product hunt (#2 and #3 for both products)
  • engineered reliable & scalable APIs, video streaming & processing services, distributed data pipelines & crawlers for analyzing millions of online items

✍️ find me on

fastapi_production_template's People

Contributors

ckpinguin avatar itisnotyourenv avatar izeye avatar na0495 avatar ntoskrn avatar ohld avatar pankaj28843 avatar sitawit avatar svanderweerd avatar zhanymkanov 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

fastapi_production_template's Issues

what's the relationship between "log_config" in uvicorn.run('main:app', host="127.0.0.1", port=8051, log_config="log.ini") and logging.getLogger(__name__)?

hello,sir.
i wtite a log.ini,pass it for the para of log_config in uvicorn.run('main:app', host="127.0.0.1", port=8051, log_config="log.ini").

besides, i initializes class of logger by:self._logger = logging.getLogger(name) in some file.

i found that the log generated by self._logger can be found in the log file defined by "log_config".

so,question is:

  1. why?
  2. how can i output some dynamic log to the log file formally?

How to define custom error responses in docs?

Currently, custom exceptions do not get a place on documentation. I have tried responses={}, but with no luck. What's the correct thing to do here? Create a custom pydantic model just for it to show on docs?

Pytest_asyncio event loop replacement deprecated

In the conftest.py the event loop is being replaced with a new one. This is no longer supported with pytest_asyncio and results in this warning:

Replacing the event_loop fixture with a custom implementation is deprecated
  and will lead to errors in the future.
  If you want to request an asyncio event loop with a scope other than function
  scope, use the "scope" argument to the asyncio mark when marking the tests.
  If you want to return different types of event loops, use the event_loop_policy
  fixture.

Question: how to manage alembic autogenerate in multi-module project structure

Hi,
Thank you for your great work!

Something is unclear for me according to "FastAPI Best Practices" and this repo.

If this repository would have the same multi-module structure (src/auth/models.py, src/posts/models.py), the alembic will not see these models during the autogenerate, because we need import Base and all models we want to track somewhere in one place.

How do you handle this?

Is the alembic/env.py the best place to do these imports?

For example:

from src.models import Base  # noqa
from src.auth.models import User # noqa
from src.posts.models import Post # noqa

target_metadata = Base.metadata

I think explicit imports in env.py is not a bad idea, because we can control which models alembic will be tracking.

But what is the best practice?

Rate Limiting on the PublicAPIs endpoint?

app          | pydantic_core._pydantic_core.ValidationError: 1 validation error for PublicAPIsResponse
app          |   Invalid JSON: expected value at line 1 column 1 [type=json_invalid, input_value=b'You have reached maximum request limit.', input_type=bytes]
app          |     For further information visit https://errors.pydantic.dev/2.3/v/json_invalid

It looks like there is some sort of rate limiting on the Public API request, might have something to do with the httpx user agent? Not sure if anyone has encountered this, as the endpoint is perfectly accessible through the browser.

Should 'logconfig' in gunicorn_conf.py takes value from environment variable?

According to start-dev.sh, it can take LOG_CONFIG

LOG_CONFIG=${LOG_CONFIG:-/src/logging.ini}

But this is static value.

logconfig = "/src/logging_production.ini"

We can change to
logconfig = os.getenv("LOG_CONFIG", "/src/logging_production.ini")

What do you think? This will make LOG_CONFIG in .env has meaning for both dev and prod environment.

Question: Use of json_dumps in Pydantic Models

Hi, and thanks for sharing this! It's always interesting to see how others are structuring their FastAPI projects. Looking over this repo I did have one question I hope you don't mind me asking (please close if you'd rather not have questions).

In your subclass of the pydantic BaseModel you set the json_dumps function to use an orjson based implementation. My understanding of pydantic means this function will be used whenever model_subclass.json() is called. However, fastAPI won't actually call .json() and instead will just use its jsonable_encoder function when returning pydantic models from an endpoint.

I know one can directly return a Response class to skip the fastAPI validation so potentially you could be doing something like:

@router.get("/endpoint", response_model=SomeModel)
def get_model():
    some_model = SomeModel(...)
    return ORJSONResponse(content=json.loads(some_model.json()))

But it would be cool if there was a way to set this up without having to explicitly call .json(). So I'd like to understand how you are using this json_dumps function in practice if you don't mind sharing?

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.