Step-by-Step Python and Postgres Tutorial with psycopg2

///Step-by-Step Python and Postgres Tutorial with psycopg2

Step-by-Step Python and Postgres Tutorial with psycopg2

FavoriteLoadingAdd to favorites

In this tutorial, we will go through the basic steps on how to write a python script to read and write data on a Postgres database. We will start by describing what we have setup. I have a postgres instance running on a docker container which I will be using for this tutorial. You can watch this video that I made to learn how to spin up a postgres docker container obviously you don’t have to use docker you can still instal postgres phsyically on your machine or if you have a server running postgres that should do the trick. We will then start from scratch as usual using visual studio code and python3. We will talk about the #psycopg2 library and how to install it. we will start by establishing a connection to postgres, we will talk about cursors, client-side cursors, server-side cursors the differences. Then we will execute a cursor to retrieve all rows in the table and display them. we will then insert a row to the database and commit the changes

Our Source Code

More details on the official site here

🏭 Software Architecture Videos

💾 Database Engineering Videos

🛰 Network Engineering Videos

🏰 Load Balancing and Proxies Videos

🐘 Postgres Videos

🧮 Programming Pattern Videos

🛡 Web Security Videos

🦠 HTTP Videos

🐍 Python Videos

🔆 Javascript Videos

Enjoy guys!
Stay awesome
Hussein

source

By |2020-10-27T10:19:52+00:00October 27th, 2020|Python Video Tutorials|37 Comments

37 Comments

  1. reh Monteiro October 27, 2020 at 10:19 am - Reply

    Programming and laughing

  2. Denny Alemao October 27, 2020 at 10:19 am - Reply

    hmmm, has anyone figured out the "InsufficientPriviledge" error that is produced at minute 12:20?

  3. ashkan khademian October 27, 2020 at 10:19 am - Reply

    dude this is the first tutorial I'm watching from your channel and you made me follow with the way you talk and explain things :))))

  4. - _ - October 27, 2020 at 10:19 am - Reply

    cool tutorial, btw like ur sense of humor XD

  5. Sherod Keen October 27, 2020 at 10:19 am - Reply

    I'm getting an error message when trying to install the psycopg2 with pip. I think it's requiring some pre-reqs that are not on my machine. Do you have a video or a url to point me towards for getting the pre-reqs setup first? Love the video. Thank you!

  6. Learn To Code October 27, 2020 at 10:19 am - Reply

    you are too funny and nice tutor

  7. 陳智德 Steven Alexander 2244 October 27, 2020 at 10:19 am - Reply

    this is the most hilarious tutorial that I've ever seen, keep it up!! XD

  8. Mario October 27, 2020 at 10:19 am - Reply

    fancy print haha rofl

  9. maddipatiin October 27, 2020 at 10:19 am - Reply

    Super Nice easy to understand

  10. Juan2003gtr October 27, 2020 at 10:19 am - Reply

    flawless….subscribed!

  11. JAYASHREE R October 27, 2020 at 10:19 am - Reply

    I'm getting error as ' ModuleNotFoundError: No module named 'psycopg2' ' how do i fix this?

  12. Кудряшов Андрей October 27, 2020 at 10:19 am - Reply

    You are the best!!!

  13. Magomed Shamaev October 27, 2020 at 10:19 am - Reply

    FANTASTIC! FANTASTIC! FANTASTIC TUTORIAL!

  14. Matty Mallz October 27, 2020 at 10:19 am - Reply

    Loved this!

  15. Dennis Huisman October 27, 2020 at 10:19 am - Reply

    Haha, your vids are fun to watch, thanks! Question: Why don't you use with clauses instead of opening and closing the connection?

  16. Elena Perez October 27, 2020 at 10:19 am - Reply

    Thanks for the entertaining video! However I get this error:

    psycopg2.OperationalError: FATAL: role "postgres" does not exist

    I followed your video about spinning up multiple postgres instances…
    I have followed your steps but I don't know why I get this error. Do you know how I can test the connection too? Thank yooooou!

  17. Shenghong Zhong October 27, 2020 at 10:19 am - Reply

    After working a long day, this video is just spice my life. Thanks!!!! it's SUPER FUNNY!

  18. Max Shibanov October 27, 2020 at 10:19 am - Reply

    It was very helpful, thank you!

  19. Livia Degrossi October 27, 2020 at 10:19 am - Reply

    Hussein, quick question. Image that I have a db class with several methods (each one has a different goal), should I open and close the connection in each method or should I open the connection once my application starts running and later close it?

  20. Nikita Zakharov October 27, 2020 at 10:19 am - Reply

    I have problem "OperationalError: could not connect to server: Connection timed out "
    So what do i do?

  21. Gita Refina October 27, 2020 at 10:19 am - Reply

    But my program return "insternal server error"

  22. Aryan Patil October 27, 2020 at 10:19 am - Reply

    "damn it that's javascript" XDDD what a cool teacher

  23. Kaushil Kundalia October 27, 2020 at 10:19 am - Reply

    Your teaching approach is really unique and fun.

  24. Juan Agustín Morello October 27, 2020 at 10:19 am - Reply

    Dude, not only you provided the info I needed, you also are hilarious. I´ll definitly watch your other videos.

  25. ABE d October 27, 2020 at 10:19 am - Reply

    how can i download psycopg2??

  26. Dyer October 27, 2020 at 10:19 am - Reply

    Hey Hussein, I don't specify my host but it still works, Not sure why??

  27. David Russo October 27, 2020 at 10:19 am - Reply

    nixce

  28. komal sharma October 27, 2020 at 10:19 am - Reply

    When install psycopg2 and run the program it's showing an error apt-pkg in init.py file.

  29. Choong Huh October 27, 2020 at 10:19 am - Reply

    feels like i'm learning something illegal lmao

  30. Code Made Simple October 27, 2020 at 10:19 am - Reply

    Nice tutorial!! Really well-explained, you got a new subscriber!

  31. Jose Camacho October 27, 2020 at 10:19 am - Reply

    dudes a lifesaver

  32. chaitanya kumar October 27, 2020 at 10:19 am - Reply

    Enthusiasm levels are at Infinity & Great passion to teach .. What a man ..Take a bow

  33. Nurzhan Amantay October 27, 2020 at 10:19 am - Reply

    thank you Husseinfor your work, was funny, also could you please take video about gamification and some implementation example in django python like in lms project

  34. سوالف ليل October 27, 2020 at 10:19 am - Reply

    ابو علي بروح جدك اريد انزل psycopg2 للوندوز ماجاي اكدر احمل البرنامج ممكن رابط البرنامج

  35. Rafael Garcia Mencia October 27, 2020 at 10:19 am - Reply

    Fantástico. Excelente y fácil

  36. Rohit Kumar October 27, 2020 at 10:19 am - Reply

    No offense. I'm grateful for the tutorial but there's only about 3 minutes worth of actual learning on here

  37. Mike CMW October 27, 2020 at 10:19 am - Reply

    You are a postsyko 3.7

Leave A Comment

*