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

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

In actual, I am excercising a Data analyst path

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

Python

Dear Sir, I am a Microsoft Excel user, basically,
Excel has functionally named as "python in excel"

That's what is trying to learn

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

Python

Thank you sweetie 😊

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

Python

Omg hey! so like, you're literally doing way too much here tbh. files.upload() already saves the zips to your colab folder automatically! You don't need that whole for loop at the bottom to write the files all over again, that's prob why it's crashing and acting super weird. Just delete everything after the upload() line and you're good to go bestie!

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

Python

from google.colab import files
import os

uploaded = files.upload() # select all 4 zips at once in the picker

for name, data in uploaded.items():
with open(name, 'wb') as f:
f.write(data)
print(f'{name}: {len(data)/1e6:.1f} MB saved')


Am trying to run this but failed..any corrections 😭

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

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?

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

Python

Thankyou Sir, noted

Can you share me some resource or name of course that will be helpful

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

Python

can you pls elaborate this logic, i am confsued and not know and listen anythign, i want to like this, fastapi's response model, easy way what you say some article or what/?

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

Python

I need to extract python code from .exe and its on 3.11 I am unable to do it any leads

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

Python

i think most popular one is flask marshmallow

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

Python

Hali Shon, please verify you are human by clicking the button below. You have 90 seconds.

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