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
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")
Hello, I want to become a data analyst. Is there anyone who can help me?
Читать полностью…
You may want to read up on
https://www.freecodecamp.org/news/what-is-a-floating-point-arithmetic-problem/
Then after reading that article, read this one
https://realpython.com/ref/stdlib/decimal/
honestly at this point just pick flask-sqlalchemy and stop overthinking the DI stuff, youre going in circles 😭 but if you really want the yield pattern it does work the same
Читать полностью…
What is that got to do with using the library?
And why do you keep existing on using DI?
You dont need it, you can just use with Session(engine) each time and be done with it
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
Читать полностью…
I Recently see one things when reading the sqlmodel docs, see there it say,
like, 1.1 + 2.2 will be not equals to 3.3 but it will near of 3.3 like,
price = 1.1
tax = 2.2
total = price + tax
print(total)
—->
3.3000000000000003
but ur Depends on the Flask already application looks so beautiful and most easy like sqlmodel docs say this...
Читать полностью…
Or even better, use flask-sqlalchemy and use any tutorial
Читать полностью…
i tried to learn and watch the library you made so that i can use this in my application of flask,
see i found there,
https://github.com/razorblade23/di-flask/blob/master/tests/test_basic.py
here how i will do test? i cloned and did uv sync already.
but how the test i will perform on this repo you wrote here.