Once you know how it works, you may want to use an ORM to avoid writting SQL manually and manipulate your tables as they were Python objects. The most famous ORM in the Python community is SQLAlchemy.
I strongly advise you to use it: your life is going to be much easier.
I recently discovered another jewel in the Python world: peewee. It's a very lite ORM, really easy and fast to setup then use. It makes my day for small projects or stand alone apps, where using big tools like SQLAlchemy or Django is overkill :
from peewee import *
db = MySQLDatabase('jonhydb', user='john',passwd='megajonhy')
author = peewee.CharField()
title = peewee.TextField()
database = db
book = Book(author="me", title='Peewee is cool')
for book in Book.filter(author="me"):
Peewee is cool
This example works out of the box. Nothing other than having peewee (
pip install peewee :-)) is required. No complicated setup. It's really cool.
- answered 5 years ago
- Gul Hafiz