Skip to main content
Version: devel View Markdown

Profiles and environments

A profile controls access to your data. It holds the credentials that a pipeline or job runs with and declares what those credentials can do with the data: write it, only read it, or not touch it at all (none).

Every job, in turn, declares the data access that it needs. When you deploy, dltHub matches the two: each pipeline and job runs with the profile that gives the data access it declares, without any code on your side. In a new workspace, pipelines load with the prod profile and notebooks read with the access profile, see How a job gets its profile.

caution

You bring your own destination, so set up the rights of each credential there. dlt trusts the declaration and never checks what a credential can do. For example, give access a read-only database role, or a storage key without write permission.

Profiles also carry settings, so the same code loads into a local DuckDB file with dev and into your warehouse with prod, unchanged.

An environment is what you deploy the workspace to. In each environment, the workspace has a workspace deployment of its own, with its own set of profiles. The built-in prod environment is meant for production. With a staging environment, you can review your changes on a small slice of data before they reach production.

In short, a profile answers what can this code do with your data? and an environment answers where does this workspace run? An environment groups several profiles, so the jobs of one deployment can run with different data access.

How profiles work​

A new workspace declares five profiles:

ProfileLocationData accessUsed by
devlocalwriteyour machine, the default profile
testslocalwriteautomated tests, with state and data of their own
prodremotewritebatch jobs on the dltHub platform
accessremotereadinteractive jobs on the dltHub platform
no-accessremotenoneagent jobs that declare no data access

Data access​

Each profile declares its data access: write, read or none. Write includes read. A local profile always has write data access. A deployment reads the data access to give each job a profile, see How a job gets its profile.

Settings files​

The .dlt folder holds config.toml and secrets.toml, the files you know from OSS dlt. Everything in them applies to every profile. A profile adds <profile>.config.toml and <profile>.secrets.toml on top. A value in the settings file of a profile wins over the same value in the shared file. So the destination credentials of a profile go in its secrets file, and the settings that are the same everywhere go in config.toml.

.dlt/
├── .workspace # declares the profiles and environments
├── config.toml # settings of every profile
├── secrets.toml # credentials of every profile (gitignored)
├── dev.config.toml # settings of dev
├── prod.config.toml # settings of prod
├── prod.secrets.toml # credentials of prod (gitignored)
└── access.secrets.toml # credentials of access (gitignored)

A new workspace has no settings files for its profiles. Create them when you need them. For a profile that is already declared, dlthub profile add creates the files that are missing and changes nothing else:

dlthub profile add prod

Each profile has a state folder, .dlt/state/<profile>/, and a data folder, .dlt/data/<profile>/. Pipeline working directories and local DuckDB files live there. Two profiles never share state. dlthub local clean removes the folders of the active profile.

Local and remote profiles​

A local profile never leaves your machine. A deployment never reads or includes its settings files. dev and tests are local profiles. A remote profile belongs to an environment and deploys with it: its settings files go to the dltHub platform with the deployment. prod, access and no-access are the remote profiles of the prod environment.

Select a profile​

A command that works on your machine, such as dlthub local run, runs with one profile, the active profile. dlt picks it in this order:

  1. The profile named with --profile after the command name, as in dlthub local show --profile tests.
  2. The profile in the WORKSPACE__PROFILE environment variable. Runners set it for deployed jobs.
  3. The profile that dlthub local profile use <name> recorded in .dlt/profile-name.
  4. The default profile, dev.

dlthub local profile use prod makes prod the active profile for every local command that follows, until you make dev the active profile again. --profile and WORKSPACE__PROFILE override the recorded profile for one command or process and do not change it.

dlthub profile info shows the active profile with its location, data access, environment and folders. In code, it is dlt.current.workspace().profile.

How environments work​

note

Environments are available from dlt 1.33.0.

You deploy the workspace to one environment at a time. Each environment has a workspace deployment of its own on the dltHub platform, so prod and staging never share jobs, job runs or credentials. Workspace setup shows how the local workspace connects to each one. An environment declares:

  • its profiles, which deploy with it. prod, access and no-access deploy with the prod environment.
  • one default profile for each data access that its profiles have. A job that declares no profile gets the default profile of the data access that it declares. In prod, the default is prod for write, access for read and no-access for none.
  • whether it is strict about access.
  • whether it is the default environment.

Every environment has a default profile with write data access, its default write profile. dlthub deploy runs with it. The first profile of a data access that you add to an environment becomes the default for that data access.

