Simple, light and nearly featureless database connection pool
Project description
DBCP Lite
A simple, light and nearly featureless database connection pool for Python.
Connections are added to the pool as needed up to max_size
in number.
Once added the connections will remain in the pool and no attempt is made
to shrink the pool. In most cases it is recommended to set
min_size == max_size
.
Usage
import cx_Oracle
from dbcp_lite import DBConnectionPool
connect_args = ('scott', 'tiger', 'dbhost.example.com/orcl')
pool = DBConnectionPool(cx_Oracle.connect,
create_args=connect_args,
create_kwargs={'threaded': False},
min_size=1,
max_size=4,
name='scott@orcl')
with pool.acquire() as connection:
...
with pool.acquire_cursor() as cursor:
...
pool.close()
The acquire_cursor()
is a convenience method that returns a Cursor
using a
Connection
from the pool. Upon successful completion commit()
will be
called on the Connection
and the Cursor
will be closed.
Timeouts
A timeout can be provided to various methods. If no connections are available to
be acquired
or closed
the methods will raise a PoolTimeout
exception.
Lifecycle Methods
The following lifecycle methods are called during normal operations and alternate implementations can be provided if needed to perform specialized setup or cleanup.
on_acquire(self, connection)
- no-op
on_return(self, connection)
- default implementation calls connection.rollback()
on_close(self, connection)
- default implementation calls connection.close()
For example, to implement auto-commit:
pool = ...
pool.on_return = lambda x: x.commit()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file dbcp-lite-0.0.1.tar.gz
.
File metadata
- Download URL: dbcp-lite-0.0.1.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 131ae0b5451167986eb8b114c00f7e1230806932f21d181760fa608174f033fb |
|
MD5 | 3a99079be2bdb01d772b95d3b0f078a4 |
|
BLAKE2b-256 | 434d36fe79d2ed1a0837a1ccc3f0616bf0a8321eef03a005488cc107b6e7932e |
File details
Details for the file dbcp_lite-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: dbcp_lite-0.0.1-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0a8de3114b32d58f8394d5815360941ce4d087d3f4d9fe6c6539a9d468d2dbc |
|
MD5 | 4e36b261bf178246faf3155a6925b8fb |
|
BLAKE2b-256 | 30cfa5b401628c9afdd3489d5c1fe72adbcbb08b7eed91da551af1abee11ca06 |