Skip to main content

litex.cxpool - a SQLAlchemy pool with native Oracle session pooling

CxOracleSessionPool is a subclass of SQLAlchemy’s NullPool, with functionality close to QueuePool. It’s major selling point is the ability to run in proxy authentication mode. In this mode, the session pool is constructed with one set of credentials and individual connections can by acquired from it, authenticated for a different user.

It’s being used in Pyramid applications interfacing with an ERP system with all logic, auditing and security contained in Oracle DB stored procedures.

Example usage:

>>> from litex.cxpool import CxOracleSessionPool
>>> def get_user():
...     return 'REAL_USER'

get_user is a callable returning login of a user we would like to connect as. To connect to db as currently authenticated user in Pyramid, this function could look like the one below (prefix is used to find the right type of principals, and exclude the system. ones e.g. system.Everyone):

>>> from pyramid.threadlocal import get_current_request
>>> from pyramid.interfaces import IAuthenticationPolicy
>>> prefix = 'example.'
>>> def get_user():
...     req = get_current_request()
...         auth = req.registry.queryUtility(IAuthenticationPolicy)
...         prc = [pr for pr in auth.effective_principals(req) if pr.startswith(prefix)]
...         if prc:
...             return prc[0].split('.')[-1]
...         else:
...             return None

Having the user source, we can construct the pool:

>>> pool = CxOracleSessionPool(
...    'oracle://proxy_user:proxy_password@test_server/test',
...    min_sessions=1,
...    max_sessions=5,
...    increment=1,
...    user_source=get_user
... )
  • First parameter is a database URL with proxy user credentials.

  • min_sessions controls, how many sessions are constructed initially (in contrast to SA QueuePool this pool precreates sessions)

  • max_sessions sets the upper cap of constructed sessions count (think about it as QP pool_size + max_overflow)

  • increment sets how many sessions to create when current session count is too low (up to max_sessions)

To allow REAL_USER to connect to the db through PROXY_USER, one have to issue the following statement as DBA:

sql> alter user REAL_USER grant connect through PROXY_USER;

Having the pool ready, we can construct a SQLAlchemy engine

>>> from sqlalchemy import create_engine
>>> engine = create_engine('oracle://', pool=pool)

and use it as any other SA engine:

>>> conn = engine.connect()
>>> res = conn.execute('select user from dual')
<sqlalchemy.engine.base.ResultProxy object at 0x1670b50>
>>> res.fetchone()
(u'REAL_USER',)

Changes:

1.1

  • Compatibile with SQLAlchemy 1.3

  • Python 3 compatibility

  • tests are using py.test and tox now

1.0.3

  • Handling network problems

1.0.2

  • SQLAlchemy 0.7 compatible

1.0.1

  • namespace package specification

  • various packaging errors

1.0

  • initial release

Release files for litex.cxpool 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for litex.cxpool 1.1.1
File Size Uploaded
litex.cxpool-1.1.1.tar.gz 3.8 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for litex.cxpool 1.1.1
File Interpreter ABI Platform
litex.cxpool-1.1.1-py3-none-any.whl Python 3 none any Details
litex.cxpool-1.1.1-py2-none-any.whl Python 2 none any Details

Total release size: 12.6 kB

Release files / litex.cxpool-1.1.1.tar.gz

Download URL litex.cxpool-1.1.1.tar.gz
Size 3.8 kB
Tags Source
SHA-256 checksum
How to use checksums
3d372aac4ef31373b561765b45ed0eae3cc2d9a15111c725d2783bc8d209d639
BLAKE2b-256 checksum
How to use checksums
92b8b6d0a2c966396b3f17c34e776c2aa8d720bd31189ab68aebe77692069da2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/2.7.16

Release files / litex.cxpool-1.1.1-py3-none-any.whl

Download URL litex.cxpool-1.1.1-py3-none-any.whl
Size 4.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a8a0e8f90e9282d048f4010797e1cb1bad52812c3a8e8695aa9450eacddb015e
BLAKE2b-256 checksum
How to use checksums
5512e393139a70ff8d6f2274f1e8437293a9d087b878daff23b6a950ef1cffb1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/2.7.16

Release files / litex.cxpool-1.1.1-py2-none-any.whl

Download URL litex.cxpool-1.1.1-py2-none-any.whl
Size 4.4 kB
Tags Python 2
SHA-256 checksum
How to use checksums
acf4b0056719760ba4e4b9c81f0e9313b33807f9c81bc9719e7f87329cbe8f93
BLAKE2b-256 checksum
How to use checksums
873b36694fb8e2276ba734c2ec851ba022ecd6b65fd5408f274daa013852d48f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/2.7.16

Release history Release notifications | RSS feed

This release

1.1.1 This release

3 release files

1.1

3 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

1 release file

1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page