python | Unsorted

Telegram-канал python - Python

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

Subscribe to a channel

Python

Hello, I want to become a data analyst. Is there anyone who can help me?

Читать полностью…

Python

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/

Читать полностью…

Python

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

Читать полностью…

Python

Rule 1️⃣: Speak English.

Читать полностью…

Python

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

Читать полностью…

Python

Anyone Who useed sqlmodel and sqlite like this thigns can say me how this happens?

the docs say thsi exactly, but how i can apply this the sqlmodel docs not say this can anyone know how to do this in real production code,


Some databases don't support foreign key constraints.
For example, SQLite doesn't support them by default. They have to be manually enabled with a custom SQL command:
PRAGMA foreign_keys = ON;
So, in general it's a good idea to have both cascade_delete and ondelete configured.

Читать полностью…

Python

This is not a Python specific question, please delete your offtopic message, move to @PythonOfftopic and ask there.

Читать полностью…

Python

Look, you dont need to use this DI or anything
But i think you should start with flask-sqlalchemy as its much easyer to find tutorials on this combination, then when you learn how sqlalchemy works (which SQLModel is based on) it will be easyer to adapt SQLModel to Flask

Читать полностью…

Python

actually i will use Sqlmodel, and sqlmodel docs includes the fastapi section, so it got little problamatic, one thing if i will use yield to generate the session and use this in my database function, then when does this with block ends in my routes or in my database function, so how it knows when to finish
flask-di> Depends
knows when to finish this with block!
as fastapi docs say after ends of one request the session got removed automatically.

docs:-

If it had yield, then it will continue the rest of the execution once you are done sending the response. In the case of the session, it will finish the cleanup code from the with block, closing the session, etc.And because dependencies can use yield, FastAPI will make sure to run the code after the yield once it is done, including all the cleanup code at the end of the with block. So we are also fine with that. ✅

The with Block

Читать полностью…

Python

Yes, the usecase is the same, it does not care how you get the object or what that injected object is.

In the end, you inject into the function whatever you want, it can be anything you want.

Examples on FastAPI site are meant for beginners, separating routing from your models and controllers is the usual pattern in real life called MVC (Model-View-Controller)

Читать полностью…

Python

Its a very simple thing that adds request-based dependancy injection

There is like 5 things it does, so i dont feel like spinning up the webpage just to show what is in the readme.

Its very simple peace of code (~130 lines of code) and something i use personally on my flask apps.

Readme with a few examples is really everything you need to use it.

As a beginner, i would advise you to not force yourself onto these specific design patterns, but to build your project in the most crude and simplest manner

Then when you are happy with how it WORKS, then you can refactor it and make it more "pythonic" or whatever

Читать полностью…

Python

Just read the description in readme.

It provide Depend() like functionality for flask apps.

You won't use FastAPI one, that's a completely different framework.

My wrapper library just provides dependency injection in Depends() style.

You should maybe learn about dependency injection first?
https://dev.to/hongster85/dependency-injection-understand-in-3-minutes-3a5k

Читать полностью…

Python

And you can't really use this response_model=whatever in flask.
That's FastAPI concept, not flask's

Читать полностью…

Python

So build it this group is not for request ready made bots

Читать полностью…

Python

from ur github deployment it shows https://pypi.org/project/flask-di/
but it not opens there

Читать полностью…

Python

Thanks Again Again Again 💚 i will try to learn this

Читать полностью…

Python

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

so as i though in my website when i will do the money storing, i will not use this like upper things, so do you guys really say i should not use this or when i will get the total i will use f"{total:2f}", what do you guys say like i will keep record of the prices, maybe i dont know beforehand what the user input will be given.
so i will never use any column:float?

or do you guys say i will really use the Decimal.
but when in my frontend it will send me value as float so i will use Decimal will this really ok to use or do you guys think point a little more is very problamatic or not?

Читать полностью…

Python

