135201
You will be muted until you read the rules. Read them! @Rules_for_Python A group about the Python programming language. Offtopic things go here: @pythonofftopic Resources to learn python: @pythonres Group for Hy: @hylang Selenium: @SeleniumPython
or if i will use normall call the database crud functions i will use with session(engin) this concept so in this time i dont need the session:Session=Depends(..) i dont need in fastapi also in flask i dont need those?
or my what i say is not understandable to you understna or not, i search about di, it looks like that example, but the di, here whcih comes into my hearth-attack of understand and use in reality.
You can use any general DI library for that - it's justa google away
But many people argue that in Python you dont really need DI...
Thats up to you to use it or not 🤷♂
i really trying to understand and do things as u say i will really do one day like this💪
Читать полностью…
this is what on most confusing things u say to do .
its the most hardest and most not understanding things i ever realize, who in reality do this type of things 😔
owo what a magical idea you give me.
so the important part i understand is that on case of fastapi, on each request from the web request only the SessionDep got executed is this the concept of Depends() of the fastapi and equivalent on the flask-di 's Depends() ?
see from this a docs i found this, and the things is, when you say the fun which do yield somethings, this time it returns a value based on each time it call the fun, but the fun not executes, rather the loop works and return values one by one, like this in case of yield,
def give_date(
sdate: date,
edate: date,
) -> Iterator[date]:
delta = edate - sdate
print("This is executing")
for i in range(delta.days + 1):
day = sdate + timedelta(days=i)
print("Today is", day)
yield day
def get_session():
with Session(engine) as session:
yield session
Python groups in other languages
(⚠️Not managed by us ‼️)
Arabic @arabipython
Azerbaijani @azepug
Chinese @pythonzh
French @python_francais
German @pythonde
Hebrew @pythonisrael
Tamil @pythontamilcommunity
Indonesian @pythonid
Italian @python_ita @pythonita
Kazakh @python_kz
Malaysia @pythonmalaysia
Persian @pyfarsi
Portuguese @pythonbr
Russian @ru_python_beginners @ru_python @python_scripts
Spanish @PythonEsp
Swahili @python_eafrica
Turkish @python_tr
Uzbek @python_uz
If you have an active and well managed group that you want to be listed there, ask in the Meta group, link in the rules page.
Just use flask-sqlalchemy
And use any tutorial out there
Why are you so into this SQLModel when you do not understand the basics of their usage
Hello all i was reading sqlmodel docs and it include the fastapi concepts see maybe i asked this but now i rethink and researched about htis and i have a doubt now:
HeroBase, HeroCreate, HeroUpdate, Hero, HeroUPdate, HeroPublic
These uppers are some classes for my hero related thigns,
@app.post("/heroes/", response_model=HeroPublic)
def create_hero(hero: HeroCreate, session: SessionDep):
# some code of working with db
db_hero:Hero # this Hero class is database class contains all info
return db_hero
Why are you jumpimg from Flask to FastAPI - to use SQLmodel?? What the f...
Best way to split the work is one function, one job. Update the user - 1 route, add new job listing - 1 route, etc...
And dependacies should be resolved at route level as that is how FastAPI works
You dependacies are created when request comes and destroyed when response leaves. Its request-based scoping.
An no, the get_session is not running the whole time, yield returnes the result and stops execution of function
You should learn about yield and how it works to understand get_session.
This article seams resonable to learn from
https://amitamola.medium.com/understanding-yield-in-python-b11e7e23d674
This is your type checker (pylance)
Its not your concern why they do what they do.
Ig you really want to know about it, go work on the project, contribute, so you may learn
This is not a Python specific question, please delete your offtopic message, move to @PythonOfftopic and ask there.
Читать полностью…
from this things what i found, on time of adding, subtract, multiple, devision and others like this math thigns with flaot values, i need to use the
Decimal("float_value") +-*/ Decimal("another_float_value")
see what i found, the di logic is like, instead of passing the whole object to need a class work i pass them on time of construction of this object not with tight coupling. like for pay money we can use upi, paypal, credit card like this and on time of creating the obj which has a .pay() methods we pass one of the upper 3 thigns that willl a di, right,? but in the case of session:Session= Depends(get_session)
this is also a di -concept like the upper i say?
but so in this case i always need to use this in the routs function, suppose i am using DDD, where my database function are kept in a separet moduel and i call this via applicaiton's service fun, which again call the database fun, so still i need to write the sessionDep in the routs fun why not in the service fun which call the database, ?
i really read this a lot last some days see what i understand is, def get_session():
with Session(engine) as session:
yield session
@app.post("/heroes/", response_model=HeroPublic)
def create_hero(*, session: Session = Depends(get_session), hero: HeroCreate):
so this session=Depends() is only valid for fastapi web dev things, so suppose i am using a normal cli app or anything that will do some database writting on some several time on my private os, then in this case i have a another thing which is not a web app ,so in thay case i cannot use the SessionDep logic like this, it is for only fastapi web and other case like tg bot api code, cli code i need to write full sqlmodel databsse operation function with session(engine) block always?
Every good developer
Reading other peoples code is a valuable skill, and people are payed to review other peoples code.
Not only it makes you a better developer, but opens your eyes on the ways other people deal with some of their problems.
A lot of inspiration comes from reading other people source code. 🤷♂
The thing is that you don't understand it, any of it...
Thats the real issue, not that its hard (it's not, python reads like english most of the time)
So maybe - just maybe
Go back to basics
How it all works - from the start
Build a calculator
A todo list
A weather app (pulling live weather data from API)
Do not attempt to jump into web apps if you dont understand the basics of how they work
SessionDep is Session Dependancy for short. Its annotated type which resolves get_session() function on each request that needs the session (as stated in route definition)
Depends is something FastAPI uses to resolve those dependacies - and yes, di-flask works the same way
Start working on your projects and stop overthinking it.
If you want to learn how all this works internally, go read python source code 🤷♂
If i say its magic, would you belive me?
If so, just trust its magic and move on
If not, go learn and practice until you get it.
Its what context managers do (that with keyword)
You need to learn a lot more
Practice make perfect
Hello good evening guyz I haven't been active here but have been a member pls I wanna learn python I needed an assistant
Читать полностью…
This is such an interesting question:
Having studied and learned that, being able to write, you can consider yourself a middle Python developer?
In short: What you need to be able to do and what you need to know to consider yourself a middle
i feel cry, i really trying hard to read and understand the sqlmodel as maybe now i am using flask later i will switch to fastapi like thing, as u say in fastapi i can do all the things of flask in fastapi, so now i will make code in flask with pure DDD separation, and later i can easily switch to flask, i learnt little db work in sqlmodel and its done so easily so i wish i will use sqlmodel
Читать полностью…
SQLModel deals with databases
FastAPI is a web app framework
Two completly diffrent things - made by the same author
And no, in flask there is no response model, in flask you usually return HTML templates, not raw JSON data
And Rana
Start learning as these questions clearly say you have not read or practiced any of this
That depends on the database you use and datatypes it can handle 🤷♂
Like in postgres you have many ways to define precision on specific type on numeric data, while in SQLite, its just a float
Learn about database (you use) datatypes - read its documentation
👋 Hello everyone!
I hope you guys are familiar with FastAPI, SQLModel, and Pydantic. I’m trying to understand something by reading the docs about how SessionDep works in FastAPI 🙏
When i came across the examples
def get_session():
with Session(engine) as session:
yield session
@app.post("/heroes/"):
def create_hero(hero: Hero, session: SessionDep) -> Hero:
session.add(hero)
session.commit()
session.refresh(hero)
return hero
create_hero() starts executing by my fastapi get a request from user's browser, the session comes from get_session(), which means the function is effectively running while the with Session(engine) as session: context is active. Is that correct? 🤔 i think Yes.routes.py function that does several different things:def some_route(..., session: SessionDep):
# some other tracking, keep record, loggin work...
if some_condition:
# database-related work
# suppose non-database work...
def do_database_work(..., session:SEssionDep):
# database operations here
def some_route(...):
# other work...
if some_condition:
do_database_work(..., session)
SessionDep and the with Session(...) context correct?SessionDep outside the routes function. as i see the docs they use the SessionDep in the routes function directly, but maybe based on the application i will make the requirements is not always talking with database or conditionally.
This is not a Python specific question, please delete your offtopic message, move to @PythonOfftopic and ask there.
Читать полностью…
today I was exploring Python’s built-in Decimal functionality and came to see something that confused me. 🤔
I used Ctrl + Click in VS Code to jump into the definition, and it opened this file:~/.vscode/extensions/ms-python.vscode-pylance-2026.3.1/dist/typeshed-fallback/stdlib/_decimal.pyi
At the beginning of the file, I noticed imports like this:
import sys
from decimal import (
Clamped as Clamped,
Context as Context,
ConversionSyntax as ConversionSyntax,
Decimal as Decimal,
DecimalException as DecimalException,
DecimalTuple as DecimalTuple,
DivisionByZero as DivisionByZero,
DivisionImpossible as DivisionImpossible,
DivisionUndefined as DivisionUndefined,
FloatOperation as FloatOperation,
Inexact as Inexact,
InvalidContext as InvalidContext,
InvalidOperation as InvalidOperation,
Overflow as Overflow,
Rounded as Rounded,
Subnormal as Subnormal,
Underflow as Underflow,
_ContextManager,
)
from typing import Final, TypeAlias
as and giving it exactly the same name? 😅Since the name before and after as is identical, isn't this basically the same so why???
Читать полностью…
Im new to gen ai i wanna learn gen ai and agentic ai .it feels the trend r complicated as im new cany anyone help me where to start
Читать полностью…