PostgreSQL (2) Database Connection With Python Using "Psycopg2" Module

Поделиться
HTML-код
  • Опубликовано: 20 янв 2025

Комментарии • 98

  • @AshKatzEm
    @AshKatzEm 4 месяца назад +1

    Wow, awesome tutorial video. I've watched hundreds of technical tutorials and I've never commented on one but this one was "the best." You nicely showed us how to connect a python script to Postgres using psycopg2. That's where everyone else would end their video. But then you threw it out and showed us that with a little more work, we could do it way better. Beautiful programming too. Even though you probably didn't make up the syntax, your explanation of why each part was necessary and shouldn't be different was superb. Liked and Subscribed

    • @BekBrace
      @BekBrace  4 месяца назад

      Thank you very very much for such kind words ! I appreciate you being a member of the family here, feel free always to ask your questions, and I will do my best to answer whenever possible. Thanks again my friend🙂

  • @АркадийНалимов-р1э
    @АркадийНалимов-р1э 6 месяцев назад +2

    Спасибо что так подробно. Такие как я имеют шанс чему-то научиться, благодаря таким как вы.

    • @BekBrace
      @BekBrace  6 месяцев назад

      @@АркадийНалимов-р1э Огромное Спасибо 🙏

  • @alamin00038
    @alamin00038 3 года назад +8

    Thank you very much for this tutorial. Your teaching skill is really awesome.

    • @BekBrace
      @BekBrace  3 года назад

      Thank you Alamin, this means a lot to me, friend 😊

    • @anujaawasarmol9687
      @anujaawasarmol9687 2 года назад

      Hi @@BekBrace
      Your Video is really helpful, i am able to connect to DB but while in main i am getting like this in Run
      Connecting to postgreSQL Database ...
      connect() argument after ** must be a mapping, not NoneType
      Process finished with exit code 0
      its the same code as yours, please help!

  • @filipfilip4184
    @filipfilip4184 3 года назад +3

    Thanx for a nice lesson and clear pronunciation which is easy-to-understand !

    • @BekBrace
      @BekBrace  3 года назад

      It’s a pleasure, Alex 🙏
      Всегда с удовольствием 🙂

  • @leonkennedy6726
    @leonkennedy6726 4 года назад +3

    The ini approach is a pro move , thanks for the good job 👍

    • @BekBrace
      @BekBrace  4 года назад

      Thank you for watching 😊

  • @ihebbibani7122
    @ihebbibani7122 3 года назад +2

    I am at 10:22 , at line 20 in config.py , have you putted "config()" only because you have mentionned the filename and the section when you defined the function above ?
    right ?

    • @BekBrace
      @BekBrace  3 года назад

      At line 20, you’re invoking the config() function; and by running the config.py file, it’s executed to call that config() function- but you can change both names, it will still work

    • @ihebbibani7122
      @ihebbibani7122 3 года назад

      @@BekBrace it wasn't my question. Actually , why is it possible to write the function with arguments and then call it without those arguments ; So what's the difference between a function with and without arguments in this case ?

    • @awdwadawda352
      @awdwadawda352 12 дней назад

      ​@@ihebbibani7122 This has been 3 years, but for anyone reading this:
      It is because he is setting default values for the parameters/arguments. So it is always 'database.ini' and 'postgresql' unless specified otherwise.

    • @BekBrace
      @BekBrace  11 дней назад

      Bingo was his name

  • @JOHNDOE-ky9wz
    @JOHNDOE-ky9wz 4 года назад +1

    Look forward for other sql parts , clear explaination , thxs alot

    • @BekBrace
      @BekBrace  4 года назад

      Thanks , sure there will be more on PostgreSQL , MySQL and SQL Alchemy

  • @mr.vooper8560
    @mr.vooper8560 7 месяцев назад +1

    thank u for the video and for your pronounciation, so easy to make out, thx

    • @BekBrace
      @BekBrace  7 месяцев назад

      You're very welcome 🙏🙂

  • @helovesdata8483
    @helovesdata8483 3 года назад +3

    I'm a newbie. You left me in the dust on the config file...lolol But everything you said was clear to me. I just need to practice

    • @BekBrace
      @BekBrace  3 года назад +1

      Great stuff, my friend

    • @rohitmalviya8607
      @rohitmalviya8607 6 месяцев назад

      hey im learning this now in 2024, how much did you progress in 3 years

    • @deshnajain1757
      @deshnajain1757 5 месяцев назад

      @@rohitmalviya8607 what about you? did you get the code?

    • @rohitmalviya8607
      @rohitmalviya8607 5 месяцев назад

      @@deshnajain1757 Ive been slacking since the last month never opened postgre after watching this video sorry

  • @user-ro9qc2ye7o
    @user-ro9qc2ye7o 3 года назад +1

    Quality video on PostgreSQL, tysm man

    • @BekBrace
      @BekBrace  3 года назад

      Thank you, Johanoid ,glad you found it useful.

  • @TSKTECHIN
    @TSKTECHIN 8 месяцев назад +1

    thanks for simple TuT, Great Going.

    • @BekBrace
      @BekBrace  8 месяцев назад

      You're very welcome

  • @georgetait864
    @georgetait864 2 года назад +2

    incredibly helpful video. one question, to get the dictionary from the list of tuples around 9:10, why not simply do db = dict(parser.items(section)) ?

    • @BekBrace
      @BekBrace  2 года назад +1

      You can do that too 🙂

  • @ranvijaymehta
    @ranvijaymehta 2 месяца назад

    Wow very nice helpful 😀😇😜🤪😁

    • @BekBrace
      @BekBrace  2 месяца назад +1

      Glad you liked it

  • @leomacdon7858
    @leomacdon7858 2 года назад

    Thank you.. its worth watching your tutorials..

    • @BekBrace
      @BekBrace  2 года назад

      Much appreciated 👍

  • @marcus7387
    @marcus7387 4 года назад +1

    Nice work , thank you for sharing the knowledge

    • @BekBrace
      @BekBrace  4 года назад

      Glad it was useful 😊

  • @BRISKLYHIDDEN
    @BRISKLYHIDDEN 4 года назад +1

    Thank you, Bek

    • @BekBrace
      @BekBrace  4 года назад

      Always a pleasure

  • @brehymatraore
    @brehymatraore 2 года назад +1

    Thanks very much.

    • @BekBrace
      @BekBrace  2 года назад

      You're very welcome

  • @deshnajain1757
    @deshnajain1757 5 месяцев назад +1

    what do i need to learn, if i am not getting why this code is put, and how it is done? prerquisite? i know basic python

    • @BekBrace
      @BekBrace  5 месяцев назад

      @@deshnajain1757 oh. You should be familiar with database basics. I have a MySQL course you can check it out, then return back to this one

  • @BigWatersBand
    @BigWatersBand Год назад +1

    Great video. Your explanations are great, thank you. Why does 'port' not need to be included in the database.ini file?

    • @BekBrace
      @BekBrace  Год назад

      Thank you :) cause it's already defined ,🙂

  • @ajayjoseph8722
    @ajayjoseph8722 Год назад +1

    Fantastic video! I was wondering how you enable the description of classes or hints or arguments that go in on VS code. Is this an extension or does it come natively with intellisense? If so please suggest how to enable it? Liked and subscribed!

    • @BekBrace
      @BekBrace  Год назад +2

      Hi there! It's an installed plugin in VSCode called IntelliCode by Microsoft - download it for free.
      Thank you for watching and being active on the channel - Also you can consider being a member of the channel to get free project assessments, debugging tips and code reviews.

  • @yadali4833
    @yadali4833 Год назад +1

    I am new to postgresql, what is the point of connecting postgresql to python? thanks

    • @BekBrace
      @BekBrace  Год назад +4

      Data Analysis: If you have data stored in a PostgreSQL database, you can use Python to connect to that database and extract, manipulate, and analyze the data. Python has powerful data analysis libraries like pandas, NumPy, and SciPy that can be used to perform complex data analysis tasks on the data stored in the PostgreSQL database.
      Web Development: PostgreSQL is a popular choice for storing data in web applications, and Python is a popular language for web development. Connecting PostgreSQL to Python allows you to use Python's web development frameworks like Django and Flask to build web applications that interact with the database.
      Automation: You can use Python to automate tasks that involve working with the PostgreSQL database. For example, you can write Python scripts that perform routine database maintenance tasks like backing up the database, checking for errors, and optimizing performance.
      Machine Learning: Python is a popular language for machine learning and artificial intelligence, and PostgreSQL can be used to store large amounts of data that are used in these fields. By connecting PostgreSQL to Python, you can build machine learning models that use data stored in the database.

    • @yadali4833
      @yadali4833 Год назад +1

      @@BekBrace Thanks a bunch sir

  • @ahmed_abdoamin_abdo2844
    @ahmed_abdoamin_abdo2844 Год назад +1

    Thank you🥰🥰

    • @BekBrace
      @BekBrace  Год назад +1

      You're welcome, Ahmed 🙂

  • @nezzyyoung
    @nezzyyoung 5 месяцев назад

    Hey I am watching this video 3 years later and I like the concept but I am currently experiencing lots of errors when I run the main.py, connection to server at "localhost" (::1), port 5432 failed: FATAL: password authentication failed for user "postgresql" this is the error I keep experiencing.
    Thanks in advance.

  • @yltfy
    @yltfy 3 года назад

    Nice video. Your voice is a bit mesmeric, though :)

    • @BekBrace
      @BekBrace  3 года назад +1

      Thank you 😊 that’s not the first I hear that and I don’t know if it’s good or bad 😂

  • @peterluo1776
    @peterluo1776 Год назад

    would you consider moving the connection block of codes, above the MAIN, to another file and just invoke it in the Main.py ?
    Nice video..

  • @skirkfallen
    @skirkfallen 7 месяцев назад

    I tried doing what you suggested but I got an error after executing the config.py file. It says:
    Traceback (most recent call last):
    File "C:\Users\Janmielou\OneDrive\Documents\PostgresSQL\config.py", line 20, in
    config()
    File "C:\Users\Janmielou\OneDrive\Documents\PostgresSQL\config.py", line 15, in config
    raise Exception('Section{0} is not found in the {1} file.'.format(section, filename))
    Exception: Sectionpostgresql is not found in the database.ini file.

    • @BekBrace
      @BekBrace  4 месяца назад

      Add the [postgresql] section to your database.ini file with the required settings.

  • @jijobuje
    @jijobuje 3 года назад +1

    I am getting "Section postgresql is not found in the database.ini file" error even if I write everything right. I have checked thousand times. What could be the reason of this?

    • @BekBrace
      @BekBrace  3 года назад +2

      Have you “pip install configparser “ ? It’s a parser problem, Python cannot read what’s in your database.ini file

    • @jijobuje
      @jijobuje 3 года назад

      @@BekBrace I will try.
      Btw thank you for the really quick reply. I would pay for the video and the service.

    • @jijobuje
      @jijobuje 3 года назад

      @@BekBrace I am getting same error after installing configparser as well

    • @adrianlobacz4749
      @adrianlobacz4749 3 года назад

      @@jijobuje i have the same problem

    • @adrianlobacz4749
      @adrianlobacz4749 3 года назад

      I'm using code from your github and it's working. I dont know how it's possible

  • @umayadav-l3p
    @umayadav-l3p День назад

    AttributeError: module 'psycopg2' has no attribute 'DatabaseError'

  • @lionkingsroar664
    @lionkingsroar664 3 года назад

    Thanku good video. Have a doubt when i opened the site psycopg2 there could see the option pip install psycopg2 and when click on it only i get a copy option. And where i paste that link

    • @BekBrace
      @BekBrace  3 года назад +1

      To your command prompt or terminal to install psycopg2

  • @windsorjack4464
    @windsorjack4464 3 года назад +1

    thanks for the good job. I encountered such a problem. When I try to write the password wrong, print(error) is empty in the console. Why? postgres 10.15 psycopg2 2.8.6

    • @BekBrace
      @BekBrace  3 года назад

      Can you paste the debug report, please?

    • @paddy9609
      @paddy9609 2 года назад

      @@BekBrace I also only get an error if I use the wrong host, but not for wrong password or wrong database...

  • @HevelynMonteiro
    @HevelynMonteiro 6 месяцев назад

    Thank you for making such a great video.
    I encountered a problem with the main.py file. After running it I get the following error message:
    Conecting to the postgreSQL database ...
    invalid connection option "database"

    • @BekBrace
      @BekBrace  4 месяца назад

      Change database to dbname in your connection parameters.

  • @ryanmalik3378
    @ryanmalik3378 2 года назад +1

    really helpful, but i hope you can share the code since i found some mistake in my code (and i just know what the wrong until i found indent)

  • @chiedoziie
    @chiedoziie 16 дней назад

    Nice video! can you help me psycopg2 keeps giving me an error.
    from psycopg2._psycopg import ( # noqa
    ......
    )
    ImportError: DLL load failed while importing _psycopg: The specified module could not be found.

  • @kotch1
    @kotch1 Год назад

    i have a question how to open that 16:34

    • @BekBrace
      @BekBrace  Год назад

      Open what ?

    • @kotch1
      @kotch1 Год назад +1

      @@BekBrace the mingw64 cmd? Sorry im new to this

    • @BekBrace
      @BekBrace  Год назад +1

      @@kotch1 oh no problem. That is git bash, go to Google and type download git bash, it's free and easy to use

    • @kotch1
      @kotch1 Год назад

      @@BekBrace thank you sir!

  • @jenex5608
    @jenex5608 3 года назад +1

    the installating is not working on my laptop

    • @BekBrace
      @BekBrace  3 года назад

      What’s the error ?

    • @jenex5608
      @jenex5608 3 года назад

      @@BekBrace I'm installing it on a Linux machine. The build wheels did not install properly. I installed the required dependencies but still got an error. So I installed it from the Github source to gett it working

    • @jenex5608
      @jenex5608 3 года назад

      @@BekBrace Also got this error
      Traceback (most recent call last):
      File "config.py", line 20, in
      config()
      File "config.py", line 11, in config
      params = parser.items(section)
      File "/usr/lib/python3.8/configparser.py", line 859, in items
      return [(option, value_getter(option)) for option in orig_keys]
      File "/usr/lib/python3.8/configparser.py", line 859, in
      return [(option, value_getter(option)) for option in orig_keys]
      File "/usr/lib/python3.8/configparser.py", line 855, in
      value_getter = lambda option: self._interpolation.before_get(self,
      File "/usr/lib/python3.8/configparser.py", line 395, in before_get
      self._interpolate_some(parser, option, L, value, section, defaults, 1)
      File "/usr/lib/python3.8/configparser.py", line 442, in _interpolate_some
      raise InterpolationSyntaxError(
      configparser.InterpolationSyntaxError: '%' must be followed by '%' or '(', found: '%'
      from the config.py

  • @samborms
    @samborms Год назад

    it's a good video

  • @redrum4486
    @redrum4486 3 года назад

    when i run the main.py file i get the following: {'host': 'localhost', 'database': 'master', 'user': 'postgres', 'password': 'admin'}
    {'host': 'localhost', 'database': 'master', 'user': 'postgres', 'password': 'admin'}
    Connecting to the postgreSQL database ...
    psycopg2.connect() argument after ** must be a mapping, not NoneType

    • @L-lk2sy
      @L-lk2sy 3 года назад

      Make the function config() return db

  • @okbrb
    @okbrb 4 года назад

    Why not just use a .env file and then read the value with load_dotenv() and os.getenv("db_port")

    • @BekBrace
      @BekBrace  4 года назад

      You can.
      There are a lot of ways to connect the server to python, however using ini file is just my preferred approach to do it especially if you want to deploy your app on Heroku for instance

    • @ihebbibani7122
      @ihebbibani7122 3 года назад

      @@BekBrace you're right , I have seen many githubs using your approach...

  • @luizferez89
    @luizferez89 3 года назад

    6 idiots 😝 dislike this great video !!
    Thanks man

    • @BekBrace
      @BekBrace  3 года назад

      Gracias 🙏 well, that’s ok, everyone to their opinion but thanks my friend

  • @ramnikbhorania4333
    @ramnikbhorania4333 Месяц назад +1

    Thank you very much for this tutorial. Your teaching skill is really awesome.