# SQL Application Development in Python

> The eXtremeSQL Python wrapper supports a SQL engine and a SQL server that operate on eXtremeDB databases using the Python DB API Specification. Developers are encouraged to view this website for general information on the Python Database classes and methods.

> ## Using the eXtremeSQL Python Wrapper Interactively

> To work with the Python wrapper interactively, first the Python interface module (which can be downloaded from www.python.org) is started and the eXtremeDB runtime loaded, then an eXtremeDB database (In-Memory or Persistent Media) can be created or an existing database can be connected.

> For example, once the Python interface is initialized, a database schema can be processed and the Database object created as follows:

>         >>> dict = exdb.load_dictionary(schema)
>         >>> dict
>         <eXDB.Dictionary object at 0x1006e0790>
>         >>>
>         >>> db = exdb.open_database("myopendb", dict)
>         >>> db
>         <exdb.Database object at 0x100827610>
>         >>>

> There are several ways to work with SQL:

> > 1. Using an “in process” database via a Database object. This is done by using a local embedded SQL engine which is available when a database is created in the current process. Virtually any eXtremeDB database can be accessed using this SQL interface. For example:

> >         >>>con = db.connect()

> > creates a connection using the exdb.Connection object which supports the SQL DB API interface.

> > 2. Using an existing shared memory database. If the shared memory database was created by another process, either another python process, or created by an application made with any of the eXtremeDB supported programming language APIs (C, C++, Java, .or C#), it may also be accessed via the python wrapper. To connect to a shared memory database, use the `connect()` method of the exdb module. For example:

> >         >>>con = exdb.connect(dbname)

> > creates a connection using the `exdb.Connection` object and supports both the eXtremeDB object-level interface and the SQL DB API interface.

> > 3. Using the RemoteSQL option which allows connecting to a remote SQL server. The remote server may be created using the SqlServer python class, by using the C++ SqlServer interface, or by using xSQL.

> > To connect to a remote SQL server, the connection must be made using the `connect(host, port)` method of the exdb module. For example:

> >         >>>con = exdb.connect('localhost', 5001)

> > Note, that the server connection is implemented using a different class, exdb.RemoteConnection, which is DB API compliant.

> > 4. Simple “sharding” of a database can be supported using a “Distributed” connection. In this case each query is sent to all nodes (shards), and the results are combined in the eXtremeSQL runtime. It is the application's responsibility to choose the sharding key, and to spread the data across shards.

> > To create a distributed connection the `connect()` method of class exdb must be used, but with two arguments. For example:

> >         >>>exdb.connect(nodes, maxConnectionAttempts = 10)

> > where `nodes` is a `tuple` of encoded node specification, in the form `'host:port'`, for example.:

> >         >>>con = exdb.connect(('node1:5001', 'node2:5001', 'node3:5001'))

> > Note that this server connection is implemented using a different class, exdb.DistributedConnection, which is DB API compliant.

> ## eXtremeSQL Application Implementation Details

> Please use the links in the table below for implementation examples:

> Cursors | Working with cursors
> Transactions | Managing SQL transactions
> Sequences | Working with the sequence data type
> AsyncDistributedConnections | Executing asynchronous distributed SQL statements