Python: Connecting to db without any external libraries - python

I'm working on a client machine running suse linux and python 2.4.2. I'm not allowed to dowload anything from the net including any external libraries. So, is there any way I can connect to a database (oracle) using only the default libraries?

No. There is nothing in the standard library for connecting to database servers.

You could look at the Apex Listener and/or PL/SQL Embedded Gateway (basically a webserver in the DB). These both provide HTTP access to database resources (eg getting data as JSON). Though obviously this shifts the 'heavy lifting' to the database platform.

Related

Create a On-Premise Gateway from Linux to Power Automate

I'm having a lot of trouble with this question and don't really find a lot of resources with it. I have a Power Automate Flow setup (triggered by a user submitting a form) in which I would like to receive data from my on-premise (on our corporate LAN) SQL (MariaDB) instance on my RHEL. From my understanding, there are three components that I would require: (1) REST API built on my web server which would simply return the data by querying the database, (2) On-Premise Gateway on my RHEL system, and (3) A HTTP Connector in my Flow process.
Developing a simple python/php script for my REST API is quite straightforward, however, I am having a bit of difficulty building my on-premise gateway. Microsoft comes with its own free Gateway however that is only available on Windows. Would I need to set up a Windows VM and from there install the gateway or is there a better solution?
Additionally, is my approach to solve this problem correct or am I going about it wrong?

How do I route an ODBC connection through a Proxy to get around a company firewall? (Python)

I am trying to access an external Amazon Redshift DB. I am using psycopg2 to access the external postgres db. As far as I know, I cannot include a proxy list as a connection parameter. The below code works when I am not connected to my company VPN.
Is there a way to do this strictly in python? I will be running this code on an on-prem Caas/VM so I would like to avoid machine level solutions such as Putty.
I have tried setting http/https proxies explicitly within my python code but this does not solve my problem. Is this because they are only useful for web API requests?
Sample Code
I am open to using alternative libraries.

How do I access an Oracle db without installing Oracle's client and cx_Oracle?

I have two RHEL servers running Python 2.4 and 2.6 separately. There is an Oracle database on the other server I need to access.
I was trying to install cx_oracle on my RHEL server but found out that the Oracle client must be installed first.
The problem is, I don’t have permission to install Oracle's client on both RHEL servers. On the same servers, a Perl program can connect to the Oracle db using:
DBI->connect("dbi:Oracle:host=myhost.prod.com;sid=prddb",'username','password')
Can Python do the same without installing cx_oracle and the Oracle client? Or are there any suggestions about how to write a module myself to do the same thing?
Thanks in advance!
An excerpt from https://forum.omz-software.com/topic/184/oracle-database:
There's no pure python client for Oracle and likely never will be. Even wonderful third-party toolsets like SQLalchemy still rely on cx_Oracle underneath to do the actual communication to the Oracle database servers.
—also, deciding by Google, the answer is no: there do not seem to be any pure Python Oracle clients in existence as of today.
Usually, all you need are the libraries, which don't necessarily require sudo rights. Extract them to a place the software will be able to read from and set the following environment variables accordingly:
ORACLE_HOME=path/to/where/you/extracted/libs
TNS_ADMIN=path/to/tnsnames.ora
I have had best luck skipping tnsnames, and just specifying the host, port, etc in the connection, but it's quite possible you'll need it for cx_oracle...I don't remember from when I used it ages ago.
if you don't want use cx_Oracle you should use expect scripting. ( for python pexpect). But you need to be carefully for handle all expectations.

Best way to access Firebird DB from a remote desktop.

I have a Firebird DB set up on my computer and I want to be able to retrieve data from a different computer. What is the best way to go about this?
I am running windows and using python.
Install firebird client to the client pc
To connect firebird programmaticaly from python you should install a python Firebird driver.
For Python 2.x, you can use kinterbasdb. This is the legacy driver and I think it is not actively developed but only maintained.
To connect windows based server database from kinterbasdb you can use
Import kinterbasdb as k
k.init(type_conv = 300) #
con = k.connect(dsn='127.0.0.1:c:\\db\\test.fdb', user='sysdba', password='masterkey', charset='YOUR_CHARSET', dialect=3)
Of course you should adjust connection parameters according to your system. Kinterbasdb documentation is here
If you want use an ORM, you can use SqlAlchemy which uses kinterbasdb for Firebird Support
For Python 3k you can use pyfirebirdsql which also supports Python 2.5+ and under active development, but not supported by SqlAlchemy yet.
Run Firebird server on the computer with database file and connect to it from remote computer. You will need in Firebird client library installed on remote computer.
I think we need a bit more info.
Do you want database access - as in "I want to be able to edit table layout and define new tables, views, procedures and so on" ?
Or do you only need to get data from the database using python ?
The latter could be achieved by installing a Firebird client (in essence its a dll (fbclient.dll)) and then use a connect string from python to connect to your database.

Using MongoLab Database service vs Custom web service with MongoDB running on AWS

I am looking for feasible solutions for my Application to be backed with MongoDB. I am looking to host the MongoDB on the cloud with a python based server to interact with the DB and my app (either mobile/web). I am trying to understand how the architecture should look like.
Either i can host a mongoDB on the AWS cloud and have the server running there only.
I also tried using MongoLab and seemed to be simple accessing it using HTTP requests. but i am not sure if it exposes all the essential features of MongoDB (what ever i can do using a pymongo driver)? Also, should i go for accessing the MongoLab service directly from my application or still i should build a server in-between?
I would prefer to building an server in either case as i want to do some processing before sending the data back to application. but i am not sure in that case how my DB-server-app interaction design should be
Any suggestions?
One thing to consider is that you don't need to use MongoLab's REST API. You can connect directly via a driver as well.
So, if you need to implement business logic (which it sounds like you do), it makes sense to have a three tier architecture with an app server connecting to your MongoLab database via one of the drivers. In your case it sounds like this would be pymongo.
-will

Categories