Skip to main content

Pure Jython (Python in the JVM) JDBC dbapi pep-249 driver

Project description

JyJDBC Pure Jython JDBC dbapi driver


Overview

https://pypi.org/project/jyjdbc/ is a pure Python pep-249 http://www.python.org/peps/pep-0249.html driver for JDBC usable under Jython.

Latest version available from https://hg.sr.ht/~clach04/jyjdbc

Original written for the Ingres JDBC driver, works with other drivers too.

Targets Jython 2.7.0, 2.5.3, and 2.5.2 (and also works with Jython 2.2).

CPython (and other Python implementations) can make use of JDBC via a bridge to Jython. For example; RPyC, Pyro4, SPyRO, execnet, and SPIRO. Use of a bridge may require additional security attention.

More information https://hg.sr.ht/~clach04/jyjdbc (previously https://bitbucket.org/clach04/jyjdbc/wiki/Home)


Features

  • Pure Python / Jython - no Java experience needed
  • No need for JDK, this driver can be extend with just a JRE
  • Only needs JRE, Jython, and JDBC driver for database
  • Better pep-249 compliance than zxJDBC, with a testsuite to prove it
  • Decimal data type support
  • Returns Java types when a Python type is not an option
  • Python developers can maintain it

Why?

I needed support for decimal data types which (in 2010) zxJDBC does not have (nor do the other Python/JDBC solutions). I needed to create a number of tests for the decimal type so this was a a major issue, I contributed Decimal support to the IronPython driver but .NET has a limit of 28 decimal places. JyJDBC has a simple internal structure, adding support for new types is trivial.

Right now I recommed using jyjdbc instead of zxJDBC. Current weakness of jyjdbc compared with zxJDBC is that row returning database procedures are not yet implemented and a few types (Binary and ROWID) are not implemented (Java types are returned instead).

A test suite is provided for JyJDBC as well as zxJDBC so the different features/limitations/problems can be compared. There are tests for Ingres and SQLite3.

Installation

Either from PyPi or a checkout.

NOTE pip support is experimental and NOT recommended.

java -jar jython-standalone-2.7.3.jar -m ensurepip
# NOTE do not recommmend updating pip, especially under Microsoft Windows due to pip-20.3.4 errors related to missing winreg module
java -jar jython-standalone-2.7.3.jar -m pip install jyjdbc

Demo

The following demos make use of the Ingres DBMS and the Ingres JDBC driver. Connection is made to a database that always exists using Operating System authentication (hence no username/password in the connect statement). SELECT is against a table that always exists in all Ingres databases.

Regular Jython example


This demo connects to a local Ingres DBMS as the current user.


    C:\>c:\jython2.5.1\jython.bat
    Jython 2.5.1 (Release_2_5_1:6813, Sep 26 2009, 13:47:54)
    [Java HotSpot(TM) Client VM (Sun Microsystems Inc.)] on java1.6.0_02
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import jyjdbc
    >>> con =jyjdbc.connect('iidbdb')  # II_SYSTEM already set, local connection
    >>> cur = con.cursor()
    >>> cur.execute('select * from iidbconstants')
    >>> print cur.description
    [(u'user_name', c, None, None, 32, 0, 0), (u'dba_name', c, None, None, 32, 0, 0), (u'system_owner', varchar, None, None, 32, 0, 0)]
    >>> print cur.fetchall()
    [(u'ingres                          ', u'$ingres                         ', u'$ingres                         ')]
    >>>

For more examples and using other databases see the project wiki
http://code.google.com/p/jyjdbc/wiki/Examples


CPython access to JDBC

This demo uses RPyC version 3.1.0 from http://pypi.python.org/pypi/RPyC/

Jython starts rpyc_classic.py:

jython rpyc_classic.py

CPython also uses RPyC, using the client:

C:\>python.exe
Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import rpyc
>>> conn = rpyc.classic.connect("localhost")
>>> jyjdbc = conn.modules.jyjdbc
>>> con =jyjdbc.connect('iidbdb')  # II_SYSTEM already set (under RPC), local connection
>>> cur = con.cursor()
>>> cur.execute('select * from iidbconstants')
>>> print cur.description
[(u'user_name', c, None, None, 32, 0, 0), (u'dba_name', c, None, None, 32, 0, 0), (u'system_owner', varchar, None, None, 32, 0, 0)]
>>> print cur.fetchall()
[(u'ingres                          ', u'$ingres                         ', u'$ingres                         ')]

NOTES

  • JDBC Time type does NOT support sub second values. This means that when Python datetime.time values are sent the time is truncated to the second. Similarly when ANSI time values are returned from the database if the JDBC driver returns a JDBC time, sub second accuracy is lost to truncation. This is how JDBC works.

  • Currently the driver is not 100% pep-249 compliant, but it is closer to 100% than zxJDBC. Patches for improvements are welcome. See test suite for details. NOTE the driver is being used everyday in the current state.

  • The test suite is incomplete, it could benefit from database procedures tests and support for other databses.

  • The driver has been tested with:

    The driver was originally developed using Ingres. Patches for support of other drivers/servers are welcome, along with API improvements to improve PEP-249 compliance.

  • Support for Jython 2.2 is present, but due to the use of modules:

    • Decimal
    • datetime
    • logging

    The Python 2.4 modules are needed. Python 2.5 support is the main focus of this driver but where possible support for older releases will be added. See "backports" notes in source. Or use a patched Jython 2.2 from https://bitbucket.org/clach04/jython/downloads

    I have jyjdbc running on a server with Jython 2.2.1 under JRE 1.5.0.

  • The setup.py script uses either setuptools or distutils. Distutils requires either either the standalone Jython jar file or a Standard Jython install (installing Core does not install distutils).

  • Building the documentation (via setup.py) requires docutils (and the docutils depedencies).

  • Running the test suite requires dbapi20 / dbapi-compliance. There are other testsuites and it would be good to have jyjdbc running with those. For more information about dbapi20 see:

    A known working copy of dbapi-compliance (aka dbapi20) is available from https://bitbucket.org/clach04/dbapi-compliance/overview

    It would be useful to add support for some ORMs and make use of the ORM test suite, for example SQLAlchemy has comprehensive test suite.

    For any changes, please ensure the test suite runs clean using the H2 test suite.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jyjdbc-0.0.5.tar.gz (36.4 kB view details)

Uploaded Source

File details

Details for the file jyjdbc-0.0.5.tar.gz.

File metadata

  • Download URL: jyjdbc-0.0.5.tar.gz
  • Upload date:
  • Size: 36.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for jyjdbc-0.0.5.tar.gz
Algorithm Hash digest
SHA256 41958dc075122cf81c580120bb844000d87f233a7fe2fc05e4272a695dc8e1cd
MD5 d422d599c510fc9a945de2f3434a6f2a
BLAKE2b-256 338ec59c08fbb53cb8ceb11786328d8a6ebc4881bb94793df6694897d6f5d1d5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page