Build postgreSQL in Windows with Python - python

Can i install and build postgreSQL from Source Code in Windows by using Python? Is it solid? Currently in their documentation they have Visual C++ as their only option!
And if it is possible (and reliable) where can i find prime material to use Python to build and customize my postgreSQL? I won't go and learn Visual C++ unless it is the only way. I also have GitBash if that helps...
For people who have no idea on db's. They never say that in documentations because they think it for granted.
IT ALL BOILS DOWN TO: It is another thing building_from_source/installing a db and a totally another thing interacting/working with a db.

There is library for accessing Postgres from python called psycopg. There is a tutorial on its use here.
To the extent that you are just learning about databases, you might also take a look at Sqlite, which is a more lightweight database and included in the python standard library

Since you want to use PostgreSQL you really don't need to compile anything. Simply install PostgreSQL and the windows binaries of psycopg2 (the PostgreSQL client library for python).
If you want to build the PostgreSQL database server - something you only want/need to do if you want to modify PostgreSQL itself, and which is something you probably don't want to do as a beginner - you should use whatever compiler the Postgres developers suggest since they most likely only have project/make files for that compiler.

Related

Can you import Python libraries with PL/Python in PostgreSQL?

I was wondering if it was possible to use Python libraries inside PL/Python.
What I want to do is remove one node in our setup. Right now we have a sensor publishing data to RabbitMQ using Mosquitto and MQTT.
On the other side, we have PostgreSQL and we want to build a database. I know that we need something between RabbitMQ and PostgreSQL and we were thinking of Paho.
But we were wondering if it was possible to run a script on PostgreSQL using plpython and using the library Paho there. So that would make onr less thing to execute "stand alone".
Or maybe there are other alternatives?
Sure, you can import any module into PL/Python. The documentation states:
PL/Python is only available as an “untrusted” language, meaning it does not offer any way of restricting what users can do in it and is therefore named plpythonu.
Just make sure you don't use multi-threading inside PostgreSQL.

Test MySQL Connection with default Python

I'm wondering if there is any built-in way in Python to test a MySQL server connection. I know I can use PyMySQL, MySQLdb, and a few others, but if the user does not already have these dependencies installed my script will not work? How can I write a Python script to test a MySQL connection without requiring external dependencies?
Python distributions do not include support for MySQL, which is only available by installing a third-party module such as PyMySQL or MySQLdb. The only relational support included in Python is for the SQLite database (in the shape of the sqlite3 module).
There is, however, nothing to stop you distributing a third-party module as a part of your application, thereby including the support your project requires. PyMySQL would probably be the best choice because, being pure Python, it will run on any platform and give you best portability.

Python consumer application with database

I want to implement a simple application (for Windows), mainly for data collection and I should be able to run some queries.
I can produce an exe file from the python code, but I don't want to install the database separately, rather I'd include it in an installer. I think some other applications do the same or they require MySQL to be installed -- not in development mode -- since I saw in Windows' Programs and Features that there are some MySQL installations.
So my question is: Is there a way to use MySQL or a specific preparation method of an application so I am able to use some database operations inclusive saving data? Remark: any database would work, I was referring to MySQL because I suspect I saw some examples.
You could use Pyinstaller to make an exe out of your database and Python file. Python natively supports sqlite so you don't have to install anything extra if you use that.

Accessing a JET (.mdb) database in Python

