im working on python application that requiring database connections..I had developed my application with sqlite3 but it start showing the error(the database is locked).. so I decided to use MySQL database instead.. and it is pretty good with no error..
the only one problem is that I need to ask every user using my application to install MySQL server on his pc (appserv for example) ..
so can I make mysql to be like sqlite3 apart of python lib. so I can produce a python script can be converted into exe file by the tool pyInstaller.exe and no need to install mysql server by users???
update:
after reviewing the code I found opened connection not closed correctly and work fine with sqllite3 ..thank you every body
It depends (more "depends" in the answer).
If you need to share the data between the users of your application - you need a mysql database server somewhere setup, your application would need to have an access to it. And, the performance can really depend on the network - depends on how heavily would the application use the database. The application itself would only need to know how to "speak" with the database server - python mysql driver, like MySQLdb or pymysql.
If you don't need to share the data between users - then sqlite may be an option. Or may be not - depends on what do you want to store there, what for and what do you need to do with the data.
So, more questions than answers, probably it was more suitable for a comment. At least, think about what I've said.
Also see:
https://stackoverflow.com/questions/1009438/which-database-should-i-use-for-my-desktop-application
Python Desktop Application Database
Python Framework for Desktop Database Application
Hope that helps.
If your application is a stand-alone system such that each user maintains their own private database then you have no alternative to install MySQL on each system that is running the application. You cannot bundle MySQL into your application such that it does not require a separate installation.
There is an embedded version of MySQL that you can build into your application (thanks, Carsten, in the comments, for pointing this out). More information is here: http://mysql-python.blogspot.com/. It may take some effort to get this working (on Windows you apparently need to build it from source code) and will take some more work to get it packaged up when you generate your executable, but this might be a MySQL solution for you.
I've just finished updating a web application using SQLite which had begun reporting Database is locked errors as the usage scaled up. By rewriting the database code with care I was able to produce a system that can handle moderate to heavy usage (in the context of a 15 person company) reliably still using SQLite -- you have to be careful to keep your connections around for the minimum time necessary and always call .close() on them. If your application is really single-user you should have no problem supporting it using SQLite -- and that's doubly true if it's single-threaded.
Related
I am leaning Python programming language. I have no problems with Python. I read Python official docs, and I can write small programs in Python. I want to familiarize myself with mysql database because it is useful in learning software development concepts. I've installed mysql database and Django on my computer. I have Ubuntu 14.04 and python 3.4 installed. I've configured Django settings to use mysql database. I tested Django connection to mysql db and all things work properly.
I am a complete newbie with web development. I didn't create my own website and I didn't start developing any web application.
My purpose currently is to master creation of mysql database and tables, making changes/migrations/queries, using Django models and Python.
Is it reasonable/possible to use Django ORM for work with mysql database without simultaneous development of a web application/local application? As I've said, I don't have my own website. I want just to try using mysql and Django together on my computer in order to get deeper knowledge as to Django and mysql in this respect.
My final purpose is development in Python, including work with mysql database.
Mysql without Python and Django is of no use for me.
If you want to learn and use MySQL, then start without anything above it - no Django, no ORM, not even a Python script. Learn to configure your mysql server (the server process I mean - doesn't have to be on a distinct computer), to work with the command-line mysql client (database creation, tables creations / modifications, adding/updating/deleting rows, and, most important, doing simple and complex queries).
While you're at it, learn about proper relational data modeling (normalisations etc) so you fully understand how to design your schemas.
Once you're confortable with this, spend some time (should be quite fast at this point) learning to do the same things from python scripts with your python's version mysql connector.
Then if you want to learn web development and Django, well go for it. The ORM is quite easy to use when you already have a good understanding of what happens underneath, so by that time you shouldn't have much problems with this part. What you'll still have to learn are the HTTP protocol (trying to do web programming without understanding the HTTP protocol is like trying to win a car race without knowing how to drive a car - it's not technically impossible but it might end up being very painful experience), then front-end stuff (html/css/javascript) and finally the views / templates parts of Django (which should be easy once you know HTTP and html).
You can of course jump right in into Django, but you will probably fight with way too many concepts at once and end up spending twice more time to figure out how everything works and why it works that way.
So I am creating a local Python script which I plan to export as an executable. However, this script is in need of a MongoDB instances that runs in the background as a service or daemon. How could one possibly include this MongoDB service along with their own ported application?
I have this configuration manually installed on my own computer with a MongoDB database installed as a local Windows service, and Python where my script adds and removes to the database as some events are fired. Is there any possible way to distribute this setup without manual installation of Python and MongoDB?
If you want to include installations of all your utilities, I recommend pynsist. It'll allow you to make a Windows installer that will make your code launchable as an app on the clients system, and include any other files and/or folders that you want.
Py2exe converts python scripts and their dependencies into Windows executable files. It has some limitations, but may work for your application.
You might also get away with not installing mongo, by embedding something like this in your application: https://github.com/Softmotions/ejdb. This may require you to rewrite your data access code.
If you can't or don't do that, then you could have all your clients share a multi-tenant mongo that you host someplace in the cloud.
Finally, if you can't or won't convert your python script to a standalone exe with an embedded database, and you don't want to host a shared mongo instance for your clients, there are legions of software installation makers that make deploying mongo, python, setting up an execution environment, creating services, etc, pretty easy. Some are free, some cost money. A long list can be found here: https://en.m.wikipedia.org/wiki/List_of_installation_software
I'm currently exploring using python to develop my server-side implementation. I've decided to use SQLAlchemy for database stuff.
What I'm not currently to sure about is how it should be set up so that more than one developer can work on the project. For the code it is not a problem but how do I handle the database modifications? How do the users sync databases and how should potential data be set up? Should/can each developer use their own sqlite db for development?
For production postgresql will be used but the developers must be able to work offline.
You can use Alembic to manage your DB structure. Keep your migrations under version control in order to ensure that it's easy for developers to keep in sync with changes.
As regards data itself, you can either work with a set of fixtures, or you could write some Fabric commands to import/export Postgres dumps, which you could also keep under version control if necessary – depending on data size, you may not want to keep a large uncompressed SQL dump under version control (though it will compress well using git or hg), however. This aspect of your question depends on the size of your development team, and the size of your database.
Make sure you have a python programs or programs to fill databases with test data from scratch. It allows each developer to work from different starting points, but also test with the same environment.
i am new in python.before this i done some work in php with codeigniter framework.
now i want to develop website using python and sqlite3.
so which framework will you suggest me.
i also want to know IDE for sqlite.
Do you mean something similar to sqliteman or dbeaver? These are not not IDEs for SQLite, but instead, are GUI interfaces. There are more here: http://www.google.com/search?&q=sqlite+gui
3rd link down is another stack overflow question: What are good open source GUI SQLite database managers?
For Python web frameworks, a very popular full-stack framework is the Django Project
Check out web2py. It's a feature-rich full-stack framework, but it's also very easy to set up, learn, and use. It requires no installation or configuration, has no dependencies, and includes its own web server and web-based IDE/administrative interface (see demo). If you download the binary version for Windows or Mac, it even includes its own Python interpreter (so you don't need to have Python installed).
The database abstraction layer (DAL) works with 10 different database backends, including SQLite. It doesn't include its own SQLite IDE, though it does include a database administrative interface called appadmin, which allows you to view all database tables; view, insert, update, and delete records within each table; and import/export tables to CSV. You can also import and export the entire database to CSV. (Note, these features work for all database backends, not just SQLite.)
You will probably also find that you don't really need an IDE for SQLite when using web2py because the DAL takes care of everything for you. You specify all of your data models using the DAL syntax, and then the DAL automatically creates the SQLite database, creates all tables, and handles migrations when you changes your models.
If you have any questions, there's a friendly and responsive mailing list that will provide lots of help.
I'm writing a script to parse some text files, and insert the data that they contain into a mysql database. I don't have root access on the server that this script will run on. I've been looking at mysql-python, but it requires a bunch of dependencies that I don't have available. Is there a simpler way to do this?
I would recommend the MySQL Python Connector, a MySQL DB-API adapter that does not use the C client library but rather reimplements the MySQL protocol completely in pure Python (compatible with Python 2.5 to 2.7, as well a 3.1).
To install C-coded extensions to Python you generally need root access (though the server you're using might have arranged things differently, that's not all that likely). But with a pure Python solution you can simply upload the modules in question (e.g. those from the Connector I recommend) just as you're uploading those you write yourself, which (if you of course do have a valid userid and password for that MySQL database!-) might solve it for you.