What is the best way to use an embedded database, say sqlite in Python:
start with Django
http://www.djangoproject.com/
ORM is the way to go here. You won't regret it. The tutorial here http://docs.djangoproject.com/en/dev/intro/tutorial01/ is fairly gentle.
Why Django/ORM ? Django will have you up an running in about half an hour, will manage your database connections, data management interfaces, etc. Django works SQLLite: you won't need to manage a MySQL/PostGre instance.
EDIT1: You don't need to use the web-app portion of Django for this. You can use the db.Model classes to manipulate your data directly. Whatever standalone app/script you will come up with, you can just use the Django data-model layer. And when you decide you want a web front-end, or atleast would like to edit your data via the admin console - you can post back here and thank me ( or everyone that said use an ORM ) :)
There's an easy-to-use Python module that meets all the stated objectives:
http://yserial.sourceforge.net/
Serialization + persistance: in a few lines of code, compress and annotate Python objects into SQLite; then later retrieve them chronologically by keywords without any SQL. Most useful "standard" module for a database to store schema-less data.
Surprisingly, there is not much difference between in-memory and persistent solutions for most practical purposes.
As for "shield me from the actual database", with y_serial, one cannot even tell that SQLite is behind it all. If you construct your records as Python dictionaries, you can concentrate on just writing code (not stored procedures).
This is an aggregate of answers, in no particular order:
Everybody is recommending an ORM layer. Which makes perfect sense, if you really need a database. Well, that was sort of requested in the title :-)
But I'm starting to think that if an in-memory database is sufficient, in this will be used in scripts only, not a web app or even a desktop gui, then option 7 is also perfectly valid, provided no transaction support is needed and "database" integrity is not an issue.
Django is perfect for this but the poster is not clear if he needs to actually make a compiled EXE or a web app. Django is only for web apps.
I'm not sure where you really get "heavy" from. Django is grossly smaller in terms of lines of code than any other major web app framework.
Another option to add to the other good suggestions: Elixir. It provides a simplified declarative layer on top of SQLAlchemy
, so it should be easier to dive into, but it also allows you to call upon the full power of SQLAlchemy
if and when you need it.
If you don't want to use an ORM, you can give a try to python-sql to create your SQL queries.