Macaron is a small and simple object-relational mapper (ORM) for SQLite and Python. It is distributed as a single file module which has no dependencies other than the Python Standard Library.
Macaron provides easy access methods to SQLite database. And it supports Bottle web framework through plugin mechanism.
Example:
>>> import macaron >>> # You need to have initialized your model before; see tutorial >>> macaron.macaronage(dbfile="members.db") >>> team = Team.create(name="Houkago Tea Time") >>> team.members.append(first_name="Ritsu", last_name="Tainaka", part="Dr") <Member object 1> >>> mio = team.members.append(first_name="Mio", last_name="Akiyama", part="Ba") >>> print mio <Member 'Mio Akiyama : Ba'> >>> for member in team.members: print member ... <Member 'Ritsu Tainaka : Dr'> <Member 'Mio Akiyama : Ba'>
Macaron supports Many-To-One and Many-To-Many (new in 0.4.0-dev) relationships and reverse reference. To realize simple implementation, Macaron does not provide methods for creation of tables.
MacaronPlugin class for Bottle web framework is implemented.
- Homepage and documentation: http://nobrin.github.com/macaron/
- Documentation in Japanese: http://biokids.org/?Macaron
- Python Package Index (PyPI): http://pypi.python.org/pypi/macaron
- GitHub: https://github.com/nobrin/macaron
tar zxvf macaron-0.3.0.tar.gz cd macaron-0.3.0 python setup.py
or using easy_install:
easy_install macaron
Bottle is a lightweight web framework for Python. Macaron can be used with Bottle through :class:`MacaronPlugin`, which is tested with Bottle 0.10.9.
#!/usr/bin/env python from bottle import * import macaron install(macaron.MacaronPlugin("address.db")) class Address(macaron.Model): _table_name = "address" @route("/hello") def index(): addr = Address.get(1) return "<h1>Hello!!</h1>My address is %s" % addr.address run(host="localhost", port=8080)
:class:`MacaronPlugin` create lazy connection. So the :class:`sqlite3.Connection` object is create at call Macaron methods. In case of no use the methods in :meth:`bottle.route`, any connection is created.