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.


Installation

From Python Package Index: pip install doctable

For sqlalchemy >= 2.0: pip install --upgrade git+https://github.com/devincornell/doctable.git@master

For sqlalchemy <= 1.4: pip install --upgrade git+https://github.com/devincornell/doctable.git@legacy


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.


Examples

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 = doctable.ConnectCore.open(
    target=':memory:', # use a filename for a sqlite to write to disk
    dialect='sqlite',
)

2. Define a database schema from a dataclass.

@doctable.table_schema
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)
pprint.pprint(core.inspect_columns('MyContainer'))

4. Execute queries on the table.

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

>> 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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file doctable-2.0.tar.gz.

File metadata

  • Download URL: doctable-2.0.tar.gz
  • Upload date:
  • Size: 26.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for doctable-2.0.tar.gz
Algorithm Hash digest
SHA256 7857c072b154817d2cd21f605c8235b1d57146876740354c1f29b0aca48c74d6
MD5 749c55dc3e7213abd2eac4548ac8f0b3
BLAKE2b-256 d54131d01fe56fa77cad0be04ca9ff084c1b02efa3cc9f4873bfe0407df8b7c2

See more details on using hashes here.

File details

Details for the file doctable-2.0-py3-none-any.whl.

File metadata

  • Download URL: doctable-2.0-py3-none-any.whl
  • Upload date:
  • Size: 35.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for doctable-2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0d84346a306b484c4b440716b2e89ecb1886ce6872e157d6c052db5dc65d733a
MD5 c394c7ecd94b8e290486f3309db579e3
BLAKE2b-256 bcd08a2bbcc2b4c1606f4edfadb7ce653d2521ff39f1e1216a1f08bfc25cfa2c

See more details on using hashes here.

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