> The complete documentation index is at [llms.txt](/llms.txt).

## Client

```python
bauplan.Client(profile: str | None = None, api_key: str | None = None, client_timeout: int | None = None, config_file_path: str | None = None)
```

A client for the Bauplan API.

**Parameters:**
- `profile` (str | None): The Bauplan config profile name to use to determine api_key.
- `api_key` (str | None): Your unique Bauplan API key; mutually exclusive with `profile`. If not provided, fetch precedence is 1) environment `BAUPLAN_API_KEY` 2) ~/.bauplan/config.yaml
- `client_timeout` (int | None): The client timeout in seconds for all the requests.
- `config_file_path` (str | None): The path to the Bauplan config file to use. If not provided, ~/.bauplan/config.yaml will be used. Note that this disables any environment-based configuration.

#### Using the client

```python
import bauplan
client = bauplan.Client()

# query the table and return result set as an arrow Table
my_table = client.query('SELECT avg(Age) AS average_age FROM bauplan.titanic limit 1', ref='main')

# efficiently cast the table to a pandas DataFrame
df = my_table.to_pandas()
```

#### Notes on authentication

```python
# by default, authenticate from BAUPLAN_API_KEY >> BAUPLAN_PROFILE >> ~/.bauplan/config.yaml
client = bauplan.Client()
# client used ~/.bauplan/config.yaml profile 'default'

import os
os.environ['BAUPLAN_PROFILE'] = "someprofile"
client = bauplan.Client()
# >> client now uses profile 'someprofile'

os.environ['BAUPLAN_API_KEY'] = "mykey"
client = bauplan.Client()
# >> client now authenticates with api_key value "mykey", because api key > profile

# specify authentication directly - this supersedes BAUPLAN_API_KEY in the environment
client = bauplan.Client(api_key='MY_KEY')

# specify a profile from ~/.bauplan/config.yaml - this supersedes BAUPLAN_PROFILE in the environment
client = bauplan.Client(profile='default')
```

#### Handling Exceptions