Is there a way to access a JET database from Python? I'm on Linux. All I found was a .mdb viewer in the repositories, but it's very faulty. Thanks
MDB Tools is a set of open source libraries and utilities to facilitate exporting data from MS Access databases (mdb files) without using the Microsoft DLLs. Thus non Windows OSs can read the data. Or, to put it another way, they are reverse engineering the layout of the MDB file.
Jackcess is a pure Java library for reading from and writing to MS Access databases. It is part of the OpenHMS project from Health Market Science, Inc. . It is not an application. There is no GUI. It's a library, intended for other developers to use to build Java applications.
ACCESSdb is a JavaScript library used to dynamically connect to and query locally available Microsoft Access database files within Internet Explorer.
Both Jackcess and ACCESSdb are much newer than MDB tools, are more active and have write support.
Install your distribution's packaged version of mdbtools, use mdb-export to export the Jet data to text files, import the data into a SQLite database, and have a combination of code and data that works in almost any computing environment you might get your hands on.
Probably the most simple solution:
Download VirtualBox and install Windows and MS access in it.
Write a small Python server which use ODBC to access the database and which receives commands from a network socket.
On Linux, connect to the server in the virtual machine and access the database this way.
This gives you full access to all features. Every other solution will either limit the features you can use (for example, you won't be able to modify the data) or be pretty unsafe.
If you build the CVS version of mdb-tools, it works rather well. It fixed a lot of issues I had trying to use the one in the repositories related to memo field size. mdb-tools is basically a dead project, but people have still been occasionally contributing code to the CVS. The build in Ubuntu is from 2004 I think.
CVS instructions here:
http://sourceforge.net/scm/?type=cvs&group_id=2294
If using Ubuntu, before downloading the sources you'll want to enable source repositories and do:
apt-get build-dep mdbtools
That will get the required packages you'll need to manually build the sources from CVS.

portable non-relational database

I want to experiment/play around with non-relational databases, it'd be best if the solution was:
portable, meaning it doesn't require an installation. ideally just copy-pasting the directory to someplace would make it work. I don't mind if it requires editing some configuration files or running a configuration tool for first time usage.
accessible from python
works on both windows and linux
What can you recommend for me?
Essentially, I would like to be able to install this system on a shared linux server where I have little user privileges.
I recommend you consider BerkelyDB with awareness of the licensing issues.
I am getting very tired of people recommending BerkleyDB without qualification - you can only distribute BDB systems under GPL or some unknown and not publicly visible licensing fee from Oracle.
For "local" playing around where it is not in use by external parties, it's probably a good idea. Just be aware that there is a license waiting to bite you.
This is also a reminder that it is a good idea when asking for technology recommendations to say whether or not GPL is acceptable.
From my own question about a portable C API database, whilst a range of other products were suggested, none of the embedded ones have Python bindings.
Metakit is an interesting non-relational embedded database that supports Python.
Installation requires just copying a single shared library and .py file. It works on Windows, Linux and Mac and is open-source (MIT licensed).
BerkleyDB
If you're used to thinking a relational database has to be huge and heavy like PostgreSQL or MySQL, then you'll be pleasantly surprised by SQLite.
It is relational, very small, uses a single file, has Python bindings, requires no extra priviledges, and works on Linux, Windows, and many other platforms.
Have you looked at CouchDB? It's non-relational, data can be migrated with relative ease and it has a Python API in the form of couchdb-python. It does have some fairly unusual dependencies in the form of Spidermonkey and Erlang though.
As for pure python solutions, I don't know how far along PyDBLite has come but it might be worth checking out nonetheless.
BerkeleyDB : (it seems that there is an API binding to python : http://www.jcea.es/programacion/pybsddb.htm)
Have you looked at Zope Object Database?
Also, SQLAlchemy or Django's ORM layer makes schema management over SQLite almost transparent.
Edit
Start with http://www.sqlalchemy.org/docs/05/ormtutorial.html#define-and-create-a-table
to see how to create SQL tables and how they map to Python objects.
While your question is vague, your comments seem to indicate that you might want to define the Python objects first, get those to work, then map them to relational schema objects via SQLAlchemy.
If you're only coming and going from Python you might think about using Pickle to serialize the objects. Not going to work if you're looking to use other tools to access the same data of course. It's built into python, so you shouldn't have any privileged problems, but it's not a true database so it may not suit the needs of your experiment.
Adding a reference to TinyDB here since this page is showing at the top of many searches. It is a portable non-relational database in python. It stores python dicts into a local json file and makes them available for database ops similar to mongodb. It also has an extension to port to mongodb's commands, the difference being that instead of working on another system server you'll be operating on a local json file.
And unlike the presently chosen answer, it is under a permissive MIT open license.
Links:
TinyDB site
Tinydb on Github
Basic Usage
Usage
Support forum
Implementations

Categories