Search code examples
pythondatabasepygresql

how does a Python api database connection work?


I am starting to try an work with databases using Python. I am trying to understand the process when I connect to a database and get some data out of it.

I think it works like this: The Python code is used by the Python Api to access the Database Management System (PostgreSQL) which in turn access the database to get the required data.

Python code <-> Python Api (PyGreSQL) <-> DBMS (PostgreSQL) <-> database

But it might also be like this Python code <-> Python Api (PyGreSQL) <-> database

Or something completely different. Thanks in advance!


Solution

  • Looking for example at the documentation of the query method of PyGreSQL it says:

    This method simply sends a SQL query to the database[...]

    So the Python API only generates SQL queries and sends them to the DBMS. I don't think there's an example where an API (in any language) would directly interact with the actual database.