You can then run SQL queries that in the end call your own data functions to generate data. I had a project where I had several diverse data files (each with its own set of functions to iterate over, but no useful querying) where wrapping each data file with a SQL Virtual table allowed med to use SQL to join them up and query them.
Here's a 2014 article where the author exposes redis as a virtual table within your sqlite code using this mechanism: https://charlesleifer.com/blog/extending-sqlite-with-python/
Postgres has some support for this (you run your SQL code but it really talks to some other service, or another postgres database) through foreign data wrappers. There's some Python library to also make adding that easy.
Interestingly a few projects do it in reverse: you are talking the postgres protocol (using library, psql client) to your database server, but it's not postgres but something else entirely (CockroachDB does this).
I like the idea of the entire world being just SQL, but you have to be careful with those wrappers and expose any indexing you might have, otherwise it's lots of expensive table scans.