Catalog operations (branch, tag, namespace and table methods) raise a subclass of
[`bauplan.exceptions.BauplanHTTPError`](/reference/bauplan-exceptions#bauplan-exceptions-bauplanhttperror) matching the HTTP status code:

- 400: [`bauplan.exceptions.BadRequestError`](/reference/bauplan-exceptions#bauplan-exceptions-badrequesterror) (e.g. `InvalidRefError`)
- 401: [`bauplan.exceptions.UnauthorizedError`](/reference/bauplan-exceptions#bauplan-exceptions-unauthorizederror)
- 403: [`bauplan.exceptions.ForbiddenError`](/reference/bauplan-exceptions#bauplan-exceptions-forbiddenerror)
- 404: [`bauplan.exceptions.NotFoundError`](/reference/bauplan-exceptions#bauplan-exceptions-notfounderror) (e.g. `TableNotFoundError`)
- 405: [`bauplan.exceptions.MethodNotAllowedError`](/reference/bauplan-exceptions#bauplan-exceptions-methodnotallowederror)
- 409: [`bauplan.exceptions.ConflictError`](/reference/bauplan-exceptions#bauplan-exceptions-conflicterror) (e.g. `MergeConflictError`)
- 429: [`bauplan.exceptions.TooManyRequestsError`](/reference/bauplan-exceptions#bauplan-exceptions-toomanyrequestserror)
- 500: [`bauplan.exceptions.InternalError`](/reference/bauplan-exceptions#bauplan-exceptions-internalerror)
- 502: [`bauplan.exceptions.BadGatewayError`](/reference/bauplan-exceptions#bauplan-exceptions-badgatewayerror)
- 503: [`bauplan.exceptions.ServiceUnavailableError`](/reference/bauplan-exceptions#bauplan-exceptions-serviceunavailableerror)
- 504: [`bauplan.exceptions.GatewayTimeoutError`](/reference/bauplan-exceptions#bauplan-exceptions-gatewaytimeouterror)

Jobs like `run` and `import_data` return a state object instead. A failed job doesn't
raise; check `state.job_status` and `state.error`. [`bauplan.exceptions.BauplanJobError`](/reference/bauplan-exceptions#bauplan-exceptions-bauplanjoberror)
is only raised if the job can't be submitted or times out.

`query`, `scan` and `query_to_*` return the results directly and raise
[`bauplan.exceptions.BauplanQueryError`](/reference/bauplan-exceptions#bauplan-exceptions-bauplanqueryerror) if the query fails.

#### Logging

You can use python's standard logging apparatus to tap logs from the client:

```python
import logging

# Enable debug logs from the Bauplan client.
logging.basicConfig()
logging.getLogger("bauplan").setLevel(logging.DEBUG)

client = bauplan.Client()
client.query("SELECT count(*) FROM titanic", ref="main")
```

#### Pagination

Methods like `get_branches` and `get_tables` return a lazy paginating iterator:

```python
#! client = bauplan.Client()
for branch in client.get_branches():
    ...
```

As a general rule, you should try to avoid eagerly evaluating them, as the lists can be very large.

```python
#! client = bauplan.Client()
# Don't do this!
branches = list(client.get_branches())
```

#### Examples

```python
client = bauplan.Client()
state = client.run("./my_pipeline")
if state.job_status != "SUCCESS":
    ...
```

### apply_table_creation_plan

```python
def apply_table_creation_plan(plan: TableCreatePlanState | str, *, args: dict[str, str] | None = None, priority: int | None = None, client_timeout: int | None = None) -> TableCreatePlanApplyState
```

Apply a plan for creating a table. It is done automatically during the
table plan creation if no schema conflicts exist. Otherwise, if schema
conflicts exist, then this function is used to apply them after the
schema conflicts are resolved. The most common schema conflict is two
parquet files with the same column name but different datatypes.

**Returns:** A [`bauplan.state.TableCreatePlanApplyState`](/reference/bauplan-state#bauplan-state-tablecreateplanapplystate) object.

**Parameters:**
- `plan` ([TableCreatePlanState](/reference/bauplan-state#bauplan-state-tablecreateplanstate) | str): The plan to apply.
- `args` (dict[str, str] | None): dict of arbitrary args to pass to the backend.
- `priority` (int | None): Optional job priority (1-10, where 10 is highest priority).
- `client_timeout` (int | None): seconds to timeout; this also cancels the remote job execution. Defaults to 1800 seconds.

**Raises:**
- [bauplan.exceptions.TableCreatePlanApplyStatusError](/reference/bauplan-exceptions#bauplan-exceptions-tablecreateplanapplystatuserror): if the table creation plan apply fails.

#### Example

```python
import bauplan
client = bauplan.Client()

plan_state = client.plan_table_creation(
    table='my_table',
    search_uri='s3://my-bucket/data/*.parquet',
    branch='main',
    namespace='my_namespace',
)
if plan_state.error:
    raise RuntimeError(f"Planning failed: {plan_state.error}")

if plan_state.can_auto_apply:
    # No schema conflicts - the table was already created automatically.
    print("Table created automatically (no conflicts)")
else:
    # Schema conflicts detected (e.g. same column name, different types across files).
    # Inspect and resolve the plan YAML, then apply manually.
    print(plan_state.plan)  # review/edit the schema plan
    apply_state = client.apply_table_creation_plan(
        plan=plan_state,
        priority=5,
        client_timeout=30,
    )
    if apply_state.error:
        raise RuntimeError(f"Apply failed: {apply_state.error}")
    print(f"Table created after conflict resolution: {apply_state.job_status}")
```

### cancel_job

```python
def cancel_job(job_id: str) -> None
```

EXPERIMENTAL: Cancel a job by ID.

**Parameters:**
- `job_id` (str): A job ID

#### Example

```python
import bauplan
client = bauplan.Client()

# Kick off a pipeline without blocking, then cancel it if it's taking too long
state = client.run(
    project_dir='./my_pipeline',
    ref='username.dev_branch',
    detach=True,
)
if state.job_id:
    client.cancel_job(state.job_id)
```

### create_branch

```python
def create_branch(branch: str | Branch, from_ref: str | Ref, *, if_not_exists: bool = False) -> Branch
```

Create a new branch at a given ref.
The branch name should follow the convention of `username.branch_name`,
otherwise non-admin users won't be able to complete the operation.

**Returns:** The created [`bauplan.schema.Branch`](/reference/bauplan-schema#bauplan-schema-branch) object.

**Parameters:**
- `branch` (str | [Branch](/reference/bauplan-schema#bauplan-schema-branch)): The name of the new branch.
- `from_ref` (str | [Ref](/reference/bauplan-schema#bauplan-schema-ref)): The name of the base branch; either a branch like "main" or ref like "main@[sha]".
- `if_not_exists` (bool): If set to `True`, the branch will not be created if it already exists.

**Raises:**
- [bauplan.exceptions.CreateBranchForbiddenError](/reference/bauplan-exceptions#bauplan-exceptions-createbranchforbiddenerror): if the user does not have access to create the branch.
- [bauplan.exceptions.BranchExistsError](/reference/bauplan-exceptions#bauplan-exceptions-branchexistserror): if the branch already exists.
- [bauplan.exceptions.RefNotFoundError](/reference/bauplan-exceptions#bauplan-exceptions-refnotfounderror): if the source ref does not exist.
- [bauplan.exceptions.InvalidRefError](/reference/bauplan-exceptions#bauplan-exceptions-invalidreferror): if the ref format is invalid.
- [bauplan.exceptions.UnauthorizedError](/reference/bauplan-exceptions#bauplan-exceptions-unauthorizederror): if the user's credentials are invalid.
- `ValueError`: if one or more parameters are invalid.

#### Example

```python
import bauplan

client = bauplan.Client()
username = client.info().user.username

branch = client.create_branch(
    branch = username+'.feature_branch',
    from_ref = 'branch_name@abcd1234',
    if_not_exists = True,
)
```

### create_external_table_from_metadata

```python
def create_external_table_from_metadata(table: str | Table, metadata_json_uri: str, *, namespace: str | Namespace, branch: str | Branch | None = None, overwrite: bool = False) -> Table
```

Create an external table from an Iceberg metadata.json file.

**Returns:** The registered [`bauplan.schema.Table`](/reference/bauplan-schema#bauplan-schema-table) with full metadata.

**Parameters:**
- `table` (str | [Table](/reference/bauplan-schema#bauplan-schema-table)): The name of the table to create.
- `metadata_json_uri` (str): The URI pointing to the Iceberg table's metadata.json file.
- `namespace` (str | [Namespace](/reference/bauplan-schema#bauplan-schema-namespace)): The namespace for the table (required).
- `branch` (str | [Branch](/reference/bauplan-schema#bauplan-schema-branch) | None): The branch name in which to create the table. Defaults to the active branch, or 'main'.
- `overwrite` (bool): Whether to overwrite an existing table with the same name (default: False).

**Raises:**
- `ValueError`: if metadata_json_uri is empty or invalid, or if table parameter is invalid.
- [bauplan.exceptions.BranchNotFoundError](/reference/bauplan-exceptions#bauplan-exceptions-branchnotfounderror): if the branch does not exist.
- [bauplan.exceptions.NamespaceNotFoundError](/reference/bauplan-exceptions#bauplan-exceptions-namespacenotfounderror): if the namespace does not exist.
- [bauplan.exceptions.UnauthorizedError](/reference/bauplan-exceptions#bauplan-exceptions-unauthorizederror): if the user's credentials are invalid.
- [bauplan.exceptions.InvalidDataError](/reference/bauplan-exceptions#bauplan-exceptions-invaliddataerror): if the metadata location is within the warehouse directory.
- [bauplan.exceptions.UpdateConflictError](/reference/bauplan-exceptions#bauplan-exceptions-updateconflicterror): if a table with the same name already exists and overwrite=False.
- [bauplan.exceptions.BauplanError](/reference/bauplan-exceptions#bauplan-exceptions-bauplanerror): for other API errors during registration or retrieval.

This operation creates an external table by pointing to an existing Iceberg table's
metadata.json file. This is useful for importing external Iceberg tables into Bauplan
without copying the data.

#### Example

```python
import bauplan
client = bauplan.Client()

# Create an external table from metadata
result = client.create_external_table_from_metadata(
    table='my_external_table',
    metadata_json_uri='s3://my-bucket/path/to/metadata/00001-abc123.metadata.json',
    namespace='my_namespace',
    branch='my_branch_name',
)
```

### create_external_table_from_parquet

```python
def create_external_table_from_parquet(table: str | Table, search_patterns: list[str], *, branch: str | Branch | None = None, namespace: str | Namespace | None = None, overwrite: bool = False, args: dict[str, str] | None = None, priority: int | None = None, client_timeout: int | None = None, detach: bool = False) -> ExternalTableCreateState
```

Creates an external table from files in your object storage.

**Returns:** A [`bauplan.state.ExternalTableCreateState`](/reference/bauplan-state#bauplan-state-externaltablecreatestate) object.

**Parameters:**
- `table` (str | [Table](/reference/bauplan-schema#bauplan-schema-table)): The name of the external table to create.
- `search_patterns` (list[str]): List of search_patterns for files to create the external table from. Must resolve to parquet files
- `branch` (str | [Branch](/reference/bauplan-schema#bauplan-schema-branch) | None): Branch in which to create the table.
- `namespace` (str | [Namespace](/reference/bauplan-schema#bauplan-schema-namespace) | None): Namespace of the table. If not specified, namespace will be inferred from table name or default settings.
- `overwrite` (bool): Whether to delete and recreate the table if it already exists.
- `args` (dict[str, str] | None): dict of arbitrary args to pass to the backend.
- `priority` (int | None): Optional job priority (1-10, where 10 is highest priority).
- `client_timeout` (int | None): seconds to timeout; this also cancels the remote job execution. Defaults to 1800 seconds.
- `detach` (bool): Whether to detach the job and return immediately without waiting for the job to finish.

#### Example

```python
import bauplan
client = bauplan.Client()

# Create from S3 files
state = client.create_external_table_from_parquet(
    table='my_external_table',
    search_patterns=['s3://path1/to/my/files/*.parquet', 's3://path2/to/my/file/f1.parquet'],
    branch='my_branch_name',
)

if state.error:
    print(f"Error: {state.error}")
else:
    print(f"External table created: {state.ctx.table_name}")
```

### create_namespace

```python
def create_namespace(namespace: str | Namespace, branch: str | Branch, *, commit_body: str | None = None, commit_properties: dict[str, str] | None = None, if_not_exists: bool = False) -> Namespace
```

Create a new namespace at a given branch.

**Returns:** The created [`bauplan.schema.Namespace`](/reference/bauplan-schema#bauplan-schema-namespace) object.

**Parameters:**
- `namespace` (str | [Namespace](/reference/bauplan-schema#bauplan-schema-namespace)): The name of the namespace.
- `branch` (str | [Branch](/reference/bauplan-schema#bauplan-schema-branch)): The name of the branch to create the namespace on.
- `commit_body` (str | None): Optional, the commit body to attach to the operation.
- `commit_properties` (dict[str, str] | None): Optional, a list of properties to attach to the commit.
- `if_not_exists` (bool): If set to `True`, the namespace will not be created if it already exists.

**Raises:**
- [bauplan.exceptions.CreateNamespaceForbiddenError](/reference/bauplan-exceptions#bauplan-exceptions-createnamespaceforbiddenerror): if the user does not have access to create the namespace.
- [bauplan.exceptions.BranchNotFoundError](/reference/bauplan-exceptions#bauplan-exceptions-branchnotfounderror): if the branch does not exist.
- [bauplan.exceptions.BranchHeadChangedError](/reference/bauplan-exceptions#bauplan-exceptions-branchheadchangederror): if the branch head hash has changed.
- [bauplan.exceptions.NotABranchRefError](/reference/bauplan-exceptions#bauplan-exceptions-notabranchreferror): if the object is not a branch.
- [bauplan.exceptions.NotAWriteBranchRefError](/reference/bauplan-exceptions#bauplan-exceptions-notawritebranchreferror): if the destination branch is not a writable ref.
- [bauplan.exceptions.NamespaceExistsError](/reference/bauplan-exceptions#bauplan-exceptions-namespaceexistserror): if the namespace already exists.
- [bauplan.exceptions.RefNotFoundError](/reference/bauplan-exceptions#bauplan-exceptions-refnotfounderror): if the ref does not exist.
- [bauplan.exceptions.InvalidRefError](/reference/bauplan-exceptions#bauplan-exceptions-invalidreferror): if the ref format is invalid.
- [bauplan.exceptions.UnauthorizedError](/reference/bauplan-exceptions#bauplan-exceptions-unauthorizederror): if the user's credentials are invalid.
- `ValueError`: if one or more parameters are invalid.

#### Example

```python
import bauplan
client = bauplan.Client()

assert client.create_namespace(
    namespace='my_namespace_name',
    branch='my_branch_name',
    if_not_exists=True,
)
```

### create_table

```python
def create_table(table: str | Table, search_uri: str, *, branch: str | Branch | None = None, namespace: str | Namespace | None = None, partitioned_by: str | None = None, replace: bool | None = None, args: dict[str, str] | None = None, priority: int | None = None, client_timeout: int | None = None) -> Table
```

Create a table from an object storage location.

**Returns:** The created [`bauplan.schema.Table`](/reference/bauplan-schema#bauplan-schema-table).

**Parameters:**
- `table` (str | [Table](/reference/bauplan-schema#bauplan-schema-table)): The table which will be created.
- `search_uri` (str): The location of the files to scan for schema.
- `branch` (str | [Branch](/reference/bauplan-schema#bauplan-schema-branch) | None): The branch name in which to create the table.
- `namespace` (str | [Namespace](/reference/bauplan-schema#bauplan-schema-namespace) | None): Optional argument specifying the namespace. If not specified, it will be inferred based on table location or the default.
- `partitioned_by` (str | None): Optional argument specifying the table partitioning.
- `replace` (bool | None): Replace the table if it already exists.
- `args` (dict[str, str] | None): dict of arbitrary args to pass to the backend.
- `priority` (int | None): Optional job priority (1-10, where 10 is highest priority).
- `client_timeout` (int | None): seconds to timeout; this also cancels the remote job execution. Defaults to 1800 seconds.

**Raises:**
- [bauplan.exceptions.TableCreatePlanStatusError](/reference/bauplan-exceptions#bauplan-exceptions-tablecreateplanstatuserror): if the table creation plan fails.
- [bauplan.exceptions.TableCreatePlanApplyStatusError](/reference/bauplan-exceptions#bauplan-exceptions-tablecreateplanapplystatuserror): if the table creation plan apply fails.

This operation will attempt to create a table based on schemas of N
parquet files found by a given search uri. This is a two step operation using
[`Client.plan_table_creation`](/reference/bauplan#bauplan-client-plan_table_creation) and [`Client.apply_table_creation_plan`](/reference/bauplan#bauplan-client-apply_table_creation_plan).

To specify partitioning, use the `create_table` method with the `partitioned_by` parameter:

#### Examples

```python
import bauplan
client = bauplan.Client()

table = client.create_table(
    table='my_table_name',
    search_uri='s3://path/to/my/files/*.parquet',
    branch='my_branch_name',
)
```

```python
import bauplan

client = bauplan.Client()

# Create a partitioned table
table = client.create_table(
    table='my_partitioned_table',
    search_uri='s3://your-bucket/data/*.parquet',
    partitioned_by="hour(tpep_pickup_datetime), PULocationID",
    branch='my_branch'
)
```

### create_tag

```python
def create_tag(tag: str | Tag, from_ref: str | Ref, *, if_not_exists: bool = False) -> Tag
```

Create a new tag at a given ref.

**Returns:** The created [`bauplan.schema.Tag`](/reference/bauplan-schema#bauplan-schema-tag) object.

**Parameters:**
- `tag` (str | [Tag](/reference/bauplan-schema#bauplan-schema-tag)): The name of the new tag.
- `from_ref` (str | [Ref](/reference/bauplan-schema#bauplan-schema-ref)): The name of the base branch; either a branch like "main" or ref like "main@[sha]".
- `if_not_exists` (bool): If set to `True`, the tag will not be created if it already exists.

**Raises:**
- [bauplan.exceptions.CreateTagForbiddenError](/reference/bauplan-exceptions#bauplan-exceptions-createtagforbiddenerror): if the user does not have access to create the tag.
- [bauplan.exceptions.RefNotFoundError](/reference/bauplan-exceptions#bauplan-exceptions-refnotfounderror): if the ref does not exist.
- [bauplan.exceptions.TagExistsError](/reference/bauplan-exceptions#bauplan-exceptions-tagexistserror): if the tag already exists.
- [bauplan.exceptions.InvalidRefError](/reference/bauplan-exceptions#bauplan-exceptions-invalidreferror): if the ref format is invalid.
- [bauplan.exceptions.UnauthorizedError](/reference/bauplan-exceptions#bauplan-exceptions-unauthorizederror): if the user's credentials are invalid.
- `ValueError`: if one or more parameters are invalid.

#### Example

```python
import bauplan
client = bauplan.Client()

assert client.create_tag(
    tag='my_tag',
    from_ref='my_ref_or_branch_name',
)
```

### delete_branch

```python
def delete_branch(branch: str | Branch, *, if_exists: bool = False) -> bool
```

Delete a branch.

**Returns:** A boolean for if the branch was deleted.

**Parameters:**
- `branch` (str | [Branch](/reference/bauplan-schema#bauplan-schema-branch)): The name of the branch to delete.
- `if_exists` (bool): If set to `True`, the branch will not raise an error if it does not exist.

**Raises:**
- [bauplan.exceptions.DeleteBranchForbiddenError](/reference/bauplan-exceptions#bauplan-exceptions-deletebranchforbiddenerror): if the user does not have access to delete the branch.
- [bauplan.exceptions.BranchNotFoundError](/reference/bauplan-exceptions#bauplan-exceptions-branchnotfounderror): if the branch does not exist.
- [bauplan.exceptions.BranchHeadChangedError](/reference/bauplan-exceptions#bauplan-exceptions-branchheadchangederror): if the branch head hash has changed.
- [bauplan.exceptions.NotABranchRefError](/reference/bauplan-exceptions#bauplan-exceptions-notabranchreferror): if the object is not a branch.
- [bauplan.exceptions.RefNotFoundError](/reference/bauplan-exceptions#bauplan-exceptions-refnotfounderror): if the ref does not exist.
- [bauplan.exceptions.InvalidRefError](/reference/bauplan-exceptions#bauplan-exceptions-invalidreferror): if the ref format is invalid.
- [bauplan.exceptions.UnauthorizedError](/reference/bauplan-exceptions#bauplan-exceptions-unauthorizederror): if the user's credentials are invalid.
- `ValueError`: if one or more parameters are invalid.

#### Example

```python
import bauplan
client = bauplan.Client()

if client.delete_branch('my_branch_name'):
    ...
```

### delete_namespace

```python
def delete_namespace(namespace: str | Namespace, branch: str | Branch, *, if_exists: bool = False, commit_body: str | None = None, commit_properties: dict[str, str] | None = None) -> Branch
```

Delete a namespace.

**Returns:** A [`bauplan.schema.Branch`](/reference/bauplan-schema#bauplan-schema-branch) object pointing to head.

**Parameters:**
- `namespace` (str | [Namespace](/reference/bauplan-schema#bauplan-schema-namespace)): The name of the namespace to delete.
- `branch` (str | [Branch](/reference/bauplan-schema#bauplan-schema-branch)): The name of the branch to delete the namespace from.
- `if_exists` (bool): If set to `True`, the namespace will not raise an error if it does not exist.
- `commit_body` (str | None): Optional, the commit body to attach to the operation.
- `commit_properties` (dict[str, str] | None): Optional, a list of properties to attach to the commit.

**Raises:**
- [bauplan.exceptions.DeleteNamespaceForbiddenError](/reference/bauplan-exceptions#bauplan-exceptions-deletenamespaceforbiddenerror): if the user does not have access to delete the namespace.
- [bauplan.exceptions.BranchNotFoundError](/reference/bauplan-exceptions#bauplan-exceptions-branchnotfounderror): if the branch does not exist.
- [bauplan.exceptions.BranchHeadChangedError](/reference/bauplan-exceptions#bauplan-exceptions-branchheadchangederror): if the branch head hash has changed.
- [bauplan.exceptions.NotABranchRefError](/reference/bauplan-exceptions#bauplan-exceptions-notabranchreferror): if the object is not a branch.
- [bauplan.exceptions.NotAWriteBranchRefError](/reference/bauplan-exceptions#bauplan-exceptions-notawritebranchreferror): if the destination branch is not a writable ref.
- [bauplan.exceptions.NamespaceNotFoundError](/reference/bauplan-exceptions#bauplan-exceptions-namespacenotfounderror): if the namespace does not exist.
- [bauplan.exceptions.NamespaceIsNotEmptyError](/reference/bauplan-exceptions#bauplan-exceptions-namespaceisnotemptyerror): if the namespace is not empty.
- [bauplan.exceptions.UnauthorizedError](/reference/bauplan-exceptions#bauplan-exceptions-unauthorizederror): if the user's credentials are invalid.
- `ValueError`: if one or more parameters are invalid.

#### Example

```python
import bauplan
client = bauplan.Client()

assert client.delete_namespace(
    namespace='my_namespace_name',
    branch='my_branch_name',
)
```

### delete_table

```python
def delete_table(table: str | Table, branch: str | Branch, *, namespace: str | Namespace | None = None, if_exists: bool = False, commit_body: str | None = None, commit_properties: dict[str, str] | None = None) -> Branch
```

Drop a table.

**Returns:** A [`bauplan.schema.Branch`](/reference/bauplan-schema#bauplan-schema-branch) object pointing to the new head.

**Parameters:**
- `table` (str | [Table](/reference/bauplan-schema#bauplan-schema-table)): The table to delete.
- `branch` (str | [Branch](/reference/bauplan-schema#bauplan-schema-branch)): The branch on which the table is stored.
- `namespace` (str | [Namespace](/reference/bauplan-schema#bauplan-schema-namespace) | None): The namespace of the table to delete.
- `if_exists` (bool): If set to `True`, the table will not raise an error if it does not exist.
- `commit_body` (str | None): Optional, the commit body message to attach to the commit.
- `commit_properties` (dict[str, str] | None): Optional, a list of properties to attach to the commit.

**Raises:**
- [bauplan.exceptions.DeleteTableForbiddenError](/reference/bauplan-exceptions#bauplan-exceptions-deletetableforbiddenerror): if the user does not have access to delete the table.
- [bauplan.exceptions.BranchNotFoundError](/reference/bauplan-exceptions#bauplan-exceptions-branchnotfounderror): if the branch does not exist.
- [bauplan.exceptions.BranchHeadChangedError](/reference/bauplan-exceptions#bauplan-exceptions-branchheadchangederror): if the branch head hash has changed.
- [bauplan.exceptions.NotAWriteBranchRefError](/reference/bauplan-exceptions#bauplan-exceptions-notawritebranchreferror): if the destination branch is not a writable ref.
- [bauplan.exceptions.MergeConflictError](/reference/bauplan-exceptions#bauplan-exceptions-mergeconflicterror): if the delete operation results in a conflict.
- [bauplan.exceptions.TableNotFoundError](/reference/bauplan-exceptions#bauplan-exceptions-tablenotfounderror): if the table does not exist.
- [bauplan.exceptions.NamespaceNotFoundError](/reference/bauplan-exceptions#bauplan-exceptions-namespacenotfounderror): if the namespace does not exist.
- [bauplan.exceptions.NamespaceUnresolvedError](/reference/bauplan-exceptions#bauplan-exceptions-namespaceunresolvederror): if conflicting namespaces names are specified.
- [bauplan.exceptions.InvalidRefError](/reference/bauplan-exceptions#bauplan-exceptions-invalidreferror): if the ref format is invalid.
- [bauplan.exceptions.UnauthorizedError](/reference/bauplan-exceptions#bauplan-exceptions-unauthorizederror): if the user's credentials are invalid.
- `ValueError`: if one or more parameters are invalid.

#### Example

```python
import bauplan
client = bauplan.Client()

assert client.delete_table(
    table='my_table_name',
    branch='my_branch_name',
    namespace='my_namespace',
)
```

### delete_tag

```python
def delete_tag(tag: str | Tag, *, if_exists: bool = False) -> bool
```

Delete a tag.

**Returns:** A boolean for if the tag was deleted.

**Parameters:**
- `tag` (str | [Tag](/reference/bauplan-schema#bauplan-schema-tag)): The name of the tag to delete.
- `if_exists` (bool): If set to `True`, the tag will not raise an error if it does not exist.

**Raises:**
- [bauplan.exceptions.DeleteTagForbiddenError](/reference/bauplan-exceptions#bauplan-exceptions-deletetagforbiddenerror): if the user does not have access to delete the tag.
- [bauplan.exceptions.TagNotFoundError](/reference/bauplan-exceptions#bauplan-exceptions-tagnotfounderror): if the tag does not exist.
- [bauplan.exceptions.BranchHeadChangedError](/reference/bauplan-exceptions#bauplan-exceptions-branchheadchangederror): if the branch head hash has changed.
- [bauplan.exceptions.NotATagRefError](/reference/bauplan-exceptions#bauplan-exceptions-notatagreferror): if the object is not a tag.
- [bauplan.exceptions.InvalidRefError](/reference/bauplan-exceptions#bauplan-exceptions-invalidreferror): if the ref format is invalid.
- [bauplan.exceptions.UnauthorizedError](/reference/bauplan-exceptions#bauplan-exceptions-unauthorizederror): if the user's credentials are invalid.
- `ValueError`: if one or more parameters are invalid.

#### Example

```python
import bauplan
client = bauplan.Client()

assert client.delete_tag('my_tag_name')
```

### get_branch

```python
def get_branch(branch: str | Branch) -> Branch
```

Get the branch.

**Returns:** A [`bauplan.schema.Branch`](/reference/bauplan-schema#bauplan-schema-branch) object.

**Parameters:**
- `branch` (str | [Branch](/reference/bauplan-schema#bauplan-schema-branch)): The name of the branch to retrieve.

**Raises:**
- [bauplan.exceptions.BranchNotFoundError](/reference/bauplan-exceptions#bauplan-exceptions-branchnotfounderror): if the branch does not exist.
- [bauplan.exceptions.NotABranchRefError](/reference/bauplan-exceptions#bauplan-exceptions-notabranchreferror): if the object is not a branch.
- [bauplan.exceptions.InvalidRefError](/reference/bauplan-exceptions#bauplan-exceptions-invalidreferror): if the ref format is invalid.
- [bauplan.exceptions.ForbiddenError](/reference/bauplan-exceptions#bauplan-exceptions-forbiddenerror): if the user does not have access to the branch.
- [bauplan.exceptions.UnauthorizedError](/reference/bauplan-exceptions#bauplan-exceptions-unauthorizederror): if the user's credentials are invalid.
- `ValueError`: if one or more parameters are invalid.

#### Example

```python
import bauplan
client = bauplan.Client()

branch = client.get_branch('my_branch_name')
```

### get_branches

```python
def get_branches(*, name: str | None = None, user: str | None = None, limit: int | None = None) -> Iterator[Branch]
```

Get the available data branches in the Bauplan catalog.

**Returns:** An iterator over [`bauplan.schema.Branch`](/reference/bauplan-schema#bauplan-schema-branch) objects.

**Parameters:**
- `name` (str | None): Filter the branches by name.
- `user` (str | None): Filter the branches by user.
- `limit` (int | None): Optional, max number of branches to get.

#### Example

```python
import bauplan
client = bauplan.Client()

for branch in client.get_branches():
    ...
```

### get_commits

```python
def get_commits(ref: str | Ref, *, filter_by_message: str | None = None, filter_by_author_username: str | None = None, filter_by_author_name: str | None = None, filter_by_author_email: str | None = None, filter_by_authored_date: str | datetime | None = None, filter_by_authored_date_start_at: str | datetime | None = None, filter_by_authored_date_end_at: str | datetime | None = None, filter_by_parent_hash: str | None = None, filter_by_properties: dict[str, str] | None = None, filter: str | None = None, limit: int | None = None) -> Iterator[Commit]
```

Get the commits for the target branch or ref.

**Returns:** An iterator over [`bauplan.schema.Commit`](/reference/bauplan-schema#bauplan-schema-commit) objects.

**Parameters:**
- `ref` (str | [Ref](/reference/bauplan-schema#bauplan-schema-ref)): The ref or branch to get the commits from.
- `filter_by_message` (str | None): Optional, filter the commits by message (can be a string or a regex like '^abc.*$')
- `filter_by_author_username` (str | None): Optional, filter the commits by author username (can be a string or a regex like '^abc.*$')
- `filter_by_author_name` (str | None): Optional, filter the commits by author name (can be a string or a regex like '^abc.*$')
- `filter_by_author_email` (str | None): Optional, filter the commits by author email (can be a string or a regex like '^abc.*$')
- `filter_by_authored_date` (str | datetime | None): Optional, filter the commits by the exact authored date.
- `filter_by_authored_date_start_at` (str | datetime | None): Optional, filter the commits by authored date start at.
- `filter_by_authored_date_end_at` (str | datetime | None): Optional, filter the commits by authored date end at.
- `filter_by_parent_hash` (str | None): Optional, filter the commits by parent hash.
- `filter_by_properties` (dict[str, str] | None): Optional, filter the commits by commit properties.
- `filter` (str | None): Optional, a CEL filter expression to filter the commits.
- `limit` (int | None): Optional, max number of commits to get.

**Raises:**
- [bauplan.exceptions.RefNotFoundError](/reference/bauplan-exceptions#bauplan-exceptions-refnotfounderror): if the ref does not exist.
- [bauplan.exceptions.InvalidRefError](/reference/bauplan-exceptions#bauplan-exceptions-invalidreferror): if the ref format is invalid.
- [bauplan.exceptions.UnauthorizedError](/reference/bauplan-exceptions#bauplan-exceptions-unauthorizederror): if the user's credentials are invalid.
- `ValueError`: if one or more parameters are invalid.

#### Example

```python
import bauplan
client = bauplan.Client()

for commit in client.get_commits('my_ref_or_branch_name', limit=50):
    ...
```

### get_job

```python
def get_job(job_id: str) -> Job
```

EXPERIMENTAL: Get a job by ID.

**Returns:** A [`bauplan.schema.Job`](/reference/bauplan-schema#bauplan-schema-job) object.

**Parameters:**
- `job_id` (str): A job ID

#### Example

```python
#! my_job: bauplan.schema.Job = ...  # ty: ignore[invalid-assignment]
import bauplan
client = bauplan.Client()

job = client.get_job(my_job.id)
print(f"{job.human_readable_status} ({job.kind})")
```

### get_job_context

```python
def get_job_context(job: str | Job, *, include_logs: bool = False, include_snapshot: bool = False) -> JobContext
```

EXPERIMENTAL: Get context for a job by ID.

**Returns:** A [`bauplan.schema.JobContext`](/reference/bauplan-schema#bauplan-schema-jobcontext) object containing the job details, and optionally logs and snapshot.

**Parameters:**
- `job` (str | [Job](/reference/bauplan-schema#bauplan-schema-job)): Union[str, Job]: A job ID or a Job instance.
- `include_logs` (bool): bool: Whether to include logs in the response.
- `include_snapshot` (bool): bool: Whether to include the code snapshot in the response.

#### Example

```python
#! my_job: bauplan.schema.Job = ...  # ty: ignore[invalid-assignment]
import bauplan
client = bauplan.Client()

ctx = client.get_job_context(my_job.id, include_logs=True)
print(f"ref: {ctx.ref}, project: {ctx.project_name}")
for log in ctx.logs:
    print(f"[{log.level}] {log.message}")
```

### get_job_contexts

```python
def get_job_contexts(jobs: str | list[str] | list[Job], *, include_logs: bool = False, include_snapshot: bool = False) -> list[JobContext]
```

EXPERIMENTAL: Get context for multiple jobs.

**Returns:** A list of [`bauplan.schema.JobContext`](/reference/bauplan-schema#bauplan-schema-jobcontext) objects containing the job details, and optionally logs and snapshot.

**Parameters:**
- `jobs` (str | list[str] | list[[Job](/reference/bauplan-schema#bauplan-schema-job)]): list[Union[str, Job]]: A list of job IDs or Job instances.
- `include_logs` (bool): bool: Whether to include logs in the response.
- `include_snapshot` (bool): bool: Whether to include the code snapshot in the response.

#### Example

```python
#! my_job: bauplan.schema.Job = ...  # ty: ignore[invalid-assignment]
import bauplan
client = bauplan.Client()

contexts = client.get_job_contexts([my_job], include_logs=True)
for ctx in contexts:
    print(f"{ctx.id}: {ctx.project_name} on {ctx.ref}")
```

### get_job_logs

```python
def get_job_logs(job: str | Job) -> list[JobLogEvent]
```

EXPERIMENTAL: Get logs for a job.

**Returns:** A list of [`bauplan.schema.JobLogEvent`](/reference/bauplan-schema#bauplan-schema-joblogevent) objects representing the log events for the job.

**Parameters:**
- `job` (str | [Job](/reference/bauplan-schema#bauplan-schema-job)): Union[str, Job]: A job ID or a Job instance.

#### Example

```python
#! my_job: bauplan.schema.Job = ...  # ty: ignore[invalid-assignment]
import bauplan
client = bauplan.Client()

for log in client.get_job_logs(my_job.id):
    print(f"[{log.level}] {log.message}")
```

### get_jobs

```python
def get_jobs(*, filter_by_current_user: bool = True, filter_by_ids: str | list[str] | list[Job] | None = None, filter_by_users: str | list[str] | None = None, filter_by_kinds: str | JobKind | list[str] | list[JobKind] | None = None, filter_by_statuses: str | JobState | list[str] | list[JobState] | None = None, filter_by_created_after: datetime | None = None, filter_by_created_before: datetime | None = None, limit: int | None = None) -> Iterator[Job]
```

Get jobs with optional filtering.

**Returns:** An iterator over [`bauplan.schema.Job`](/reference/bauplan-schema#bauplan-schema-job) objects.

**Parameters:**
- `filter_by_current_user` (bool): Optional[bool]: If True (the default), only return jobs
belonging to the current user. Mutually exclusive with filter_by_users.
- `filter_by_ids` (str | list[str] | list[[Job](/reference/bauplan-schema#bauplan-schema-job)] | None): Optional[Union[str, List[str]]]: Optional, filter by job IDs.
- `filter_by_users` (str | list[str] | None): Optional[Union[str, List[str]]]: Optional, filter by job users.
- `filter_by_kinds` (str | [JobKind](/reference/bauplan-schema#bauplan-schema-jobkind) | list[str] | list[[JobKind](/reference/bauplan-schema#bauplan-schema-jobkind)] | None): Optional[Union[str, JobKind, List[Union[str, JobKind]]]]: Optional, filter by job kinds.
- `filter_by_statuses` (str | [JobState](/reference/bauplan-schema#bauplan-schema-jobstate) | list[str] | list[[JobState](/reference/bauplan-schema#bauplan-schema-jobstate)] | None): Optional[Union[str, JobState, List[Union[str, JobState]]]]: Optional, filter by job statuses.
- `filter_by_created_after` (datetime | None): Optional[datetime]: Optional, filter jobs created after this datetime.
- `filter_by_created_before` (datetime | None): Optional[datetime]: Optional, filter jobs created before this datetime.
- `limit` (int | None): Optional[int]: Optional, max number of jobs to return.

#### Example

```python
import bauplan
client = bauplan.Client()

for job in client.get_jobs():
    print(f"{job.id}: {job.status} ({job.kind})")
```

### get_namespace

```python
def get_namespace(namespace: str | Namespace, ref: str | Ref) -> Namespace
```

Get a namespace.

**Returns:** A [`bauplan.schema.Namespace`](/reference/bauplan-schema#bauplan-schema-namespace) object.

**Parameters:**
- `namespace` (str | [Namespace](/reference/bauplan-schema#bauplan-schema-namespace)): The name of the namespace to get.
- `ref` (str | [Ref](/reference/bauplan-schema#bauplan-schema-ref)): The ref, branch name or tag name to check the namespace on.

**Raises:**
- [bauplan.exceptions.NamespaceNotFoundError](/reference/bauplan-exceptions#bauplan-exceptions-namespacenotfounderror): if the namespace does not exist.
- [bauplan.exceptions.RefNotFoundError](/reference/bauplan-exceptions#bauplan-exceptions-refnotfounderror): if the ref does not exist.
- [bauplan.exceptions.InvalidRefError](/reference/bauplan-exceptions#bauplan-exceptions-invalidreferror): if the ref format is invalid.
- [bauplan.exceptions.UnauthorizedError](/reference/bauplan-exceptions#bauplan-exceptions-unauthorizederror): if the user's credentials are invalid.
- `ValueError`: if one or more parameters are invalid.

#### Example

```python
import bauplan
client = bauplan.Client()

namespace =  client.get_namespace(
    namespace='my_namespace_name',
    ref='my_branch_name',
)
```

### get_namespaces

```python
def get_namespaces(ref: str | Ref, *, filter_by_name: str | None = None, limit: int | None = None) -> Iterator[Namespace]
```

Get the available data namespaces in the Bauplan catalog branch.

**Returns:** [`bauplan.schema.Namespace`](/reference/bauplan-schema#bauplan-schema-namespace) objects.

**Parameters:**
- `ref` (str | [Ref](/reference/bauplan-schema#bauplan-schema-ref)): The ref, branch name or tag name to retrieve the namespaces from.
- `filter_by_name` (str | None): Optional, filter the namespaces by name.
- `limit` (int | None): Optional, max number of namespaces to get.

**Raises:**
- [bauplan.exceptions.RefNotFoundError](/reference/bauplan-exceptions#bauplan-exceptions-refnotfounderror): if the ref does not exist.
- [bauplan.exceptions.InvalidRefError](/reference/bauplan-exceptions#bauplan-exceptions-invalidreferror): if the ref format is invalid.
- [bauplan.exceptions.UnauthorizedError](/reference/bauplan-exceptions#bauplan-exceptions-unauthorizederror): if the user's credentials are invalid.
- `ValueError`: if one or more parameters are invalid.

#### Example

```python
import bauplan
client = bauplan.Client()

for namespace in client.get_namespaces('my_ref_or_branch_name'):
    ...
```

### get_table

```python
def get_table(table: str | Table, ref: str | Ref, *, namespace: str | Namespace | None = None) -> Table
```

Get the table data and metadata for a table in the target branch.

**Returns:** a [`bauplan.schema.Table`](/reference/bauplan-schema#bauplan-schema-table) object

**Parameters:**
- `table` (str | [Table](/reference/bauplan-schema#bauplan-schema-table)): The table to retrieve.
- `ref` (str | [Ref](/reference/bauplan-schema#bauplan-schema-ref)): The ref, branch name or tag name to get the table from.
- `namespace` (str | [Namespace](/reference/bauplan-schema#bauplan-schema-namespace) | None): The namespace of the table to retrieve.

**Raises:**
- [bauplan.exceptions.RefNotFoundError](/reference/bauplan-exceptions#bauplan-exceptions-refnotfounderror): if the ref does not exist.
- [bauplan.exceptions.InvalidRefError](/reference/bauplan-exceptions#bauplan-exceptions-invalidreferror): if the ref format is invalid.
- [bauplan.exceptions.NamespaceNotFoundError](/reference/bauplan-exceptions#bauplan-exceptions-namespacenotfounderror): if the namespace does not exist.
- [bauplan.exceptions.NamespaceUnresolvedError](/reference/bauplan-exceptions#bauplan-exceptions-namespaceunresolvederror): if conflicting namespaces names are specified.
- [bauplan.exceptions.TableNotFoundError](/reference/bauplan-exceptions#bauplan-exceptions-tablenotfounderror): if the table does not exist.
- [bauplan.exceptions.UnauthorizedError](/reference/bauplan-exceptions#bauplan-exceptions-unauthorizederror): if the user's credentials are invalid.
- `ValueError`: if one or more parameters are invalid.

#### Example

```python
import bauplan
client = bauplan.Client()

# get the fields and metadata for a table
table = client.get_table(
    table='titanic',
    ref='my_ref_or_branch_name',
    namespace='bauplan',
)

# You can get the total number of rows this way.
num_records = table.records

# The table documentation, if the table has any.
print(table.comment)

# Or access the schema.
for c in table.fields:
    print(c.name, c.type, c.doc)
```

### get_tables

```python
def get_tables(ref: str | Ref, *, filter_by_name: str | None = None, filter_by_namespace: str | Namespace | None = None, limit: int | None = None) -> Iterator[Table]
```

Get the tables and views in the target branch.

**Returns:** An iterator over [`bauplan.schema.Table`](/reference/bauplan-schema#bauplan-schema-table) objects.

**Parameters:**
- `ref` (str | [Ref](/reference/bauplan-schema#bauplan-schema-ref)): The ref or branch to get the tables from.
- `filter_by_name` (str | None): Optional, the table name to filter by.
- `filter_by_namespace` (str | [Namespace](/reference/bauplan-schema#bauplan-schema-namespace) | None): Optional, the namespace to get filtered tables from.
- `limit` (int | None): Optional, max number of tables to get.

**Raises:**
- [bauplan.exceptions.RefNotFoundError](/reference/bauplan-exceptions#bauplan-exceptions-refnotfounderror): if the ref does not exist.
- [bauplan.exceptions.InvalidRefError](/reference/bauplan-exceptions#bauplan-exceptions-invalidreferror): if the ref format is invalid.
- [bauplan.exceptions.NamespaceNotFoundError](/reference/bauplan-exceptions#bauplan-exceptions-namespacenotfounderror): if the namespace does not exist.
- [bauplan.exceptions.TableNotFoundError](/reference/bauplan-exceptions#bauplan-exceptions-tablenotfounderror): if the table does not exist.
- [bauplan.exceptions.UnauthorizedError](/reference/bauplan-exceptions#bauplan-exceptions-unauthorizederror): if the user's credentials are invalid.
- `ValueError`: if one or more parameters are invalid.

On failure, raises [`bauplan.exceptions.BauplanError`](/reference/bauplan-exceptions#bauplan-exceptions-bauplanerror).

#### Example

```python
import bauplan
client = bauplan.Client()

for table in client.get_tables('my_branch_name'):
    ...
```

### get_tag

```python
def get_tag(tag: str | Tag) -> Tag
```

Get the tag.

**Returns:** A [`bauplan.schema.Tag`](/reference/bauplan-schema#bauplan-schema-tag) object.

**Parameters:**
- `tag` (str | [Tag](/reference/bauplan-schema#bauplan-schema-tag)): The name of the tag to retrieve.

**Raises:**
- [bauplan.exceptions.TagNotFoundError](/reference/bauplan-exceptions#bauplan-exceptions-tagnotfounderror): if the tag does not exist.
- [bauplan.exceptions.NotATagRefError](/reference/bauplan-exceptions#bauplan-exceptions-notatagreferror): if the object is not a tag.
- [bauplan.exceptions.InvalidRefError](/reference/bauplan-exceptions#bauplan-exceptions-invalidreferror): if the ref format is invalid.
- [bauplan.exceptions.UnauthorizedError](/reference/bauplan-exceptions#bauplan-exceptions-unauthorizederror): if the user's credentials are invalid.
- `ValueError`: if one or more parameters are invalid.

#### Example

```python
import bauplan
client = bauplan.Client()

tag = client.get_tag('my_tag_name')
```

### get_tags

```python
def get_tags(*, filter_by_name: str | None = None, limit: int | None = None) -> Iterator[Tag]
```

Get all the tags.

**Returns:** An iterator over [`bauplan.schema.Tag`](/reference/bauplan-schema#bauplan-schema-tag) objects.

**Parameters:**
- `filter_by_name` (str | None): Optional, filter the tags by name.
- `limit` (int | None): Optional, max number of tags to get.

**Raises:**
- [bauplan.exceptions.UnauthorizedError](/reference/bauplan-exceptions#bauplan-exceptions-unauthorizederror): if the user's credentials are invalid.
- `ValueError`: if one or more parameters are invalid.

#### Example

```python
import bauplan
client = bauplan.Client()

tags = client.get_tags()
for tag in tags:
    print(tag.name)
```

### has_branch

```python
def has_branch(branch: str | Branch) -> bool
```

Check if a branch exists.

**Returns:** A boolean for if the branch exists.

**Parameters:**
- `branch` (str | [Branch](/reference/bauplan-schema#bauplan-schema-branch)): The name of the branch to check.

**Raises:**
- [bauplan.exceptions.ForbiddenError](/reference/bauplan-exceptions#bauplan-exceptions-forbiddenerror): if the user does not have access to the branch.
- [bauplan.exceptions.UnauthorizedError](/reference/bauplan-exceptions#bauplan-exceptions-unauthorizederror): if the user's credentials are invalid.
- `ValueError`: if one or more parameters are invalid.

#### Example

```python
import bauplan
client = bauplan.Client()

if client.has_branch('my_branch_name'):
    ...
```

### has_namespace

```python
def has_namespace(namespace: str | Namespace, ref: str | Ref) -> bool
```

Check if a namespace exists.

**Returns:** A boolean for if the namespace exists.

**Parameters:**
- `namespace` (str | [Namespace](/reference/bauplan-schema#bauplan-schema-namespace)): The name of the namespace to check.
- `ref` (str | [Ref](/reference/bauplan-schema#bauplan-schema-ref)): The ref, branch name or tag name to check the namespace on.

**Raises:**
- [bauplan.exceptions.RefNotFoundError](/reference/bauplan-exceptions#bauplan-exceptions-refnotfounderror): if the ref does not exist.
- [bauplan.exceptions.InvalidRefError](/reference/bauplan-exceptions#bauplan-exceptions-invalidreferror): if the ref format is invalid.
- [bauplan.exceptions.UnauthorizedError](/reference/bauplan-exceptions#bauplan-exceptions-unauthorizederror): if the user's credentials are invalid.
- `ValueError`: if one or more parameters are invalid.

#### Example

```python
import bauplan
client = bauplan.Client()

assert client.has_namespace(
    namespace='my_namespace_name',
    ref='my_branch_name',
)
```

### has_table

```python
def has_table(table: str | Table, ref: str | Ref, *, namespace: str | Namespace | None = None) -> bool
```

Check if a table exists.

**Returns:** A boolean for if the table exists.

**Parameters:**
- `table` (str | [Table](/reference/bauplan-schema#bauplan-schema-table)): The table to retrieve.
- `ref` (str | [Ref](/reference/bauplan-schema#bauplan-schema-ref)): The ref, branch name or tag name to get the table from.
- `namespace` (str | [Namespace](/reference/bauplan-schema#bauplan-schema-namespace) | None): The namespace of the table to check.

**Raises:**
- [bauplan.exceptions.RefNotFoundError](/reference/bauplan-exceptions#bauplan-exceptions-refnotfounderror): if the ref does not exist.
- [bauplan.exceptions.InvalidRefError](/reference/bauplan-exceptions#bauplan-exceptions-invalidreferror): if the ref format is invalid.
- [bauplan.exceptions.NamespaceNotFoundError](/reference/bauplan-exceptions#bauplan-exceptions-namespacenotfounderror): if the namespace does not exist.
- [bauplan.exceptions.UnauthorizedError](/reference/bauplan-exceptions#bauplan-exceptions-unauthorizederror): if the user's credentials are invalid.
- `ValueError`: if one or more parameters are invalid.

#### Example

```python
import bauplan
client = bauplan.Client()

assert client.has_table(
    table='titanic',
    ref='my_ref_or_branch_name',
    namespace='bauplan',
)
```

### has_tag

```python
def has_tag(tag: str | Tag) -> bool
```

Check if a tag exists.

**Returns:** A boolean for if the tag exists.

**Parameters:**
- `tag` (str | [Tag](/reference/bauplan-schema#bauplan-schema-tag)): The tag to retrieve.

**Raises:**
- [bauplan.exceptions.UnauthorizedError](/reference/bauplan-exceptions#bauplan-exceptions-unauthorizederror): if the user's credentials are invalid.
- `ValueError`: if one or more parameters are invalid.

#### Example

```python
import bauplan
client = bauplan.Client()

assert client.has_tag(
    tag='my_tag_name',
)
```

### import_data

```python
def import_data(table: str | Table, search_uri: str, *, branch: str | Branch | None = None, namespace: str | Namespace | None = None, continue_on_error: bool = False, import_duplicate_files: bool = False, best_effort: bool = False, preview: str | None = None, args: dict[str, str] | None = None, priority: int | None = None, client_timeout: int | None = None, detach: bool = False) -> TableDataImportState
```

Imports data into an already existing table.

**Returns:** A [`bauplan.state.TableDataImportState`](/reference/bauplan-state#bauplan-state-tabledataimportstate) object.

**Parameters:**
- `table` (str | [Table](/reference/bauplan-schema#bauplan-schema-table)): Previously created table into which data will be imported.
- `search_uri` (str): URI to scan for files to import.
- `branch` (str | [Branch](/reference/bauplan-schema#bauplan-schema-branch) | None): Branch in which to import the table.
- `namespace` (str | [Namespace](/reference/bauplan-schema#bauplan-schema-namespace) | None): Namespace of the table. If not specified, namespace will be inferred from table name or default settings.
- `continue_on_error` (bool): Do not fail the import even if 1 data import fails.
- `import_duplicate_files` (bool): Ignore prevention of importing files that were already imported.
- `best_effort` (bool): Ignore source columns that are not in the table schema instead of failing the import.
- `preview` (str | None): Whether to enable or disable preview mode for the import.
- `args` (dict[str, str] | None): dict of arbitrary args to pass to the backend.
- `priority` (int | None): Optional job priority (1-10, where 10 is highest priority).
- `client_timeout` (int | None): seconds to timeout; this also cancels the remote job execution. Defaults to 1800 seconds.
- `detach` (bool): Whether to detach the job and return immediately without waiting for the job to finish.

#### Example

```python
import bauplan
client = bauplan.Client()

state = client.import_data(
    table='my_table_name',
    search_uri='s3://path/to/my/files/*.parquet',
    branch='my_branch_name',
)
if state.error:
    print(f"Import failed: {state.error}")
else:
    print(f"Import succeeded: {state.job_status}")
```

### info

```python
def info(*, client_timeout: int | None = None) -> InfoState
```

Fetch organization & account information.

**Returns:** A [`bauplan.InfoState`](/reference/bauplan#bauplan-infostate) object containing organization, user, and runner information.

**Parameters:**
- `client_timeout` (int | None): timeout in seconds.

#### Example

```python
import bauplan
client = bauplan.Client()

info = client.info()
print(info.user.username)
print(info.organization.name)
```

### merge_branch

```python
def merge_branch(source_ref: str | Ref, into_branch: str | Branch, *, commit_message: str | None = None, commit_body: str | None = None, commit_properties: dict[str, str] | None = None) -> Branch
```

Merge one branch into another.

**Returns:** The [`bauplan.schema.Branch`](/reference/bauplan-schema#bauplan-schema-branch) where the merge was made.

**Parameters:**
- `source_ref` (str | [Ref](/reference/bauplan-schema#bauplan-schema-ref)): The name of the merge source; either a branch like "main" or ref like "main@[sha]".
- `into_branch` (str | [Branch](/reference/bauplan-schema#bauplan-schema-branch)): The name of the merge target.
- `commit_message` (str | None): Optional, the commit message.
- `commit_body` (str | None): Optional, the commit body.
- `commit_properties` (dict[str, str] | None): Optional, a list of properties to attach to the merge.

**Raises:**
- [bauplan.exceptions.MergeForbiddenError](/reference/bauplan-exceptions#bauplan-exceptions-mergeforbiddenerror): if the user does not have access to merge the branch.
- [bauplan.exceptions.BranchNotFoundError](/reference/bauplan-exceptions#bauplan-exceptions-branchnotfounderror): if the destination branch does not exist.
- [bauplan.exceptions.BranchHeadChangedError](/reference/bauplan-exceptions#bauplan-exceptions-branchheadchangederror): if the branch head hash has changed.
- [bauplan.exceptions.NotAWriteBranchRefError](/reference/bauplan-exceptions#bauplan-exceptions-notawritebranchreferror): if the destination branch is not a writable ref.
- [bauplan.exceptions.MergeConflictError](/reference/bauplan-exceptions#bauplan-exceptions-mergeconflicterror): if the merge operation results in a conflict.
- [bauplan.exceptions.RefNotFoundError](/reference/bauplan-exceptions#bauplan-exceptions-refnotfounderror): if the source ref does not exist.
- [bauplan.exceptions.InvalidRefError](/reference/bauplan-exceptions#bauplan-exceptions-invalidreferror): if the ref format is invalid.
- [bauplan.exceptions.UnauthorizedError](/reference/bauplan-exceptions#bauplan-exceptions-unauthorizederror): if the user's credentials are invalid.
- `ValueError`: if one or more parameters are invalid.

#### Example

```python
import bauplan
client = bauplan.Client()

assert client.merge_branch(
    source_ref='my_ref_or_branch_name',
    into_branch='main',
)
```

### plan_table_creation

```python
def plan_table_creation(table: str | Table, search_uri: str, *, branch: str | Branch | None = None, namespace: str | Namespace | None = None, partitioned_by: str | None = None, replace: bool | None = None, args: dict[str, str] | None = None, priority: int | None = None, client_timeout: int | None = None) -> TableCreatePlanState
```

Create a table import plan from an object storage location.

**Returns:** A [`bauplan.state.TableCreatePlanState`](/reference/bauplan-state#bauplan-state-tablecreateplanstate) object.

**Parameters:**
- `table` (str | [Table](/reference/bauplan-schema#bauplan-schema-table)): The table which will be created.
- `search_uri` (str): The location of the files to scan for schema.
- `branch` (str | [Branch](/reference/bauplan-schema#bauplan-schema-branch) | None): The branch name in which to create the table.
- `namespace` (str | [Namespace](/reference/bauplan-schema#bauplan-schema-namespace) | None): Optional argument specifying the namespace. If not specified, it will be inferred based on table location or the default.
- `partitioned_by` (str | None): Optional argument specifying the table partitioning.
- `replace` (bool | None): Replace the table if it already exists.
- `args` (dict[str, str] | None): dict of arbitrary args to pass to the backend.
- `priority` (int | None): Optional job priority (1-10, where 10 is highest priority).
- `client_timeout` (int | None): seconds to timeout; this also cancels the remote job execution. Defaults to 1800 seconds.

**Raises:**
- [bauplan.exceptions.TableCreatePlanStatusError](/reference/bauplan-exceptions#bauplan-exceptions-tablecreateplanstatuserror): if the table creation plan fails.

This operation will attempt to create a table based on schemas of N
parquet files found by a given search uri. A YAML file containing the
schema and plan is returned and if there are no conflicts, it is
automatically applied.

To manually add partitioning to a plan before applying it:

#### Examples

```python
import bauplan
client = bauplan.Client()

plan_state = client.plan_table_creation(
    table='my_table_name',
    search_uri='s3://path/to/my/files/*.parquet',
    branch='my_branch_name',
)
if plan_state.error:
    print(f"Plan failed: {plan_state.error}")
else:
    print(plan_state.plan)
```

```python
import yaml
import bauplan

client = bauplan.Client()

plan_state = client.plan_table_creation(
    table='my_partitioned_table',
    search_uri='s3://your-data/*.parquet',
    branch='my_branch',
)

# Modify plan to add partitioning
plan = yaml.safe_load(plan_state.plan)
plan['schema_info']['partitions'] = [
    {
        'from_column_name': 'datetime_column',
        'transform': {'name': 'year'},
    }
]

# Apply the modified plan
client.apply_table_creation_plan(yaml.dump(plan))
```

### query

```python
def query(query: str, *, ref: str | Ref | None = None, max_rows: int | None = None, cache: Literal['on', 'off'] | None = None, namespace: str | Namespace | None = None, args: dict[str, str] | None = None, priority: int | None = None, client_timeout: int | None = None) -> pyarrow.Table
```

Execute a SQL query and return the results as a pyarrow.Table.
Note that this function uses Arrow also internally, resulting
in a fast data transfer.

**Returns:** The query results as a `pyarrow.Table`.

**Parameters:**
- `query` (str): The Bauplan query to execute. Column and table names are case-sensitive.
- `ref` (str | [Ref](/reference/bauplan-schema#bauplan-schema-ref) | None): The ref, branch name or tag name to query from.
- `max_rows` (int | None): The maximum number of rows to return; default: `None` (no limit).
- `cache` (Literal['on', 'off'] | None): Whether to enable or disable caching for the query.
- `namespace` (str | [Namespace](/reference/bauplan-schema#bauplan-schema-namespace) | None): The Namespace to run the query in. If not set, the query will be run in the default namespace for your account.
- `args` (dict[str, str] | None): Additional arguments to pass to the query (default: None).
- `priority` (int | None): Optional job priority (1-10, where 10 is highest priority).
- `client_timeout` (int | None): seconds to timeout; this also cancels the remote job execution. Defaults to 1800 seconds.

If you prefer to return the results as a pandas DataFrame, use
the `to_pandas` function of pyarrow.Table.

#### Example

```python
import bauplan

client = bauplan.Client()

# query the table and return result set as an arrow Table
my_table = client.query(
    query='SELECT avg(Age) as average_age FROM bauplan.titanic',
    ref='my_ref_or_branch_name',
)

# efficiently cast the table to a pandas DataFrame
df = my_table.to_pandas()
```

### query_to_csv_file

```python
def query_to_csv_file(path: str | pathlib.Path, query: str, *, ref: str | Ref | None = None, max_rows: int | None = None, cache: Literal['on', 'off'] | None = None, namespace: str | Namespace | None = None, args: dict[str, str] | None = None, priority: int | None = None, client_timeout: int | None = None) -> pathlib.Path
```

Export the results of a SQL query to a file in CSV format.

**Returns:** The path of the file written.

**Parameters:**
- `path` (str | pathlib.Path): The name or path of the file csv to write the results to.
- `query` (str): The Bauplan query to execute. Column and table names are case-sensitive.
- `ref` (str | [Ref](/reference/bauplan-schema#bauplan-schema-ref) | None): The ref, branch name or tag name to query from.
- `max_rows` (int | None): The maximum number of rows to return; default: `None` (no limit).
- `cache` (Literal['on', 'off'] | None): Whether to enable or disable caching for the query.
- `namespace` (str | [Namespace](/reference/bauplan-schema#bauplan-schema-namespace) | None): The Namespace to run the query in. If not set, the query will be run in the default namespace for your account.
- `args` (dict[str, str] | None): Additional arguments to pass to the query (default: None).
- `priority` (int | None): No description
- `client_timeout` (int | None): seconds to timeout; this also cancels the remote job execution. Defaults to 1800 seconds.

#### Example

```python
import bauplan
client = bauplan.Client()

# query the table and iterate through the results one row at a time
client.query_to_csv_file(
    path='/tmp/out.csv',
    query='SELECT Name, Age FROM bauplan.titanic LIMIT 100',
    ref='my_ref_or_branch_name',
)
```

### query_to_generator

```python
def query_to_generator(query: str, *, ref: str | Ref | None = None, max_rows: int | None = None, cache: Literal['on', 'off'] | None = None, namespace: str | Namespace | None = None, args: dict[str, str] | None = None, priority: int | None = None, client_timeout: int | None = None) -> Iteratordict[str, [Any]]
```

Execute a SQL query and return the results as a generator, where each row is
a Python dictionary.

**Returns:** A dictionary representing a row of query results.

**Parameters:**
- `query` (str): The Bauplan query to execute. Column and table names are case-sensitive.
- `ref` (str | [Ref](/reference/bauplan-schema#bauplan-schema-ref) | None): The ref, branch name or tag name to query from.
- `max_rows` (int | None): The maximum number of rows to return; default: `None` (no limit).
- `cache` (Literal['on', 'off'] | None): Whether to enable or disable caching for the query.
- `namespace` (str | [Namespace](/reference/bauplan-schema#bauplan-schema-namespace) | None): The Namespace to run the query in. If not set, the query will be run in the default namespace for your account.
- `args` (dict[str, str] | None): Additional arguments to pass to the query (default: `None`).
- `priority` (int | None): Optional job priority (1-10, where 10 is highest priority).
- `client_timeout` (int | None): seconds to timeout; this also cancels the remote job execution. Defaults to 1800 seconds.

#### Example

```python
import bauplan
client = bauplan.Client()

# query the table and iterate through the results one row at a time
res = client.query_to_generator(
    query='SELECT Name, Age FROM bauplan.titanic LIMIT 100',
    ref='my_ref_or_branch_name',
)

for row in res:
    ... # handle results
```

### query_to_json_file

```python
def query_to_json_file(path: str | pathlib.Path, query: str, *, file_format: Literal['json', 'jsonl'] = 'json', ref: str | Ref | None = None, max_rows: int | None = None, cache: Literal['on', 'off'] | None = None, namespace: str | Namespace | None = None, args: dict[str, str] | None = None, priority: int | None = None, client_timeout: int | None = None) -> pathlib.Path
```

Export the results of a SQL query to a file in JSON format.

**Returns:** The path of the file written.

**Parameters:**
- `path` (str | pathlib.Path): The name or path of the file json to write the results to.
- `query` (str): The Bauplan query to execute. Column and table names are case-sensitive.
- `file_format` (Literal['json', 'jsonl']): The format to write the results in; default: `json`. Allowed values are 'json' and 'jsonl'.
- `ref` (str | [Ref](/reference/bauplan-schema#bauplan-schema-ref) | None): The ref, branch name or tag name to query from.
- `max_rows` (int | None): The maximum number of rows to return; default: `None` (no limit).
- `cache` (Literal['on', 'off'] | None): Whether to enable or disable caching for the query.
- `namespace` (str | [Namespace](/reference/bauplan-schema#bauplan-schema-namespace) | None): The Namespace to run the query in. If not set, the query will be run in the default namespace for your account.
- `args` (dict[str, str] | None): Additional arguments to pass to the query (default: None).
- `priority` (int | None): No description
- `client_timeout` (int | None): seconds to timeout; this also cancels the remote job execution. Defaults to 1800 seconds.

#### Example

```python
import bauplan
client = bauplan.Client()

# query the table and iterate through the results one row at a time
client.query_to_json_file(
    path='/tmp/out.json',
    query='SELECT Name, Age FROM bauplan.titanic LIMIT 100',
    ref='my_ref_or_branch_name',
)
```

### query_to_parquet_file

```python
def query_to_parquet_file(path: str | pathlib.Path, query: str, *, ref: str | Ref | None = None, max_rows: int | None = None, cache: Literal['on', 'off'] | None = None, namespace: str | Namespace | None = None, args: dict[str, str] | None = None, priority: int | None = None, client_timeout: int | None = None) -> pathlib.Path
```

Export the results of a SQL query to a file in Parquet format.

**Returns:** The path of the file written.

**Parameters:**
- `path` (str | pathlib.Path): The name or path of the file parquet to write the results to.
- `query` (str): The Bauplan query to execute. Column and table names are case-sensitive.
- `ref` (str | [Ref](/reference/bauplan-schema#bauplan-schema-ref) | None): The ref, branch name or tag name to query from.
- `max_rows` (int | None): The maximum number of rows to return; default: `None` (no limit).
- `cache` (Literal['on', 'off'] | None): Whether to enable or disable caching for the query.
- `namespace` (str | [Namespace](/reference/bauplan-schema#bauplan-schema-namespace) | None): The Namespace to run the query in. If not set, the query will be run in the default namespace for your account.
- `args` (dict[str, str] | None): Additional arguments to pass to the query (default: None).
- `priority` (int | None): No description
- `client_timeout` (int | None): seconds to timeout; this also cancels the remote job execution. Defaults to 1800 seconds.

#### Example

```python
import bauplan
client = bauplan.Client()

# query the table and iterate through the results one row at a time
client.query_to_parquet_file(
    path='/tmp/out.parquet',
    query='SELECT Name, Age FROM bauplan.titanic LIMIT 100',
    ref='my_ref_or_branch_name',
)
```

### rename_branch

```python
def rename_branch(branch: str | Branch, new_branch: str | Branch) -> Branch
```

Rename an existing branch.
The branch name should follow the convention of "username.branch_name",
otherwise non-admin users won't be able to complete the operation.

**Returns:** The renamed [`bauplan.schema.Branch`](/reference/bauplan-schema#bauplan-schema-branch) object.

**Parameters:**
- `branch` (str | [Branch](/reference/bauplan-schema#bauplan-schema-branch)): The name of the branch to rename.
- `new_branch` (str | [Branch](/reference/bauplan-schema#bauplan-schema-branch)): The name of the new branch.

**Raises:**
- [bauplan.exceptions.RenameBranchForbiddenError](/reference/bauplan-exceptions#bauplan-exceptions-renamebranchforbiddenerror): if the user does not have access to rename the branch.
- [bauplan.exceptions.BranchNotFoundError](/reference/bauplan-exceptions#bauplan-exceptions-branchnotfounderror): if the branch does not exist.
- [bauplan.exceptions.BranchExistsError](/reference/bauplan-exceptions#bauplan-exceptions-branchexistserror): if the new branch name already exists.
- [bauplan.exceptions.NotABranchRefError](/reference/bauplan-exceptions#bauplan-exceptions-notabranchreferror): if the object is not a branch.
- [bauplan.exceptions.InvalidRefError](/reference/bauplan-exceptions#bauplan-exceptions-invalidreferror): if the ref format is invalid.
- [bauplan.exceptions.UnauthorizedError](/reference/bauplan-exceptions#bauplan-exceptions-unauthorizederror): if the user's credentials are invalid.
- `ValueError`: if one or more parameters are invalid.

#### Example

```python
import bauplan
client = bauplan.Client()

assert client.rename_branch(
    branch='username.old_name',
    new_branch='username.new_name',
)
```

### rename_tag

```python
def rename_tag(tag: str | Tag, new_tag: str | Tag) -> Tag
```

Rename an existing tag.

**Returns:** The renamed [`bauplan.schema.Tag`](/reference/bauplan-schema#bauplan-schema-tag) object.

**Parameters:**
- `tag` (str | [Tag](/reference/bauplan-schema#bauplan-schema-tag)): The name of the tag to rename.
- `new_tag` (str | [Tag](/reference/bauplan-schema#bauplan-schema-tag)): The name of the new tag.

**Raises:**
- [bauplan.exceptions.RenameTagForbiddenError](/reference/bauplan-exceptions#bauplan-exceptions-renametagforbiddenerror): if the user does not have access to rename the tag.
- [bauplan.exceptions.TagNotFoundError](/reference/bauplan-exceptions#bauplan-exceptions-tagnotfounderror): if the tag does not exist.
- [bauplan.exceptions.TagExistsError](/reference/bauplan-exceptions#bauplan-exceptions-tagexistserror): if the new tag name already exists.
- [bauplan.exceptions.NotATagRefError](/reference/bauplan-exceptions#bauplan-exceptions-notatagreferror): if the object is not a tag.
- [bauplan.exceptions.InvalidRefError](/reference/bauplan-exceptions#bauplan-exceptions-invalidreferror): if the ref format is invalid.
- [bauplan.exceptions.UnauthorizedError](/reference/bauplan-exceptions#bauplan-exceptions-unauthorizederror): if the user's credentials are invalid.
- `ValueError`: if one or more parameters are invalid.

#### Example

```python
import bauplan
client = bauplan.Client()

assert client.rename_tag(
    tag='old_tag_name',
    new_tag='new_tag_name',
)
```

### revert_table

```python
def revert_table(table: str | Table, *, namespace: str | Namespace | None = None, source_ref: str | Ref, into_branch: str | Branch, replace: bool | None = None, commit_body: str | None = None, commit_properties: dict[str, str] | None = None) -> Branch
```

Revert a table to a previous state.

**Returns:** The [`bauplan.schema.Branch`](/reference/bauplan-schema#bauplan-schema-branch) where the revert was made.

**Parameters:**
- `table` (str | [Table](/reference/bauplan-schema#bauplan-schema-table)): The table to revert.
- `namespace` (str | [Namespace](/reference/bauplan-schema#bauplan-schema-namespace) | None): The namespace of the table to revert.
- `source_ref` (str | [Ref](/reference/bauplan-schema#bauplan-schema-ref)): The name of the source ref; either a branch like "main" or ref like "main@[sha]".
- `into_branch` (str | [Branch](/reference/bauplan-schema#bauplan-schema-branch)): The name of the target branch where the table will be reverted.
- `replace` (bool | None): Optional, whether to replace the table if it already exists.
- `commit_body` (str | None): Optional, the commit body message to attach to the operation.
- `commit_properties` (dict[str, str] | None): Optional, a list of properties to attach to the operation.

**Raises:**
- `ValueError`: if the table identifier is invalid, source_ref or branch_name is blank, the source entry is not Iceberg, a snapshot_id is missing, or a path validation error occurs.
- [bauplan.exceptions.InvalidRefError](/reference/bauplan-exceptions#bauplan-exceptions-invalidreferror): if the ref format from Nessie is invalid.
- [bauplan.exceptions.NotAWriteBranchRefError](/reference/bauplan-exceptions#bauplan-exceptions-notawritebranchreferror): if the destination ref is not a branch.
- [bauplan.exceptions.SameRefError](/reference/bauplan-exceptions#bauplan-exceptions-samereferror): if the source and destination have the same hash.
- [bauplan.exceptions.UnauthorizedError](/reference/bauplan-exceptions#bauplan-exceptions-unauthorizederror): if the JWT is invalid or the auth session is missing.
- [bauplan.exceptions.ForbiddenError](/reference/bauplan-exceptions#bauplan-exceptions-forbiddenerror): if the user lacks writer role.
- [bauplan.exceptions.RevertTableForbiddenError](/reference/bauplan-exceptions#bauplan-exceptions-reverttableforbiddenerror): if there is a zone/workspace restriction on the destination branch.
- [bauplan.exceptions.RefNotFoundError](/reference/bauplan-exceptions#bauplan-exceptions-refnotfounderror): if the source ref doesn't exist.
- [bauplan.exceptions.TableNotFoundError](/reference/bauplan-exceptions#bauplan-exceptions-tablenotfounderror): if the source table is not found on the source ref.
- [bauplan.exceptions.BranchNotFoundError](/reference/bauplan-exceptions#bauplan-exceptions-branchnotfounderror): if the destination branch doesn't exist.
- [bauplan.exceptions.NamespaceUnresolvedError](/reference/bauplan-exceptions#bauplan-exceptions-namespaceunresolvederror): if the namespace cannot be resolved.
- [bauplan.exceptions.BranchHeadChangedError](/reference/bauplan-exceptions#bauplan-exceptions-branchheadchangederror): if a concurrent modification changed the branch head.
- [bauplan.exceptions.RevertDestinationTableExistsError](/reference/bauplan-exceptions#bauplan-exceptions-revertdestinationtableexistserror): if the destination table exists and the replace flag is not set.
- [bauplan.exceptions.RevertIdenticalTableError](/reference/bauplan-exceptions#bauplan-exceptions-revertidenticaltableerror): if the source and destination have the same snapshot.
- [bauplan.exceptions.MergeConflictError](/reference/bauplan-exceptions#bauplan-exceptions-mergeconflicterror): if there is a merge conflict during the transactional revert.

#### Example

```python
import bauplan
client = bauplan.Client()

assert client.revert_table(
    table='my_table_name',
    namespace='my_namespace',
    source_ref='my_ref_or_branch_name',
    into_branch='main',
)
```

### run

```python
def run(project_dir: str, *, ref: str | Ref | None = None, namespace: str | Namespace | None = None, parameters: dict[str, str | int | float | bool | None] | None = None, cache: bool = True, transaction: bool = True, dry_run: bool | None = None, strict: bool = True, preview: str | None = None, args: dict[str, str] | None = None, priority: int | None = None, client_timeout: int | None = None, detach: bool = False) -> RunState
```

Run a Bauplan project and return the state of the run. This is the equivalent of
running through the CLI the `bauplan run` command. Caching, transaction mode, and strict mode are enabled by default.

**Returns:** [`bauplan.state.RunState`](/reference/bauplan-state#bauplan-state-runstate): The state of the run.

**Parameters:**
- `project_dir` (str): The directory of the project (where the `bauplan_project.yml` or `bauplan_project.yaml` file is located).
- `ref` (str | [Ref](/reference/bauplan-schema#bauplan-schema-ref) | None): The ref, branch name or tag name from which to run the project.
- `namespace` (str | [Namespace](/reference/bauplan-schema#bauplan-schema-namespace) | None): The Namespace to run the job in. If not set, the job will be run in the default namespace.
- `parameters` (dict[str, str | int | float | bool | None] | None): Parameters for templating into SQL or Python models.
- `cache` (bool): Whether to enable caching for the run. Defaults to True. Set to False to disable caching.
- `transaction` (bool): Whether to enable transaction mode for the run. Defaults to True. Set to False to disable transaction mode.
- `dry_run` (bool | None): Whether to enable or disable dry-run mode for the run; models are not materialized.
- `strict` (bool): Whether runtime warnings, including failing expectations and invalid column outputs, fail the run. Defaults to True. Set to False to disable strict mode.
- `preview` (str | None): Whether to enable or disable preview mode for the run.
- `args` (dict[str, str] | None): Additional arguments (optional).
- `priority` (int | None): Optional job priority (1-10, where 10 is highest priority).
- `client_timeout` (int | None): seconds to timeout; this also cancels the remote job execution. Defaults to 1800 seconds.
- `detach` (bool): Whether to detach the run and return immediately instead of blocking on log streaming.

#### Example

```python
#! client = bauplan.Client()
# Run a daily sales pipeline on a dev branch, and if successful and data is good, merge to main
run_state = client.run(
    project_dir='./etl_pipelines/daily_sales',
    ref="username.dev_branch",
    namespace='sales_analytics',
)

if str(run_state.job_status).lower() != "success":
    raise RuntimeError(f"{run_state.job_id} failed: {run_state.job_status} - {run_state.error}")
```

### scan

```python
def scan(table: str | Table, *, ref: str | Ref | None = None, columns: list[str] | None = None, filters: str | None = None, limit: int | None = None, cache: Literal['on', 'off'] | None = None, namespace: str | Namespace | None = None, args: dict[str, str] | None = None, priority: int | None = None, client_timeout: int | None = None) -> pyarrow.Table
```

Execute a table scan (with optional filters) and return the results as an arrow Table.

**Returns:** The scan results as a `pyarrow.Table`.

**Parameters:**
- `table` (str | [Table](/reference/bauplan-schema#bauplan-schema-table)): The table to scan.
- `ref` (str | [Ref](/reference/bauplan-schema#bauplan-schema-ref) | None): The ref, branch name or tag name to scan from.
- `columns` (list[str] | None): The columns to return (default: `None`).
- `filters` (str | None): The filters to apply (default: `None`).
- `limit` (int | None): The maximum number of rows to return (default: `None`).
- `cache` (Literal['on', 'off'] | None): Whether to enable or disable caching for the query.
- `namespace` (str | [Namespace](/reference/bauplan-schema#bauplan-schema-namespace) | None): The Namespace to run the scan in. If not set, the scan will be run in the default namespace for your account.
- `args` (dict[str, str] | None): dict of arbitrary args to pass to the backend.
- `priority` (int | None): Optional job priority (1-10, where 10 is highest priority).
- `client_timeout` (int | None): seconds to timeout; this also cancels the remote job execution. Defaults to 1800 seconds.

Note that this function uses SQLGlot to compose a safe SQL query,
and then internally defer to the `query` function for the actual
scan.

#### Example

```python
import bauplan
client = bauplan.Client()

# run a table scan over the data lake
# filters are passed as a string
my_table = client.scan(
    table='titanic',
    ref='my_ref_or_branch_name',
    namespace='bauplan',
    columns=['Name'],
    filters='Age < 30',
)
```

## InfoState

**Attributes:**
- `client_version` (str)
- `organization` ([OrganizationInfo](/reference/bauplan#bauplan-organizationinfo))
- `runners` (list[[RunnerNodeInfo](/reference/bauplan#bauplan-runnernodeinfo)])
- `user` ([UserInfo](/reference/bauplan#bauplan-userinfo))

## JobKind

The kind/type of a job.

**Attributes:**
- `EXTERNAL_TABLE_CREATE` (Final[[JobKind](/reference/bauplan-schema#bauplan-schema-jobkind)])
- `IMPORT_PLAN_APPLY` (Final[[JobKind](/reference/bauplan-schema#bauplan-schema-jobkind)])
- `IMPORT_PLAN_CREATE` (Final[[JobKind](/reference/bauplan-schema#bauplan-schema-jobkind)])
- `QUERY` (Final[[JobKind](/reference/bauplan-schema#bauplan-schema-jobkind)])
- `RUN` (Final[[JobKind](/reference/bauplan-schema#bauplan-schema-jobkind)])
- `TABLE_IMPORT` (Final[[JobKind](/reference/bauplan-schema#bauplan-schema-jobkind)])
- `TABLE_PLAN_CREATE` (Final[[JobKind](/reference/bauplan-schema#bauplan-schema-jobkind)])
- `TABLE_PLAN_CREATE_APPLY` (Final[[JobKind](/reference/bauplan-schema#bauplan-schema-jobkind)])
- `UNSPECIFIED` (Final[[JobKind](/reference/bauplan-schema#bauplan-schema-jobkind)])

## JobState

The execution state of a job.

**Attributes:**
- `ABORT` (Final[[JobState](/reference/bauplan-schema#bauplan-schema-jobstate)])
- `COMPLETE` (Final[[JobState](/reference/bauplan-schema#bauplan-schema-jobstate)])
- `FAIL` (Final[[JobState](/reference/bauplan-schema#bauplan-schema-jobstate)])
- `NOT_STARTED` (Final[[JobState](/reference/bauplan-schema#bauplan-schema-jobstate)])
- `OTHER` (Final[[JobState](/reference/bauplan-schema#bauplan-schema-jobstate)])
- `RUNNING` (Final[[JobState](/reference/bauplan-schema#bauplan-schema-jobstate)])
- `UNSPECIFIED` (Final[[JobState](/reference/bauplan-schema#bauplan-schema-jobstate)])

## OrganizationInfo

**Attributes:**
- `default_parameter_secret_key` (str | None)
- `default_parameter_secret_public_key` (str | None)
- `id` (str)
- `name` (str)
- `slug` (str)

## RefType

The type of a ref.

**Attributes:**
- `BRANCH` (Final[[RefType](/reference/bauplan-schema#bauplan-schema-reftype)])
- `DETACHED` (Final[[RefType](/reference/bauplan-schema#bauplan-schema-reftype)])
- `TAG` (Final[[RefType](/reference/bauplan-schema#bauplan-schema-reftype)])

## RunnerNodeInfo

**Attributes:**
- `hostname` (str)

## UserInfo

**Attributes:**
- `first_name` (str)
- `full_name` (str)
- `id` (str)
- `last_name` (str)
- `username` (str)