Only the settings files of the profiles of an environment deploy with it, together with the shared config.toml, secrets.toml and .workspace. The credentials of prod never reach staging. By default, the workspace dashboard is deployed with the deployment module of the default environment only, see Choose the deployment module of an environment.

Select an environment​

A command that deploys or works with the remote workspace, its jobs, job runs, logs and traces, takes --environment after the command name. dlt picks the environment in this order:

  1. The environment named with --environment.
  2. The environment of the active profile, when that profile is a remote one.
  3. The default environment, prod in a new workspace.
dlthub deploy --environment staging

Here dlt generates the manifest and deploys with staging-write, the default write profile of staging. While a profile of staging is the active profile, a plain dlthub deploy deploys to staging, not to prod.

How a job gets its profile​

Every job declares the access that it needs to run. The data axis of the declaration is the data access of the job: write, read or none. The dltHub platform grants a job no more than it declares. The profile gives the credentials for it.

Declare access with access= on the job:

from dlt.hub import run

# a batch job that only reads
@run.job(access={"data": ["read"]})
def check_freshness() -> None:
...

A job without access declares the data access of its job type:

JobData access it declares
batch and stream jobs: @run.pipeline, @run.jobwrite
interactive jobs: notebooks, dashboards, MCP serversread
agent jobs without accessnone
any job with accesswhat data says: write or read. Without data it is none.

A deployment gives every job the default profile of the data access it declares. A job that declares a profile with require={"profile": ...} gets that profile. If the job declares no data axis, the deployment gives it the data access of that profile.

The workspace dashboard runs with the default read profile of its environment. It shows the pipelines that the default write profile of the environment ran, and reads their data with the credentials of the read profile. In an environment that is not strict, it runs with the default write profile as long as the read profile has no settings files, without a warning.

A strict environment accepts only a profile that gives exactly the data access a job declares and has settings files, <profile>.config.toml or <profile>.secrets.toml. Otherwise dlthub deploy fails and its message names the fix. A profile without data access holds no credentials and needs no settings files. Every environment that dlthub profile add-environment creates is strict.

The prod environment of a new workspace is not strict. There, a job that declares read data access runs with prod as long as access has no settings files, and dlthub deploy warns about it. This keeps existing workspaces working and lets a small team start with one set of credentials. When you add .dlt/access.secrets.toml with read-only credentials, the next deployment gives these jobs access.

note

This leniency of the prod environment is temporary. A future release will deprecate it.

On the dltHub platform, a job run makes the profile of the job the active profile before it imports the job module. dlthub local run runs with the active profile, or with the one named with --profile. A pipeline created at module level therefore uses the active profile of the run. Other jobs and notebooks can import the pipeline to read its dataset, see Access a dataset from another script, job or notebook.

How to use profiles and environments​

This section shows the common use cases, from the simplest to the most advanced.

Run on DuckDB locally and on a warehouse in production​

Give the destination a name in your pipeline. Each profile then says what the name means. dev points warehouse at a local DuckDB file. prod points it at MotherDuck, or at any cloud destination. The code does not change.

The steps below use the settings files of dev and prod. If the workspace does not have them yet, create them with dlthub profile add dev and dlthub profile add prod.

  1. In .dlt/dev.config.toml, define the local destination:
[destination.warehouse]
destination_type = "duckdb"
  1. Define the production destination. Its type goes in .dlt/prod.config.toml:
[destination.warehouse]
destination_type = "motherduck"

Its credentials go in .dlt/prod.secrets.toml:

[destination.warehouse]
credentials = "md:///dlt_data?motherduck_token=...."
  1. In the pipeline, use destination="warehouse". A job reads its settings from the [jobs.<module>] section of the active profile, so the limit of the load can differ per profile:
# pokemon_api_pipeline.py
import dlt
from dlt.hub import run
from dlt.hub.run import trigger

from pokemon_api import pokemon_source


@run.pipeline("pokemon_api_pipeline", trigger=trigger.every("1h"))
def load_pokemon(limit: int = dlt.config.value) -> None:
pipeline = dlt.pipeline(
pipeline_name="pokemon_api_pipeline",
destination="warehouse",
dataset_name="pokemon_api_data",
)
pipeline.run(pokemon_source().add_limit(limit))
  1. Set the limit of each profile. In .dlt/dev.config.toml:
[jobs.pokemon_api_pipeline]
limit = 10

In .dlt/prod.config.toml:

[jobs.pokemon_api_pipeline]
limit = 10000
  1. Run the job on your machine. The data lands in .dlt/data/dev/warehouse.duckdb and the state in .dlt/state/dev/:
