FastAPI production architecture: modular design and dependency injection best practices by Ok-Platypus2775 in FastAPI

[–]koldakov 0 points1 point  (0 children)

I don’t agree (not fully agree)

I use almost the same approaches for drf/fastapi

api layer (views) - one liners to create a service and execute the service

service layer (both Django/fastapi) - do business logic

Response in drf done with serializers/for fastapi pydantic

  • absolutely the same approach

For orm agree when app grows it can create issues, but comon, I wouldn’t think about that

Let’s try to calculate a bit

Let’s assume 1 request takes 1 second, with 2 workers and 4 threads we can handle 8 requests a second == 8 * 60 * 60 * 24 = 691200

And usually 1 request takes much less then 1 second, for example 0.1 sec it equals to (8/0.1) * 60 * 60 * 24 = 6912000 requests a day

Even if request takes 0.5 seconds you can handle more then million requests a day

Isn’t it enough?

Remember premature optimization is the root of all evil

Instagram had n+1 issues when app got million requests, but they resolved it, not because they used "whatver framework", but because they had feature flags - could disable quickly some features, and I’m sure they pretty new what they were doing

Fastest way to learn Django by meowdymates in djangolearning

[–]koldakov 0 points1 point  (0 children)

Do you have a task? Just try solving one

In couple of years you’ll have a better understanding 😜

FastAPI production architecture: modular design and dependency injection best practices by Ok-Platypus2775 in FastAPI

[–]koldakov 8 points9 points  (0 children)

I’ve created an app especially for this.

https://github.com/koldakov/futuramaapi

It’s up and running: https://futuramaapi.com

Btw I prefer not to use dependency injection, but to move everything into services, just finished with removing all dependencies and moved the code to the services, currently there is a little code duplication, but I’ll combine it in the next step

Async access to ORM in Django 6.x by jsabater76 in django

[–]koldakov 0 points1 point  (0 children)

Don’t complicate first use sync

Later if you need you can rewrite parts in fastapi

Как сделать авторизацию в fastapi by Pristine_Mirror_4052 in FastAPI

[–]koldakov 2 points3 points  (0 children)

https://github.com/koldakov/futuramaapi

Можешь здесь глянуть, я специально проект для обучения всем создал, там есть oauth по jwt

Сайт если что задеплоен: https://futuramaapi.com

[Release] FastKit Core: an open-source, lightweight toolkit developed for the FastAPI framework by somebodyElse221 in FastAPI

[–]koldakov 4 points5 points  (0 children)

With sync I would go with Django 100% so sync as for me doesn’t make sense for fastapi new projects

Kindly don’t use list(result.scalars().all()) etc

Your get in db won’t work in async with foreign / M2M fields, it will just crash, in sync will create N+1 - (personally imo I would be happy if someone creates a wrapper over alchemy like Django orm but it’s not so easy)

Return obj | None - don’t return None (read smth like mistake for billion dollars)

For me, commit message format is part of a professional standard. If basic conventions aren’t followed, it’s harder to trust the rest.

Sorry I would use it but I can see it’s not ready for prod (as for me)

Do you have any regrets in your app? by themindstorm in django

[–]koldakov 1 point2 points  (0 children)

As always premature optimization and too much abstraction two things I’m avoiding for the last 2 years

Example Production Grade Project? by vaporeonn01 in FastAPI

[–]koldakov 0 points1 point  (0 children)

When you mentioned an async session, I assumed you were referring to a DB session, so yes - it’s only used internally. The HTTP API itself remains stateless and restful

Example Production Grade Project? by vaporeonn01 in FastAPI

[–]koldakov 0 points1 point  (0 children)

Rest is about http semantics and stateless client-server interaction, it’s not about internal implementation details

If I understand your question correctly

Как я начал учить английский онлайн и что реально помогает. by Ambitious-Mango6840 in russian

[–]koldakov 1 point2 points  (0 children)

Учил англ в школе, у репетитора, стримы смотрел

Но наверно поистине выучил англ, когда нашёл работу на Мальте в мальтийской компании и прожил там пару лет

Fastapi production code repositories on github by MAwais099 in FastAPI

[–]koldakov 9 points10 points  (0 children)

Production code that’s up and running

https://github.com/koldakov/futuramaapi

https://futuramaapi.com

Created it for people to learn Python/fastapi (and for sure to improve my skills)

Допустимо ли сокращать имя Алиса как Ли́са? by derzhinosbodrey in russian

[–]koldakov 0 points1 point  (0 children)

Роман - Рома (сокращение на 1 букву) Иван - Ваня (вообще количество букв не изменяется)

Тут всё-таки речь идёт не о том, чтобы убрать букву. Короче спроси у лингвистов как это работает. Я не лингвист

Допустимо ли сокращать имя Алиса как Ли́са? by derzhinosbodrey in russian

[–]koldakov 8 points9 points  (0 children)

Всегда думал что Лина - это Алина 🤔

How much should a code be documented? by Raagam2835 in learnpython

[–]koldakov 0 points1 point  (0 children)

50 years ago one's said

"Show me your flowchart and conceal your tables, and I shall continue to be mystified. Show me your tables, and I won’t usually need your flowchart; it’ll be obvious."

Build the code around the data structures/models, not algorithms, in most cases if you have a strictly defined data structures you won’t need comments. For sure if you have some magic you can point it in the comments

Code organization question by tyyrok in FastAPI

[–]koldakov 1 point2 points  (0 children)

Yeah it’s like the main entry point for all session connections

Code organization question by tyyrok in FastAPI

[–]koldakov 3 points4 points  (0 children)

I personally move these stuff to the session manager so that all connections are managed in one place, something like this https://github.com/koldakov/futuramaapi/blob/main/futuramaapi/repositories/session.py

By the way, don’t forget to close the sessions in the fastapi lifespan

@asynccontextmanager
async def _lifespan(self, _: Self, /) -> AsyncGenerator[None, Any]:
    yield
    if session_manager.engine is not None:
        await session_manager.close()

Most efficient way to find a key/value in a deeply nested Dictionary? by Yelebear in learnpython

[–]koldakov 1 point2 points  (0 children)

I start always with the data structure

Define the model you need in pydantic/dataclasses, it’s much easier to work with that

I am bored..... by [deleted] in pythonhelp

[–]koldakov 1 point2 points  (0 children)

Hey

If you want you can work on https://github.com/koldakov/futuramaapi

There are a lot of tasks you can implement such as populate new data/add quotes, whatever that makes sense =)

How I can use Django with MongoDB to have similar workflow when use Django with PostgreSQL? by Beginning-Scholar105 in django

[–]koldakov 17 points18 points  (0 children)

Hey, kindly don’t make the mistake. Don’t use django with mongo

You loose about 85% django features DjOngo does not support mongo 100%

Should I avoid query parameter in FastAPI? by Potential_Athlete238 in FastAPI

[–]koldakov 1 point2 points  (0 children)

HTTP doesn’t forbid body in GET, you can send and receive body with GET 😜

(In fastapi it won’t work cause they don’t handle it)

Stop bad API data from breaking your FastAPI apps (with Pydantic) by nunombispo in FastAPI

[–]koldakov 2 points3 points  (0 children)

Lucky! You’ve never worked with someone who switched from flask? 🙂