Menu

Tree [27b78f] master /
 History

HTTPS access


File Date Author Commit
 .github 2025-02-28 Oleg Broytman Oleg Broytman [5c8fe5] Tests(GHActions): Better error handling
 debian 2016-08-09 Oleg Broytman Oleg Broytman [e17be4] Rename reStructuredText file from *.txt to *.rst
 devscripts 2025-03-07 Oleg Broytman Oleg Broytman [0217eb] Release 3.13.0
 docs 2025-03-07 Oleg Broytman Oleg Broytman [27b78f] Build: Prepare for the next release
 scripts 2015-03-02 Neil Neil [c8b19c] Update scripts to user print function
 sqlobject 2025-03-07 Oleg Broytman Oleg Broytman [0217eb] Release 3.13.0
 .gitignore 2018-04-01 Oleg Broytman Oleg Broytman [6e1705] Build(.gitignore): Ignore `.pytest_cache`
 ANNOUNCE.rst 2025-03-07 Oleg Broytman Oleg Broytman [27b78f] Build: Prepare for the next release
 LICENSE 2016-10-05 Oleg Broytman Oleg Broytman [1aab65] Move docs/LICENSE to the top-level directory so...
 MANIFEST.in 2021-09-27 Oleg Broytman Oleg Broytman [d2921e] Tests(tox): Stop collecting test coverage
 README.rst 2025-03-07 Oleg Broytman Oleg Broytman [0217eb] Release 3.13.0
 setup.cfg 2025-02-01 Oleg Broytman Oleg Broytman [d13705] Build: Prepare for the next release
 setup.py 2025-03-07 Oleg Broytman Oleg Broytman [27b78f] Build: Prepare for the next release
 tox.ini 2025-03-07 Oleg Broytman Oleg Broytman [c61aa5] Tests(tox): Rename `mysql-connector-python` tes...

Read Me

SQLObject 3.13.0

SQLObject is a free and open-source (LGPL) Python object-relational mapper. Your database tables are described as classes, and rows are instances of those classes. SQLObject is meant to be easy to use and quick to get started with.

SQLObject supports a number of backends: MySQL/MariaDB (with a number of DB API drivers: MySQLdb, mysqlclient, mysql-connector, PyMySQL, mariadb), PostgreSQL (psycopg, psycopg2, PyGreSQL, partially pg8000), SQLite (builtin sqlite3); connections to other backends - Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB) - are less debugged).

Python 2.7 or 3.4+ is required.

Example

Install:

$ pip install sqlobject

Create a simple class that wraps a table:

>>> from sqlobject import *
>>>
>>> sqlhub.processConnection = connectionForURI('sqlite:/:memory:')
>>>
>>> class Person(SQLObject):
...     fname = StringCol()
...     mi = StringCol(length=1, default=None)
...     lname = StringCol()
...
>>> Person.createTable()

Use the object:

>>> p = Person(fname="John", lname="Doe")
>>> p
<Person 1 fname='John' mi=None lname='Doe'>
>>> p.fname
'John'
>>> p.mi = 'Q'
>>> p2 = Person.get(1)
>>> p2
<Person 1 fname='John' mi='Q' lname='Doe'>
>>> p is p2
True

Queries:

>>> p3 = Person.selectBy(lname="Doe")[0]
>>> p3
<Person 1 fname='John' mi='Q' lname='Doe'>
>>> pc = Person.select(Person.q.lname=="Doe").count()
>>> pc
1
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.