dlthub local run pokemon_api_pipeline.py
  1. Deploy. The deployment is made with prod, so the job loads into MotherDuck on the dltHub platform:
dlthub deploy

Work with production data from your machine​

You can run a local command with the production credentials, for example to look at the data that the deployed jobs loaded. Name the profile on the command:

dlthub local show --profile prod

Here dlthub local show opens the dashboard with prod for this one command, and the active profile stays dev. To work with prod for longer, make it the active profile with dlthub local profile use prod, and return with dlthub local profile use dev when you are done.

Check the production credentials before the first deployment​

You can test the credentials of prod from your machine before you deploy. Restore the pipeline state from the destination with prod:

dlthub --debug local pipeline sync pokemon_api_pipeline --destination warehouse --dataset-name pokemon_api_data --profile prod

With wrong credentials, dlt raises an exception with the full stack trace. When the dataset does not exist yet, dlt reports Pipeline pokemon_api_pipeline was not found in dataset pokemon_api_data in warehouse. This message is expected before the first load.

caution

sync drops the local working directory of the pipeline in the prod profile and restores it from the destination. Run it only on a fresh state of prod, as here.

Run tests on the tests profile​

tests is a local profile with state and data folders of its own. Tests that run with it never touch the pipelines that you work on with dev. A test run and your notebook can run at the same time.

  1. Define warehouse for tests in .dlt/tests.config.toml, as for dev:
[destination.warehouse]
destination_type = "duckdb"
  1. When the test session starts, make tests the active profile in conftest.py:
import dlt
import pytest


def pytest_sessionstart(session: pytest.Session) -> None:
dlt.current.workspace().switch_profile("tests")

pytest calls the hook before it imports the test modules. So the jobs that the tests import, and the pipelines that they create at the module level, run with tests. A fixture runs only after the imports.

Or override the profile for one pytest run from the shell:

WORKSPACE__PROFILE=tests uv run pytest
  1. If a test fails, inspect the pipeline that it ran with --profile tests:
dlthub local pipeline trace pokemon_api_pipeline --profile tests
dlthub local pipeline failed-jobs pokemon_api_pipeline --profile tests
dlthub local show --profile tests

dlthub local clean --profile tests removes the data and state of the test runs.

Limit the data access of jobs​

A profile with read data access holds credentials that can only read. On the dltHub platform, a job that declares read data access gets the default profile with read data access: access in the prod environment. Interactive jobs declare read data access without any code. Define the destination for access as for prod: its type in .dlt/access.config.toml, and read-only credentials in .dlt/access.secrets.toml:

[destination.warehouse]
# a token of a user that can only read
credentials = "md:///dlt_data?motherduck_token=...."

Until access has settings files, these jobs run with prod, see How a job gets its profile.

A batch job declares write data access unless it says otherwise. Declare what the job needs with access=, and the deployment gives it access and not prod:

# freshness_checks.py
from dlt.hub import run
from dlt.hub.run import trigger


@run.job(access={"data": ["read"]}, trigger=trigger.every("1h"))
def check_freshness() -> None:
...

Some jobs need a profile of their own. An agent job that reads personal data to answer customer care tickets must not share access with every notebook. Add a profile with read data access to the environment. Then declare the profile on the job:

dlthub profile add sensitive-access --access read
# __deployment__.py
from dlt.hub import run

care_inspector = run.agent(
"agents/customer_care",
trigger="job.fail:tag:care",
require={"profile": "sensitive-access"},
)

sensitive-access deploys with the prod environment, together with its other profiles, and only this job runs with its credentials. The agent definition declares data: read, so the profile gives exactly the data access that the job declares. See Profile of an agent job.

A profile without data access has no destination credentials and needs no settings files. The prod environment has one: no-access. Agent jobs that declare no data access, such as those that only read logs and job runs, get it, so no data credential reaches the model. Declare one in another environment with --access none.

Check which profile each job gets​

You can see the profile that a deployment gives each job before you deploy. Print the deployment manifest of an environment by naming one of its profiles:

dlthub local info --show-manifest --profile prod
WARNING: profile `access` has no settings files: 1 job (`jobs.freshness_checks.check_freshness`) that declares read data access runs with `prod` (write data access). Create the settings files with `dlthub profile add access` to give them read data access.

Here dlt generates the manifest for the prod environment, and each job in it has its profile under require. access has no settings files yet, so dlt warns that the job that declares read data access runs with prod. In a strict environment, the command fails and names the profile to add. Without --profile, the active profile is a local one, and the manifest shows only the profiles that the jobs declare themselves.