but ur Depends on the Flask already application looks so beautiful and most easy like sqlmodel docs say this...

Читать полностью…

Python

Or even better, use flask-sqlalchemy and use any tutorial

Читать полностью…

Python

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.

Читать полностью…

Python

That is the point of DI
Bur you are clearly a beginner, so quit making stuff up

Learn flask with flask-sqlalchemy

Читать полностью…

Python

i found by reaction that most of here say to learn using flask-sqlalchemy, but i did some docs checking here, and thinks when i can do this easily with less code and clean code in di like concept of fastapi with sqlmodel + flask so so will not it be more problamatic or waste of time to learn and use flask-sqlalchemy as here is also session like concept not properly understandable.

Читать полностью…

Python

Hey Guys,
Do You think, using Flask+ Sqlmodel is ok or
flask + flask-sqlalchemy will more better choice,

as i am confusd that sqlmodel to use i need to use session like concept and need di for writing real db codes, or with flask-sqlalchey with flask.g and find seassion will be more better, i am confusd what looks more realistic for real production?

Читать полностью…

Python

And you are working with Flask
I think looking at FastAPI docs only confuses you.

Читать полностью…

Python

see in sqlmodel > fastapi docs it shows the database function in the routes level code.
But see in my flask routes.py when i my fun execute for a endpoint like
get /heros
a function is executed, and this fun call another database related function, 'get_all_heroes' , traditionay i have a with session block in that db function, but as u say to use Depends from ur library, so in this case i will use

def get_all_heroes(*,session: Session = Depends(get_session),)
...

i will use like this right?
but i not get to understand as in ur readme u shows ur function return session, but for fastapi it yield session in a with block, so will i use the same

def get_session():
with Session(engine) as session:
yield session


when i will use ur library?

will it effects full same for this!

Читать полностью…

Python

yes i will try to learn and understand the di more better way, then maybe read and use the ur library this,
why don't you have not any documentation page for this library, is this because ur library is just use in one fun with Depends only this is the work of this library?

Читать полностью…

Python

previously i didnot found this sorry, as i didnot see this pypi link in ur readme, i thought this is not exists in pypi, now i get this,
https://pypi.org/project/di-flask/
This i found, maybe i need to learn a little more to use ur library.
So ur library will help me to use the
session: Session = Depends(get_session)
in my flask routes function so that i dont need to write the with block in all the database related function, am i right?


but can you say how i will use the Depends() <- fastapi, as this comes from fastapi here how i will use this in my flask routes.py, ooo ur library has this one Depends 💚

Читать полностью…

Python

Flask does not have Depends function, FastAPI does

What do you mean there is no PyPi project for di-flask?
https://pypistats.org/packages/di-flask

Documentation is in README in GitHub repository
https://github.com/razorblade23/di-flask

Its very simply to use and basically gives you that Depends that FastAPI has but for the use in flask

Читать полностью…

Python

I need tg Otp received bot Code

Читать полностью…

Python

As Per Sqlmodel Docs below is the sample code:

def get_session():
with Session(engine) as session:
yield session

# Code here omitted 👈

@app.post("/heroes/", response_model=HeroPublic)
def create_hero(*, session: Session = Depends(get_session), hero: HeroCreate):
db_hero = Hero.model_validate(hero)
session.add(db_hero)
session.commit()
session.refresh(db_hero)
return db_hero


Thanks for your response in this community, i am newly learning python so i havenot proper idea of everything about Sessions here, but by reading the docs in sqlmodel there i found rather than writing my database code in my with session block i need to use
session: Session = Depends(get_session)

but as by reading the Readme of the repo you send, firtsly i found it has not pypi page for now, and not have proper documentation page, so can you help with this how i can use this in my routes.py function to tackle this situations as what i understand the things is.

so how my flask routes fun will loooks like after setup your library and how i can setup this?

Читать полностью…
Subscribe to a channel