Proper way to connect database in python

I have a script with several functions that everyone should do for database calls. I try to write clean code better, and not just dump scripts with terrible style. It is usually considered the best way to establish a global database connection, access to which can be obtained anywhere in the script, but is not prone to errors, for example, by accidentally overriding a variable containing a connection. I suppose I should put everything in a module? Any links to the actual code are also very useful. Thank.

+3
source share
2 answers

If you work with Python and databases, you cannot afford to not look at SQLAlchemy :

SQLAlchemy is a Python SQL toolkit and object relational mapper that gives application developers the full power and flexibility of SQL.

It provides a complete set of well-known enterprise-level persistence models, designed for efficient and high-performance database access, adapted to the simple and Pythonic domain language.

( ). , , , Python (.. , ), API . , : -, API O'Reilly, , , .

Relation Mapper, SQL. , ( MySQL, Oracle, SQLite ).

Session ( ).

- , , , Google sqlalchemy tutorial.

+3

/ ORM.

0

All Articles