Create a staging environment with its own workspace deployment​

In a staging environment, the same local workspace has a second workspace deployment, with credentials and settings of its own. Reviewers see your changes run on small data before the changes reach prod. This use case builds on the sensitive-access profile from Limit the data access of jobs.

  1. Declare the environment and its profiles:
dlthub profile add-environment staging
dlthub profile add staging-read --access read --environment staging
dlthub profile add staging-sensitive-access --access read --environment staging

staging is strict, and deployments to it use staging-write, its default write profile. staging-read is the first profile with read data access, so it is the default that interactive jobs get. Without it, a deployment with a notebook fails. staging-sensitive-access is not a default: only a job that declares it gets it.

  1. Put the staging credentials in .dlt/staging-write.secrets.toml, .dlt/staging-read.secrets.toml and .dlt/staging-sensitive-access.secrets.toml. Put the staging limit in .dlt/staging-write.config.toml:
[jobs.pokemon_api_pipeline]
limit = 100
  1. Vary the deployment by environment. The deployment module reads the environment, then decides which jobs to deploy and which profile a job declares:
# __deployment__.py
import dlt
from dlt.hub import run

from pokemon_api_pipeline import load_pokemon
import pokemon_notebook

__all__ = ["load_pokemon", "pokemon_notebook", "care_inspector"]

environment = dlt.current.workspace().environment

# the nightly report runs in production only
if environment == "prod":
from reports import nightly_report

__all__.append("nightly_report")

# the profile with the personal data: `environment` is None on a local profile
SENSITIVE_PROFILE = {"staging": "staging-sensitive-access"}

care_inspector = run.agent(
"agents/customer_care",
trigger="job.fail:tag:care",
require={"profile": SENSITIVE_PROFILE.get(environment, "sensitive-access")},
)
  1. Deploy to staging:
dlthub deploy --environment staging

dlt generates the deployment manifest with staging-write as the active profile, so environment in the module is staging. staging-write, staging-read and staging-sensitive-access deploy with the staging environment. The first dlthub deploy connects the local workspace in staging to the workspace deployment ingest-staging and writes [workspace.environment.staging] to config.toml. dlthub deploy without --environment deploys to prod as before.

  1. Work with the staging deployment. Name the environment on each command, or make a profile of staging the active profile:
dlthub job list --environment staging
dlthub local profile use staging-read
dlthub job list

While staging-read is the active profile, a plain dlthub deploy deploys to staging. When you are done, make dev the active profile again with dlthub local profile use dev.

Credentials and limits live in the settings files of each profile. The deployment module only changes which jobs deploy and which profile a job declares. To keep the jobs of staging in a module of their own, make it the deployment module of staging. The CI/CD blueprint deploys to staging from a GitHub pull request with this layout.

Declare profiles and environments​

dlt stores the declarations in .dlt/.workspace, a file that it writes for you. A new workspace declares the five profiles in How profiles work, with prod, access and no-access in the prod environment.

Add profiles and environments with the CLI. Both commands show what they add to .dlt/.workspace and which files they create, then ask before they change anything:

# the staging environment, deployed with staging-write
dlthub profile add-environment staging
# a profile with read data access in staging
dlthub profile add staging-read --access read --environment staging
# a profile with read data access in the default environment
dlthub profile add sensitive-access --access read
# a profile without data access in staging
dlthub profile add staging-none --access none --environment staging
# a local profile
dlthub profile add lab --local

profile add-environment <name> declares a strict environment with one profile, <name>-write, its default write profile. Then it prints the command that adds the profile with read data access that interactive jobs need. profile add declares one profile in the default environment, or in the environment named with --environment, with write data access unless --access says otherwise. The first profile of a data access in an environment becomes the default for that data access. With --local, it declares a local profile.

Both commands create <profile>.config.toml and <profile>.secrets.toml for each new profile with data access. A profile without data access takes the shared config.toml and secrets.toml. The commands keep existing files. For a declared profile or environment, the command creates the settings files that are missing. When none is missing, it shows the declaration and fails.

For anything else, edit .dlt/.workspace, for example to make another profile the default of its data access, see Edit the workspace file.

Choose the deployment module of an environment​

dlt imports the deployment module to find the jobs of a deployment. The deployment module is __deployment__.py by default. An environment can name another module with deployment_module in its section:

# .dlt/config.toml
[workspace.environment.staging]
deployment_module = "__staging__.py"

