Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CT-1770] [Feature] [Spike] Review programmatic entry point for top-level commands #6550

Closed
Tracked by #6356
jtcohen6 opened this issue Jan 8, 2023 · 2 comments
Closed
Tracked by #6356
Labels
enhancement New feature or request python_api Issues related to dbtRunner Python entry point spike

Comments

@jtcohen6
Copy link
Contributor

jtcohen6 commented Jan 8, 2023

Status quo

Here's how the "thin layer" for programmatically invoking dbt works today, on the feature/click-cli feature branch:

# initialize
from dbt.cli.main import dbtRunner
dbt = dbtRunner()

# need to pass CLI-style args as an ordered list
cli_args = ['--fail-fast', 'run', '--select', 'tag:my_tag+2', 'another_model', '--exclude', 'not_this_model']

# 'results' is List[RunResult], 'success' is boolean
results, success = dbt.invoke(cli_args)

It's very very important that dbt-core's Python API is able to accept anything that you could also throw at its CLI. We should by no means take away this implementation; it works exactly in the ways it needs to. That said, it might not be in line what what community members are expecting the Python API to look & feel like.

Proposal

Another entry point could enable users to pass in structured data, and call a top-level method matching the desired command:

# initialize
from dbt.main import dbtRunner  # not dbt.cli.main
dbt = dbtRunner()

# https://docs.getdbt.com/reference/global-configs
global_configs = {"fail_fast": true}

# these could still be CLI-style strings
select = "tag:my_tag+ another_model"
exclude = "not_this_model"

# top-level method matching the CLI subcommand
results, success = dbt.run(
    select=select,
    exclude=exclude,
    global_configs=global_configs
)

For selection syntax, we could also mirror the data structure of yaml selectors:

one_off_selector = {
    "union": [
        {"method": "tag", "value": "my_tag", "children": true, "children_depth": 2},
        "another_model",
        "exclude": ["not_this_model"]
    ]
}
results, success = dbt.run(selector=one_off_selector, global_configs=global_configs)

Additional thoughts

@jtcohen6 jtcohen6 added enhancement New feature or request python_api Issues related to dbtRunner Python entry point Team:Execution labels Jan 8, 2023
@github-actions github-actions bot changed the title [Feature] Review programmatic entry point for top-level commands [CT-1770] [Feature] Review programmatic entry point for top-level commands Jan 8, 2023
@nathaniel-may
Copy link
Contributor

A big part of this ticket is to discuss what using dbt as a "library" really looks like. We may need follow up tickets to this one after that discussion.

@nathaniel-may nathaniel-may changed the title [CT-1770] [Feature] Review programmatic entry point for top-level commands [CT-1770] [Feature] [Spike] Review programmatic entry point for top-level commands Jan 12, 2023
@jtcohen6 jtcohen6 added the spike label Jan 15, 2023
@ChenyuLInx
Copy link
Contributor

Internal conversation going on about this topic. Closing in favor upcoming issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request python_api Issues related to dbtRunner Python entry point spike
Projects
None yet
Development

No branches or pull requests

3 participants