Connecting to Sql Server with Python 3 in Windows - python

Can someone please point me in the right direction of how I can connect to MS SQL Server with Python? What I want to do is read a text file, extract some values and then insert the values from the text file into a table in my Sql Server database. I am using Python 3.1.3, and it seems some of the modules I have come across in research online are not included in the library. Am I missing something? Is there a good 3rd party module I should know about. Any help would be greatly appreciated.I am using Windows. thanks

There are a bunch more SQL Server libraries listed on the Python wiki. At least mxODBC is fully ready for Python 3.1, but I haven't used it so I can't comment on its appropriateness...

There is a pymssql module. Here you can find installation instructions

I found a module called CEODBC that I was able to use with Python 3 after doing some research. It looks like they will also be releasing a Python3 compatible version of PYODBC soon. Thanks for all your help.

Related

How to create a database in MySQL then link it to Python

I am trying to create a database that I can then read from / write to in Python. I've tried installing the recommended dev installation via this https://dev.mysql.com/downloads/windows/installer/8.0.html. I then went into the designer and added a table with some entities. However, the UX in MySQL is really terrible and I can't work out how to actually view the table in the database I've just created and add test values or whatever. I got frustrated and uninstalled MySQL completely because either I downloaded it incorrectly (I selected dev machine but I want to develop and run it on this machine, was that the wrong option?) or it's just terrible to deal with. However, it seems like there are no real alternatives unfortunately and so I would appreciate some help with regards to just setting up a simple database and connecting it to Python so I can perform SQL statements from my Python code. Also, another complication is that my normal Python installation (i.e. the one linked to PATH etc.) is 3.6, but I was forced to install 3.7 when I downloaded MySQL so I'm not really sure how that will work.
Thanks.

How do I use bugzilla's webservice xml-rpc with python?

I need to know how to log into bugzilla using python. I have no idea where to start. The only requirement I got is that I have to use bugzilla's webservice xml-rpc. I also have no experience with python. So could anyone tell me the basic steps I need to take to import bugzilla using python? Thanks.
I have python installed on linux and can run code like print "hello world!". But I did not download any additional plugins.
Do I need this plugin: https://pypi.python.org/pypi/python-bugzilla/1.1.0?
Finally figured it out:
bz = bugzilla.Bugzilla(url='https://bugzilla.redhat.com/xmlrpc.cgi')
bug = bz.getbug(495561)

How to distribute a Python program with embedded Firebird SQL for Linux and Windows

