I often use Python to prototype ideas for other platforms, a scratch pad of sorts. Right now I want to play with some ideas related to relational data in a database.
What is the best way to represent a database in Python? A set of tuples? Using a module like SQLite?
I’m looking for simple solutions in Python. If the solution is too “databasey” I mine as well do my prototyping in the database itself.
UPDATE: I wont actually be using Python with the database (I don’t even have a specific database in mind), I just want to think with codes about questions like “If I have X relational data, can I answer Y questions, and solve Z problems?”
Either sqllite3 or an Object Relational Mapper such as SQLAlchemy.
sqllite3is very easy to set up and works just like a SQL database (for prototyping purposes, of course- not for production).SQLAlchemy is a great way to work with a real database engine (which can itself be sqllite3) as if it were a set of objects. Creating a table, for example, looks something like this (from this tutorial):
Similarly, it has simple functions and classes that allow you to insert elements, create relationships, and everything else you can do in a database.
ETA: I understand you won’t actually be using Python with the database. However, working with an ORM like SQLAlchemy lets you deal with relational data as objects. It is approximately as easy as any form of prototyping, with the added benefit that it is closer to what you’ll end up doing.