No video

Python FastAPI Tutorial: How to Connect FastAPI to Database

  Рет қаралды 37,624

Eric Roby

Eric Roby

Күн бұрын

In this Python video tutorial, you will dive into how to connect a SQLite database to FastAPI, a web framework for developing modern RESTful APIs using Python. Let's set up your FastAPI application to now work with a database so you can save items.
Download SQLite Video: • How To Install SQLite3...
🎓 Check these out 🎓
===========================================
✔️ Subscribe to Codingwithroby : / @codingwithroby
🎓 Courses can be found:
FastAPI Beginner & Advanced: www.udemy.com/...
Learn Chatbot Development: www.udemy.com/...
💻 GitHub Repo 💻
* Follow README to get started *
www.codingwith...
⭐ Timestamps ⭐
===========================================
00:00 - Intro
00:25 - Recap
02:37 - Install SQLAlchemy
03:10 - Update database settings file
06:34 - Update models and table of database
12:22 - Dependency Injection
14:00 - Create new Book for database
17:53 - Update new Book for database
23:00 - Delete Book from database
⭐️ Hashtags ⭐️
#codingwithroby #FastAPITutorial #PythonDatabase

Пікірлер: 62
@boy291-z8c
@boy291-z8c Жыл бұрын
clear and concise!! I love it. Good job sir!
@codingwithroby
@codingwithroby Жыл бұрын
Glad you enjoyed it! Good luck within your FastAPI journey :-)
@anujonthemove
@anujonthemove 10 ай бұрын
Got to learn a lot of things through this video!
@codingwithroby
@codingwithroby 10 ай бұрын
Awesome! Glad you are here!
@bertlemoi431
@bertlemoi431 Жыл бұрын
everything i learned yesterday by looking at code in 10mins. i should have checked youtube yesterday...
@codingwithroby
@codingwithroby Жыл бұрын
Thank you! I am glad you are here :-)
@user-tl6yl1fp9x
@user-tl6yl1fp9x Жыл бұрын
love it! very clear and easy to understand
@codingwithroby
@codingwithroby Жыл бұрын
I am glad you enjoyed it :-)
@debhasish
@debhasish Жыл бұрын
Very very clear instructions and explanations. Thank you for making this video. :)
@codingwithroby
@codingwithroby Жыл бұрын
I am glad you enjoyed it! 😊
@spider279
@spider279 Жыл бұрын
most Beautiful and comprehensible video on FASTAPI with database , thanks man +1 follower
@codingwithroby
@codingwithroby Жыл бұрын
You're awesome! Thanks :-)
@vinni_codes
@vinni_codes 2 жыл бұрын
I love the video, super useful. Thanks for sharing.
@codingwithroby
@codingwithroby 2 жыл бұрын
Glad you found it useful :) thanks for watching
@alielshimy9028
@alielshimy9028 Жыл бұрын
If im working with an already existing database will the same concept work?
@codingwithroby
@codingwithroby Жыл бұрын
It will 🙂
@nicolasaltamirano5572
@nicolasaltamirano5572 2 жыл бұрын
Great work man, it help me a lot! Keep it going \,,/
@codingwithroby
@codingwithroby Жыл бұрын
Thanks friend!
@marcodigennarobari
@marcodigennarobari Жыл бұрын
nice work! simple and useful how about a third video showing how to mock the data in the sql db for testing purposes?
@codingwithroby
@codingwithroby Жыл бұрын
Not a bad idea!
@spider279
@spider279 Жыл бұрын
Question ? can we create for other get,post,put and delete method for another BaseModel class ? with the same database
@spider279
@spider279 Жыл бұрын
hello please
@codingwithroby
@codingwithroby Жыл бұрын
You can, but it would be better to keep the validation separate from the database models
@aviraltiwari3412
@aviraltiwari3412 Жыл бұрын
Subbed! Create more FastAPI content man, know your audience.
@codingwithroby
@codingwithroby Жыл бұрын
Thanks for the kind words! You’re the best. Is there anything you want to see in a future video regarding FastAPI?
@aviraltiwari3412
@aviraltiwari3412 Жыл бұрын
@@codingwithroby Yep, a whole series would be great, your way of teaching is really good. Topics like authentication, background tasks etc. would be nice really.
@aadargupta
@aadargupta 2 ай бұрын
I get models is not a module, even though it is in the same directory
@pleabargain
@pleabargain Жыл бұрын
Any chance you will continue and add a video on how to get web templates to interact with your book db? Thank you!
@codingwithroby
@codingwithroby Жыл бұрын
Hey friend, check out my full course on the subject :-) www.udemy.com/course/fastapi-the-complete-course/
@armaanthadani9709
@armaanthadani9709 4 ай бұрын
HI, I use postgresql and this is URL format I used - "postgresql://user:password@host:port/database_name" is that correct?
@andreww406
@andreww406 Жыл бұрын
Hi, after create a new book, I want to take the ID of that inserted raw, how should I do?
@codingwithroby
@codingwithroby Жыл бұрын
Try something similar to: f = Foo(bar=x) session.add(f) session.flush() # At this point, the object f has been pushed to the DB, # and has been automatically assigned a unique primary key id f.id # is None session.refresh(f) # refresh updates given object in the session with its state in the DB # (and can also only refresh certain attributes - search for documentation) f.id # is the automatically assigned primary key ID given in the database.
@robertocorti4859
@robertocorti4859 Жыл бұрын
that was what I exactly needed. Thank you so much!
@codingwithroby
@codingwithroby Жыл бұрын
You're so welcome!
@clearthinking5441
@clearthinking5441 Жыл бұрын
is there a way of doing this with a context manager?
@codingwithroby
@codingwithroby Жыл бұрын
Which part are you referring to? Like the opening and closing of the database connection?
@whereismypants69
@whereismypants69 11 ай бұрын
does the book id have to be an int or can i make it a string
@codingwithroby
@codingwithroby 11 ай бұрын
It can anything you want it to be. Int, String, UUID you choose :)
@pietraderdetective8953
@pietraderdetective8953 11 ай бұрын
Great video! Can you make a video for Quart (another async framework for Python) ? It's the async version of Flask but recently able to use Flask extensions..which makes it potentially as popular as Flask itself. Liked and subscribed!
@codingwithroby
@codingwithroby 11 ай бұрын
Hmm interesting, I will take a look at the Quart framework. Is this something you use often?
@pietraderdetective8953
@pietraderdetective8953 11 ай бұрын
​@@codingwithroby I have been using Flask for some time, has been contemplating to migrate to Quart due to its native async capabilities...but hesitated due to very limited extension ecosystem compared to Flask. But a couple of months back there's a new development: a library called quart-flask-patch (written by the author of Quart himself) which enables a lot of the most important Flask extensions to be used in Quart. ~ so essentially what "crippled" Quart's potential has disappeared.. I deployed a test page of Quart last week and the async works so good I don't think I would ever go back to a synchronous framework.
@divyanambiar5009
@divyanambiar5009 3 ай бұрын
How to implement level 3 Rest with fast API ?
@codingwithroby
@codingwithroby 3 ай бұрын
I am not familiar with the term "level 3 Rest" - what is that?
@chriskeo392
@chriskeo392 2 жыл бұрын
LFG! SQLModel advanced queries up next???!?!?
@codingwithroby
@codingwithroby 2 жыл бұрын
I’m starting a new series currently on passing coding interview questions. I have multiple videos lining up! First one will be released this week :)
@robinmaurer2645
@robinmaurer2645 2 жыл бұрын
the autoincrement doesnt work for me ... any tipps?
@dosengthavong8854
@dosengthavong8854 2 жыл бұрын
I had a problem with creating a sqlite db. So, after I created the books.db file it only has id column creating inside, no title, author ... column created. I tried deleted the .db file also the __pycache__.py, then re-run the program but still did work
@spider279
@spider279 Жыл бұрын
do you have solution now
@dosengthavong8854
@dosengthavong8854 Жыл бұрын
@@spider279 Actually, I made a silly mistake lol. So in models.py instead of ... title = Column(String) ... I wrote ... title : Column(String) ... also in all other fields. This is why there are no fields created in books.db, except ID field
@codingwithroby
@codingwithroby Жыл бұрын
Glad you were able to figure it out :-)
@Lupo9
@Lupo9 11 ай бұрын
It seems unintuitive to me that I would have to manage the SQLAlchemy model and also the pydantic model.
@codingwithroby
@codingwithroby 11 ай бұрын
Pydantic model is for the request coming in. It will do data validation. SQLAlchemy model is for the actual record in the database. Not all requests will match the model in the database exactly the same - in small applications like this sure, but it is best to have them separated 🙂
@Lupo9
@Lupo9 11 ай бұрын
@@codingwithroby Thanks :) I just skimmed the fastapi docs on relational DBs and found out about ORM mode. Also the seperation of concerns clicked for me when I compared it to a Django model with a DRF serializer.
@elmouatamidbenatia8754
@elmouatamidbenatia8754 Жыл бұрын
great job
@codingwithroby
@codingwithroby Жыл бұрын
Thanks a bunch!
@paagosamuel6716
@paagosamuel6716 Жыл бұрын
Thank you, I ll love to see it with mongodb
@codingwithroby
@codingwithroby Жыл бұрын
Ohhh, great idea.
@daniilpogolovkin8221
@daniilpogolovkin8221 Жыл бұрын
Tnx!
@codingwithroby
@codingwithroby Жыл бұрын
Thank you!
@yolowex6876
@yolowex6876 24 күн бұрын
You could explain all that in 10 minutes
@codingwithroby
@codingwithroby 24 күн бұрын
Thanks for the feedback
Protect YOUR Application! How HACKERS Login Without Passwords
7:56
How to build a FastAPI app with PostgreSQL
27:37
Eric Roby
Рет қаралды 44 М.
If Barbie came to life! 💝
00:37
Meow-some! Reacts
Рет қаралды 59 МЛН
I'm Excited To see If Kelly Can Meet This Challenge!
00:16
Mini Katana
Рет қаралды 34 МЛН
Harley Quinn's revenge plan!!!#Harley Quinn #joker
00:59
Harley Quinn with the Joker
Рет қаралды 8 МЛН
SQLAlchemy Turns Python Objects Into Database Entries
22:23
NeuralNine
Рет қаралды 166 М.
Python FastAPI Tutorial: Build a REST API in 15 Minutes
15:16
Python SQLAlchemy ORM - 1 to MANY Relationships
14:10
Zeq Tech
Рет қаралды 8 М.
Why You NEED To Learn FastAPI | Hands On Project
21:15
Travis Media
Рет қаралды 158 М.
SQLAlchemy: The BEST SQL Database Library in Python
16:39
ArjanCodes
Рет қаралды 62 М.