Summary:
What is the best (easiest, most flexible, simplest) way to redistribute a Firebird SQL database with Python code in a way that end users can use it without going to the trouble of installing and maintaining Firebird?
Background (somewhat long-winded):
I've been trying to write a program that sifts through stock fundamentals and appraises different companies' stock based on those fundamentals and randomized weights. I noticed that after some length of time, the program seemed to just stall. I did use multi-threading here and there, and I considered dead/livelocks, but apart from just combing through the code and seeing if it makes sense, I can't debug that. I noticed I was also eating up a lot of RAM, since all this data was held in big Python dicts in memory. So I figured putting it in SQL databases would fix that.
After a few weeks, I got the code working again with SQLAlchemy and SQLite. Now the problem is that the appraisal function takes ten minutes (!) per stock. Multiplied by a total of twelve "genomes" competing initially, this would add up to around 200 hours. I started thinking maybe this had to do with SQLite's concurrency locks, or something along those lines, so I started trying to use Firebird, since it is the only other one I know that stores a database in a file.
Question elaboration:
Ideally, I would be able to just throw my code on a disk or a server, take it to another computer with Python on it, and run everything out of the box. That's doable with SQLite. Is it possible with Firebird? I know that there is a separate embedded package for Windows, but that Linux only has the libfbembed library that ships with the Classic server. The docs said that Linux always requires some version of the Firebird server proper to be installed.
Will end users need to do any database administration to make that work; that is, will they need to set up users and such manually, as if I had just given them an fdb file and told them to figure out the rest? Or is it enough to install the basic packages for Firebird? Will I ever be able to get something close to the simplicity of SQLite in redistributing Firebird databases? Is there any special syntax I need to pass to SQLalchemy/FDB/Kinterbasedb to use an embedded server? (I could not find anything about this on either SQLalchemy or FDB's websites). Can my program run seamlessly on Linux and Windows, or will there need to be slightly different setups for each case?
Thanks in advance, anyone who can answer some of these questions.
Well, i only can give partial answers. But i think that'll be enough to start with.
Let's start with the Firebird embedded thing: As you have written - using linux as os you have to provide a full install. There is no other way.
HINT: Use the native tgz provided from firebird, not any package delivered from distribution - to avoid dependency hell.
Installing Firebird on Windows : The Windows Firebird Installer is mostly a 'click-through' thing. Luckily you can customize the installer: Install Firebird and look into doc\scripted-install.txt.
HINT: on Win7/8 don't install into %PROGRAM FILES% or %PROGRAM FILES (x86)%
Talking to firebird:
AFAIK you have two options, but for both i don't know if and how they will work with SQLAlchemy:
The fdb module which comes from firebird. When installing the fdb package make shure the appropriate fbclient.dll is in the search path.
the pyfirebirdsql module: https://github.com/nakagami/pyfirebirdsql/ which needs no dll or that. Partial drawback - it is not as fast as the fdb module as there is no real database engine. Personally i only use it for short lookups.
Using the fdb module you also can talk to the firebird services api - from creating over dropping databases to querying header statistics, ending up with backup/restore actions.
That should at least answer the question if the end user needs to perform any database administration.

query rdf file windows

I wanna know how to query a RDF file using Sparql on windows. I'm using python 2.7 and on linux os.system(roqet... ) is there something similar to roqet (rasqal) on windows, like curl for example?, can I make this query with rdflib or something like that? it is very important that this rdf is not online, I wanna perform this query locally through the file.
Thanks
Take a look at either the ARQ tools provided by Apache Jena which will run on Windows provided Java is installed
Or take a look at the rdfQuery tool provided by dotNetRDF which will run on Windows provided .Net 4.0 Full is installed
Disclaimer - I'm a developer on both of the above projects
If your file is reasonably small (less than a few 100,000 triples), I would highly recommend RDFlib, as you suggested. It can be used anywhere you've installed Python and allows full use of SPARQL (both select and update/delete statements), and also gives many other handy features that can be utilized on a local file completely in-memory.
The nice part about using RDFlib is that to get it up and running requires only adding the Python library, so it is very simple to install.

What are the most popular open source ODBC interfaces for python?

I was wondering what are the most popular open source obdc/database connection libraries are.
I've heard of pyodbc, but I wasn't sure how widely used it was.
Thanks
If you use Windows, then in popular Active State distribution you will find odbc module. I think it is part of pywin32 package. Of course pyodbc will be better if you do not use MS Windows. All you have to do is:
import odbc
connection = odbc.odbc('dsnname/user/passwd')
While pydobc connect string looks different you can made your program work with both libraries:
if '/' in connect_string:
import odbc
# dsnname/user/password
_CONN = odbc.odbc(connect_string)
elif connect_string.startswith('Driver='):
import pyodbc
# Driver={PostgreSQL};Server=db-test;Port=5435;Database=dbname;Uid=user;Pwd=password;
_CONN = pyodbc.connect(connect_string)
I would also like to point out turbodbc. It is open source, actively maintained, compatible with Python 2 and 3, and available for Linux, OSX, and Windows. You might want to give it a shot since it often improves on pyodbc's performance due to the use of bulk operations. It also offers built-in NumPy support, if you are into that kind of thing. Check out the official documentation, in particular the getting started guide.
http://wiki.python.org/moin/ODBC details some of the ODBC solutions for Python. pyodbc seems to be your best option for a few reasons:
It appears to be the only open source option, having an MIT style license
It's cross-platform
Sadly, I have no way of providing you much further information because Google Code is down, and that's where pyodbc is hosted (along with many others). It seems to be the closest to a standard solution, however.
Update
Google Code is back up and it seems to me from the project site that pyodbc is very actively contributed to and maintained, and it seems to be keeping up with Python, as a 3.x port is coming soon.

Categories

Resources