dlthub deploy --environment staging then imports __staging__.py. Give a .py path relative to the workspace, or a module name. A local profile uses the deployment module of the default environment, for example in dlthub local run. dlthub profile list shows the deployment module of each environment. dlthub local info shows the deployment module that it reads.

The workspace dashboard is deployed with the deployment module of the default environment, unless that environment is strict. A module that you name in dlthub deploy gets no dashboard. To decide for one environment, set deploy_dashboard in its section: true deploys the dashboard to any environment, also a strict one, and false deploys none.

Edit the workspace file​

dlthub profile add and dlthub profile add-environment cover the common changes. For anything else, edit .dlt/.workspace yourself. A new workspace declares:

engine_version: 1
environments:
prod:
default: true
strict_access: false
profiles:
prod:
data_access: write
default: true
access:
data_access: read
default: true
no-access:
data_access: none
default: true
local_profiles:
dev:
data_access: write
default: true
tests:
data_access: write

A profile under environments.<environment>.profiles is a remote profile, and a profile under local_profiles is a local one. default: true marks the default environment, the default local profile and, in each environment, the default profile of each data access. dlt validates the file on every command and names what to fix. Do not change engine_version.

You can make the following changes:

  • Make another profile the default of its data access. Move default: true to it. Every job of that data access that declares no profile then gets the new default, so give it settings files first. If you change the default write profile, deployments run with the new one.
  • Rename a profile. Rename its key, its settings files and its folders in .dlt/state and .dlt/data. Replace the old name in your code and in CI, and in .dlt/profile-name if it records the profile.
  • Make an environment strict. Set strict_access: true. First give the environment a default profile with settings files for each data access that its jobs declare, or the next deployment fails.
  • Change the default environment. Move default: true to another environment. First connect the local workspace in each environment, so that each one has its own section in config.toml.
  • Remove a profile or an environment. Remove its key and its settings files. If it was a default, move default: true first. Every environment keeps a profile with write data access.
caution

Keep the prod environment and its profiles prod, access and no-access. An empty workspace file declares them again, and the docs and the AI Harness refer to them by name. To deploy production somewhere else, add an environment next to prod.

Workspaces from before dlt 1.33.0​

The first time dlt loads such a workspace, it declares its profiles in .dlt/.workspace:

  • A profile whose settings files set a workspace_id other than the one in config.toml or secrets.toml gets an environment of its own, named after the profile. Deploy its jobs with --environment <profile>, or move its declaration to prod in .dlt/.workspace.
  • Any other profile with settings files, and the one recorded in .dlt/profile-name, becomes a write profile of prod. Its jobs deploy to prod as before.
  • A profile that only --profile or WORKSPACE__PROFILE names, as in CI, is not declared. Unset WORKSPACE__PROFILE and declare the profile with dlthub profile add.
  • An agent job that declares no data access and no profile gets no-access instead of access. If it reads access.secrets.toml, move those settings to secrets.toml or declare require={"profile": "access"}.

For the connection of such a workspace, see Workspaces connected before dlt 1.33.0.

Commands​

CommandWhat it does
dlthub profile listLists the declared profiles, with the workspace deployment of each environment.
dlthub profile infoShows the active profile: location, data access, environment and folders.
dlthub profile add <name>Declares a profile in an environment (--environment, --access) or a local profile (--local).
dlthub profile add-environment <name>Declares a strict environment with <name>-write as its default write profile.
dlthub local profile use <name>Makes a profile the active profile.
dlthub local cleanRemoves the state and data folders of the active profile.
dlthub <command> --profile <name>Overrides the recorded profile for one local command.
dlthub <command> --environment <name>Names the environment for a command that deploys or works with the remote workspace.
dlthub variable --workspaceSelects the variables of the whole workspace, in the environment that --environment names, else of the active profile, else the default one. Only commands that take --profile and --environment take it.

Next steps​

This demo works on codespaces. Codespaces is a development environment available for free to anyone with a Github account. You'll be asked to fork the demo repository and from there the README guides you with further steps.
The demo uses the Continue VSCode extension.

Off to codespaces!

DHelp

Ask a question

Welcome to "Codex Central", your next-gen help center, driven by OpenAI's GPT-4 model. It's more than just a forum or a FAQ hub – it's a dynamic knowledge base where coders can find AI-assisted solutions to their pressing problems. With GPT-4's powerful comprehension and predictive abilities, Codex Central provides instantaneous issue resolution, insightful debugging, and personalized guidance. Get your code running smoothly with the unparalleled support at Codex Central - coding help reimagined with AI prowess.