Skip to main content

Simple database interface for text analysis applications.

Project description

doctable Python Package

See the doctable website for documentation and examples.

Created by Devin J. Cornell.

Doctable has a new interface!

The package has been updated with an entirely new API to improve on previous limitations and better match the Sqlalchemy 2.0 interface. Inspired by the attrs project, I used different names for functions and classes to make it clear that the interface has changed and open the possibility for backwards compatibility with upgraded internals in the future.

For now, stick to installing from the legacy branch when using sqlalchemy <= 1.4, and the master branch for sqlalchemy >= 2.0.


From Python Package Index: pip install doctable

For sqlalchemy >= 2.0: pip install --upgrade git+

For sqlalchemy <= 1.4: pip install --upgrade git+

Changes in Version 2.0

  • Create database connections using ConnectCore objects instead of ConnectEngine or DocTable objects.

  • Database tables represented by DBTable objects instead of DocTable objects. All DBTable instances originate from a ConnectCore object.

  • Create schemas using the doctable.table_schema decorator instead of the doctable.schema decorator. This new decorator includes constraint and index parameters as well as those for the dataclass objects.

  • The Column function replaces Col as generic default parameter values with more fine-grained control over column properties. This function provides a clearer separation between parameters that affect the behavior of the object as a dataclass (supplied as a FieldArgs object) and those that affect the database column schema (supplied via a ColumnArgs object).

  • New command line interface: you may execute doctable functions through the command line. Just use python -m doctable execute {args here} to see how to use it.


See the examples/ directory for more detailed examples.

Basic steps

These are the basic steps for using doctable to create a database connection, define a schema, and execute queries. For more examples, see the doctable website.

1. Create a database connection.

core =
    target=':memory:', # use a filename for a sqlite to write to disk

2. Define a database schema from a dataclass.

class MyContainer:
    name: str
    age: int
    id: int = doctable.Column(
        column_args=doctable.ColumnArgs(order=0, primary_key=True, autoincrement=True),

3. Emit DDL to create a table from the schema.

with core.begin_ddl() as emitter:
    tab0 = emitter.create_table(container_type=MyContainer)

4. Execute queries on the table.

with tab1.query() as q:
    q.insert_single(MyContainer(name='devin', age=40))

>> MyContainer(name='devin', age=40, id=1)

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

doctable-2.0.tar.gz (26.7 kB view hashes)

Uploaded Source

Built Distribution

doctable-2.0-py3-none-any.whl (35.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page