Skip to main content

Build Status

dbt_docstring

Docstring dbt test & documentation in SQL file

What is it?

dbt has a test and documentation feature where models/schema.yml is the definition file. While this is already a big help for testing and documentation in ELT, not being able to keep documentation in the source code may cause more documentats out of sync with the source.

dbtdocstr lets you write docment in a docstring style directly in .sql files.

Install

pip install dbt_docstring

How does it work?

dbtdocstr command scans .sql files under dbt's models directories and look for a block that begins with ```dbt and end with ```. Inside the block you can write the content of the models section of schema.yml corresponding to the current table as specified in dbt document:

Example (<dbt_root>/models/api_key_status.sql)

/*
# API key status

This table lists the API keys with the status.

```dbt
columns:
  - name: api_key
    description: API key
    tests:
      - unique
  - name: enabled
    description: True if API key is enabled status
  - name: update_datetime
    description: Last update date and time
```
*/
SELECT
   api_key,
   enabled,
   update_datetime
FROM {{ ref('my_api_key_list') }}

Then run:

dbtdocstr <dbt_project_root_directory>

These two files will be auto-generated from each .sql file in the dbt project:

models/docs.md:

# This file was auto-generated by dbtdocstr.
# Don't manually update.
# https://github.com/anelendata/dbt_docstring

{% docs api_key_status %}
# API key status

This table lists the API keys with the status.
{% enddocs %}

models/schema.yml:

# This file was auto-generated by dbtdocstr.
# Don't manually update.
# https://github.com/anelendata/dbt_docstring

version: 2
models:
  - name: api_key_status
    description: '{{ docs("api_key_status") }}'
    columns:
      - name: api_key
        description: API key
        tests:
          - unique
      - name: enabled
        description: True if API key is enabled status
      - name: update_datetime
        description: Last update date and time
  - name: ...

To see the document generation, use dbt command:

dbt docs generate
dbt docs serve

Notes

  • The doc must be a SQL comment block comment that begins with '/*' and ends with '*/'
  • The first comment block will be extracted.
  • The dbt block is searched within the first comment block.
  • Any text after the dbt block will be ignored.
  • dbt's Docs Blocks feature can be used only for table & view description. Not column descriptions.
  • dbtdocstr --backup <dbt_root_directory> to create backup files of schema.yml and docs.yml if they exsit.

Original repository

About this project

This project is developed by ANELEN and friends. Please check out the ANELEN's open innovation philosophy and other projects

ANELEN

Copyright © 2020~ Anelen Co., LLC

Release files for dbt-docstring 0.1.6

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

Source distribution (sdist)

Source distribution for dbt-docstring 0.1.6
File Size Uploaded
dbt_docstring-0.1.6.tar.gz 8.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dbt-docstring 0.1.6
File Interpreter ABI Platform
dbt_docstring-0.1.6-py3-none-any.whl Python 3 none any Details

Total release size: 18.4 kB

Release files / dbt_docstring-0.1.6.tar.gz

Download URL dbt_docstring-0.1.6.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
85b11f619cc21e0b999085420a9ce4a115b1ed6bbd3274902f1ab55262f75cb6
BLAKE2b-256 checksum
How to use checksums
5e4dc1d1debe9c41e2c0aca397fbd4c30057e0c13048fe711c1e6f7de7eab40f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release files / dbt_docstring-0.1.6-py3-none-any.whl

Download URL dbt_docstring-0.1.6-py3-none-any.whl
Size 9.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
54f7574a29472673cfd6d5896a5e3cf54c51b46405ba6d604d189823f6302441
BLAKE2b-256 checksum
How to use checksums
4eb8a918fbc0ab787b1a02a34418932b04a92ac920963315777dd95b7607938e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release history Release notifications | RSS feed

This release

0.1.6 This release

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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