I've been looking across the internet to find some sort of library that will connect an Oracle database to a Python script, but so far I have been unsuccessful. If anyone has found a great library for Oracle, preferably first party, then please give me documentation. I'm working on a project now that particularly needs this integration. I've already seen lots of documentation for MySQL, which is maintained by Oracle, but that's about it.
The library is cx_Oracle. It conforms to the Python DB API 2.0 specification with a number of additions and a couple of exclusions. The cx_Oracle creator is Anthony Tuininga. Since 2017 the cx_Oracle is manteined by Oracle and Anthony Tuininga joined to Oracle and making maintaining the driver his full time job.
The lib have a good documentation and are frequently updated. There are a bunch of samples on cx_Oracle github.
Oracle provides the python library cx_Oracle. Like everything else produced by Oracle, the documentation leaves some to be desired and the drivers are an absolute pain in the ass, but it works.
Related
so I was just wondering. I am designing this Kivy app but I currently use .txt files which is messy and just seems like a huge waste of time. I was wondering if there was a package that could read/write/create MySQL databases with python. However, I do use Pycharm and I read a while back that the free version the one I use. May have some limitations with this.
You could use the mysql package for this.
https://dev.mysql.com/doc/connector-python/en/connector-python-example-connecting.html
The PyCharm support for MySQL is just for viewing the data in the database as a programmer or for debugging.
How can I use Tarantool in conjunction with Django and MySQL for caching (instead of i.e. Redis) and/or in the sense that all read transaction go to Tarantool (after insured MySQL replication) and all writes go into MySQL (preferred option) Would anyone have a sample?
Well. Tarantool does not have a Django plugin. That means you have to introduce it first. By the way, tarantool has python 2.71 and python 3.x1 libraries, so it may be useful for integration.
How it could be implemented? You have to use taranool's python library and also MySQL's python library for creating some Django / Python plugin.
Also. About MySQL replication. Tarantool has this feature, you can get codes from GH repo[2].
I'm not sure that Django's sample could be found.
Afterword. It's the pretty big task :)
1 https://github.com/tarantool/tarantool-python
[2] https://github.com/tarantool/mysql-tarantool-replication
UPD: February 2021:
The Django-Tarantool Database Backend was introduced as django-tarantool PyPi package and can be used for Django 1.10-3.1 versions.
pip install django-tarantool
Feel free to contribute to the package https://github.com/artembo/django-tarantool
In order to work with HANA in python, I've always used the pretty old python 2.6.4 that came with the HANA client. There are ways to get it working with other python versions, too, but they seem to by very hacky.
Now I've found the very promising-looking PyHDB project on Github, which seems to do the same job being installed more easy and working with newer Python versions, too.
Which features won't work with PyHDB that worked with the HANA python?
Are there performance drawbacks?
Edit:
Here is what I found using the module globals:
PyHDB is more thread-safe (threads may share connections here)
the parameter style is different (PyHDB: format; hdbcli: qmark, named)
Here an update on the current situation:
pyhdb supports Python 2.7, 3.3, 3.4, 3.5 and also PyPy on Linux, OSX
and Windows.
hdbcli has support for python 2.7 and python 3.4+ and is is fully supported and pushed by SAP.
Regarding performance:
executemany is an order of magnitude faster with hdbcli
The following blog post contains some further information:
https://blogs.sap.com/2017/07/26/sap-hana-2.0-sps02-new-feature-updated-python-driver/
The PyHDB is the younger brother of the node-hdb, both implementing the same protocol as ODBC based Python package hdbcli. The hdbcli Python client is a part of standard HANA installation but it does not belong to the list of officially supported interfaces for building HANA applications, to my knowledge.
The orientation for building PyHDB was therefore not the hdbcli client but the above mentioned protocol specification and the existing node-hdb implementation.
The detailed hdbcli/PyHDB cross-comparison is therefore not currently available but looking into the protocol specification and READMEs of PyHDB and node-hdb helps getting insight into connectors' features and the current coverage of the specification by both implementations.
Among these three HANA connectors, hdbcli, node-hdb and PyHDB, the PyHDB, being the youngest one, offers atm. the least features and capabilities, missing some features already available in node-hdb, like authentication methods or prepared statements for example. Looking into node-hdb source helps getting the rough estimate of efforts required for building the same in Python.
Rather than waiting for the full coverage of the protocol, which could take a while, the PyHDB is released "as is", but open for receiving input and requirements from projects and offering new features in that direction.
No performance drawbacks discovered so far.
Perhaps worth of mentioning here, the direct connectivity from Python and nodejs (GO should come soon) is also possible with ABAP, via SAP RFC protocol, via PyRFC and node-rfc connectors, which are counterparts of standard ABAP RFC connectors, available for Java and .NET as well.
pyhdb was deprecated in May 2021 and is no longer maintained. You can find its GitHub repo is archived (https://github.com/SAP-archive/PyHDB) and in read-only mode. Any open issues and pull requests were closed by the SAP maintainer #bsrdjan. hdbcli is now the recommended Python package for interacting with SAP HANA databases, although it's closed source with less documentation.
I recommend using sqlalchemy-hana, which is a SQLAlchemy dialect for SAP HANA databases. It can use hdbcli or pyhdb with a one-line change to the configuration, so you don't need to track down database driver documentation.
I am trying to get Django-pyodbc to work with DB2 on IBM i using the standard IBM i Access ODBC driver.
I know there is a Django DB implementation supported by IBM, but that requires the DB2 Connect product, which is (for us) prohibitively expensive, whereas the included Access ODBC driver comes no-charge with the OS.
I have seen a question asked regarding django-pyodbc with iSeries ODBC, suggesting that it is possible, but I have found no way to get it to work:
https://stackoverflow.com/questions/25066866/django-inspectdb-on-db2-database
My first question therefore is; has anybody succeeded in getting this setup to work?
And if yes, can you share information on how you did it?
Thanks,
Richard
I am looking for a pure-python SQL library that would give access to both MySQL and PostgreSQL.
The only requirement is to run on Python 2.5+ and be pure-python, so it can be included with the script and still run on most platforms (no-install).
In fact I am looking for a simple solution that would allow me to write SQL and export the results as CSV files.
Two part answer:
A) This is absolutely possible.
B) Depending on your exact concerns, a pure-python may or may not be a good approach to your problem.
Explained:
The SqlAlchemy library comes with two components : the more popular "ORM" , and the "Core" which it sits on top of. Either one will let you write your SQL commands in the SqlAlchemy format (which is just Python); SqlAlchemy will then compile the statements to Mysql or PostgreSQL and connect to the appropriate database.
SqlAlchemy is a great library, and I recommend it for just about everything. While you do have to write your statements in their format, it's easy to pick up -- and you can switch to virtually any underlying database library you want... at any time. It's the perfect platform to use in any database project , whether or not you need to support multiple backends.
SqlAlchemy talks to the database via the standard DBAPI drivers, and does support multiple options for pure python, notably the pymysql and pypostgresql drivers ( http://docs.sqlalchemy.org/en/latest/core/engines.html#supported-dbapis )
As for writing csv, the standard library has you covered.
import csv
So the caveat?
The following may or may not apply to your situation:
Most higher level db modules in the python universe are still recommending mysql-python and psycopg - both of which are not pure-python and compile/link/configure against the installed database. This largely seems to be from a mix of API / integration concerns and the speed of the various pure-python packages compared to c-extensions when run under CPython.
There are pure-python drivers like I recommended, but most reviewers state that they're largely experimental. The pymysql authors claim stability and production readiness, some developers who blog have challenged that. As for what "stabile" or "experimental" means, that varies with the projects. Some have a changing API, others are incomplete, some are buggy.
You'd need to ensure that you can find pure-python drivers for each system that support the exact operations you need. This could be simple, or this could be messy. Whether you use SqlAlchemy or something else, you'll still face this concern when selecting a DBAPI driver.
The PyPy project ( pure-python python interpreter ) has a wiki listing the compatibility of various packages : https://bitbucket.org/pypy/compatibility/wiki/Home I would defer to them for specific driver suggestions. If PyPy is your intended platform, SqlAlchemy runs perfectly on it as well.
Are you looking for an ORM, or a single library that would allow you to write SQL statements directly and convert where there are differences?
I'm not sure whether psycopg2 is pure-python or not, but it certainly has bindings and works on all platforms. You'd still have to install at least psycopg2 to communicate with the PostgreSQL database as Python (as far as I know) doesn't ship with it natively.
From there, any additional ORM library you want would also need to be installed, but most are pure-python on-top of whatever backend they use.
Storm, Django, SQLAlchemy all have abstracted layers on top of their database layer - based on your description, Django is probably too large a framework for your needs (was for mine) but is a popular one, SQLAlchemy is a tried and true system - tho a bit clunky particularly if you have to deal with inheritance (in my opinion). I have heard that Storm is good, tho I haven't tested too much with it so I can't fully say.
If you are looking to mix and match (some tables in MySQL and some tables in PostgreSQL) vs. a single database that could be either MySQL or PostgreSQL, I've been working on an ORM called ORB that focuses more on object-oriented design and allows for multiple databases and relationships between databases. Right now it only supports PostgreSQL and Mongo, just cause I haven't needed MySQL, but I'd be up for writing that backend. The code for that can be found at http://docs.projexsoftware.com/api/orb
Use SQL-Alchemy. It will work with most database types, and certainly does work with postgres and MySQL.