Skip to main content

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)

Metadata

Release files for doctable 2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for doctable 2.0
File Size Uploaded Provenance Actions
doctable-2.0.tar.gz 26.7 kB Without provenance Details for doctable-2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for doctable 2.0
File Interpreter ABI Platform Actions
doctable-2.0-py3-none-any.whl Python 3 none any Details for doctable-2.0-py3-none-any.whl

Total release size: 61.9 kB

Release files / doctable-2.0.tar.gz

Download URL doctable-2.0.tar.gz
Size 26.7 kB
Tags Source
SHA-256 checksum
How to use checksums
7857c072b154817d2cd21f605c8235b1d57146876740354c1f29b0aca48c74d6
BLAKE2b-256 checksum
How to use checksums
d54131d01fe56fa77cad0be04ca9ff084c1b02efa3cc9f4873bfe0407df8b7c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / doctable-2.0-py3-none-any.whl

Download URL doctable-2.0-py3-none-any.whl
Size 35.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0d84346a306b484c4b440716b2e89ecb1886ce6872e157d6c052db5dc65d733a
BLAKE2b-256 checksum
How to use checksums
bcd08a2bbcc2b4c1606f4edfadb7ce653d2521ff39f1e1216a1f08bfc25cfa2c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Security for doctable 2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page