This page is part of the .

    Previous: SQLAlchemy Unified Tutorial | Next:

    Establishing Connectivity - the Engine

    The start of any SQLAlchemy application is an object called the . This object acts as a central source of connections to a particular database, providing both a factory as well as a holding space called a connection pool for these database connections. The engine is typically a global object created just once for a particular database server, and is configured using a URL string which will describe how it should connect to the database host or backend.

    The main argument to is a string URL, above passed as the string . This string indicates to the Engine three important facts:

    Lazy Connecting

    The , when first returned by create_engine(), has not actually tried to connect to the database yet; that happens only the first time it is asked to perform a task against the database. This is a software design pattern known as .

    We have also specified a parameter create_engine.echo, which will instruct the to log all of the SQL it emits to a Python logger that will write to standard out. This flag is a shorthand way of setting up Python logging more formally and is useful for experimentation in scripts. Many of the SQL examples will include this SQL logging output beneath a [SQL] link that when clicked, will reveal the full SQL interaction.

    Next Tutorial Section: