> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lancedb.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Using Namespaces

> Use LanceDB's namespace-aware table and catalog APIs in Python, TypeScript, and Rust.

export const RsNamespaceTableOps = "let conn = connect(uri).execute().await?;\nlet search_namespace = vec![\"prod\".to_string(), \"search\".to_string()];\nlet recommendations_namespace = vec![\"prod\".to_string(), \"recommendations\".to_string()];\n\nlet schema = std::sync::Arc::new(arrow_schema::Schema::new(vec![\n    arrow_schema::Field::new(\"id\", arrow_schema::DataType::Int64, false),\n]));\n\nconn.create_empty_table(\"user\", schema.clone())\n    .namespace(search_namespace.clone())\n    .execute()\n    .await?;\n\nconn.create_empty_table(\"user\", schema)\n    .namespace(recommendations_namespace.clone())\n    .execute()\n    .await?;\n\nlet search_table_names = conn\n    .table_names()\n    .namespace(search_namespace)\n    .execute()\n    .await?;\nlet recommendation_table_names = conn\n    .table_names()\n    .namespace(recommendations_namespace)\n    .execute()\n    .await?;\n\nprintln!(\"{search_table_names:?}\"); // [\"user\"]\nprintln!(\"{recommendation_table_names:?}\"); // [\"user\"]\n";

export const RsNamespaceAdminOps = "let mut properties = std::collections::HashMap::new();\nproperties.insert(\"root\".to_string(), \"./local_lancedb\".to_string());\nlet db = lancedb::connect_namespace(\"dir\", properties).execute().await?;\nlet namespace = vec![\"prod\".to_string(), \"search\".to_string()];\n\ndb.create_namespace(lancedb::database::CreateNamespaceRequest {\n    namespace: vec![\"prod\".to_string()],\n})\n.await?;\ndb.create_namespace(lancedb::database::CreateNamespaceRequest {\n    namespace: namespace.clone(),\n})\n.await?;\n\nlet child_namespaces = db\n    .list_namespaces(lancedb::database::ListNamespacesRequest {\n        namespace: vec![\"prod\".to_string()],\n        ..Default::default()\n    })\n    .await?;\nprintln!(\n    \"Child namespaces under {:?}: {:?}\",\n    namespace, child_namespaces\n);\n// Child namespaces under [\"prod\", \"search\"]: [\"search\"]\n\ndb.drop_namespace(lancedb::database::DropNamespaceRequest {\n    namespace: namespace.clone(),\n})\n.await?;\ndb.drop_namespace(lancedb::database::DropNamespaceRequest {\n    namespace: vec![\"prod\".to_string()],\n})\n.await?;\n";

export const PyNamespaceAdminOps = "import lancedb\n\ndb = lancedb.connect_namespace(\"dir\", {\"root\": \"./local_lancedb\"})\nnamespace = [\"prod\", \"search\"]\n\ndb.create_namespace([\"prod\"])\ndb.create_namespace([\"prod\", \"search\"])\n\nchild_namespaces = db.list_namespaces(namespace_path=[\"prod\"]).namespaces\nprint(f\"Child namespaces under {namespace}: {child_namespaces}\")\n# Child namespaces under ['prod', 'search']: ['search']\n\nmetadata = db.describe_namespace([\"prod\", \"search\"])\nprint(f\"Metadata for namespace {namespace}: {metadata}\")\n# Metadata for namespace ['prod', 'search']: properties=None\n\ndb.drop_namespace([\"prod\", \"search\"], mode=\"skip\")\ndb.drop_namespace([\"prod\"], mode=\"skip\")\n";

export const PyNamespaceTableOps = "import lancedb\n\ndb = lancedb.connect_namespace(\"dir\", {\"root\": \"./local_lancedb\"})\n\n# Create namespace tree: prod/search\ndb.create_namespace([\"prod\"], mode=\"exist_ok\")\ndb.create_namespace([\"prod\", \"search\"], mode=\"exist_ok\")\ndb.create_namespace([\"prod\", \"recommendations\"], mode=\"exist_ok\")\n\ndb.create_table(\n    \"user\",\n    data=[{\"id\": 1, \"vector\": [0.1, 0.2], \"name\": \"alice\"}],\n    namespace_path=[\"prod\", \"search\"],\n    mode=\"create\",  # use \"overwrite\" only if you want to replace existing table\n)\n\ndb.create_table(\n    \"user\",\n    data=[{\"id\": 2, \"vector\": [0.3, 0.4], \"name\": \"bob\"}],\n    namespace_path=[\"prod\", \"recommendations\"],\n    mode=\"create\",  # use \"overwrite\" only if you want to replace existing table\n)\n\n# Verify\nprint(db.list_namespaces())  # ['prod']\nprint(db.list_namespaces(namespace_path=[\"prod\"]))  # ['recommendations', 'search']\nprint(db.list_tables(namespace_path=[\"prod\", \"search\"]))  # ['user']\nprint(db.list_tables(namespace_path=[\"prod\", \"recommendations\"]))  # ['user']\n";

As your table organization needs grow over time and your projects become more complex, you can use namespaces to organize your tables in a way that reflects your business domains, teams, or environments.

As described in the [Namespaces and Catalog Model](/namespaces) section, namespaces are LanceDB's way of generalizing catalog specs, providing developers a clean way to manage hierarchical organization of tables in the catalog. The SDKs treat a namespace as a path and can use it for table resolution when you use LanceDB outside the root namespace.

## Table operations with namespace paths

Let's imagine a scenario where your table management needs have evolved, and you now have the following multi-level structure to organize your tables outside the root namespace.

```
./local_lancedb (root)
└── prod
    └── search
        └── user   (table)
            └── data   (table)
    └── recommendations
        └── user   (table)
            └── data   (data)
```

Below, we show how you would express table operations within that namespace. Each item in the namespace
list (`["prod", "search"]`) represents a level in the namespace hierarchy, and the table name is
specified when you create, open, list, or drop it.

The SDK methods expose the namespace path in the idiom of each language:

* Python: pass `namespace_path=["prod", "search"]` to table operations.
* Rust: call builder methods such as `.namespace(vec!["prod".to_string(), "search".to_string()])`.
* TypeScript: pass a `namespacePath` array, for example `await db.openTable("user", ["prod", "search"])`.

<CodeGroup>
  <CodeBlock filename="Python" language="Python" icon="python">
    {PyNamespaceTableOps}
  </CodeBlock>

  <CodeBlock filename="Rust" language="Rust" icon="rust">
    {RsNamespaceTableOps}
  </CodeBlock>
</CodeGroup>

<Note>
  Using namespaces is **optional** in LanceDB, and most basic use cases do not require to work with them.
  An empty namespace (`[]`), which is the default, means "root namespace", and the data will be stored in
  the `data/` directory under the specified root path.
</Note>

In TypeScript, namespace-scoped table operations are available on `Connection` even though namespace
lifecycle operations are not exposed there. These calls use the same namespace path array:

* Create a table: `await db.createTable("user", rows, ["prod", "search"], { mode: "create" })`
* List tables: `await db.tableNames(["prod", "search"])`
* Drop a table: `await db.dropTable("user", ["prod", "search"])`

## Namespace management APIs

You can open/create/drop tables inside a namespace path (like `["prod", "search"]`).
The Python and Rust SDKs expose namespace lifecycle operations directly.
In Python, use `lancedb.connect_namespace(...)` when calling namespace lifecycle methods such as
`create_namespace`, `list_namespaces`, `describe_namespace`, and `drop_namespace`.
In Rust, use `lancedb::connect_namespace(...)` and call `create_namespace`, `list_namespaces`,
and `drop_namespace`.

<CodeGroup>
  <CodeBlock filename="Python" language="Python" icon="python">
    {PyNamespaceAdminOps}
  </CodeBlock>

  <CodeBlock filename="Rust" language="Rust" icon="rust">
    {RsNamespaceAdminOps}
  </CodeBlock>
</CodeGroup>

<Note>
  In TypeScript, namespace lifecycle operations such as creating, listing, describing, and dropping
  namespaces are not currently exposed on `Connection`. Use a namespace-aware admin surface, such as
  [REST](/api-reference/rest/index), when you need to manage namespace lifecycle from TypeScript.
</Note>

Namespace creation and deletion have modes that control what happens when the target already exists,
doesn't exist, or contains data:

* Create mode: `create` fails if the namespace already exists, `exist_ok` keeps the existing namespace, and `overwrite` replaces it.
* Drop mode: `FAIL` reports an error when the namespace doesn't exist, and `SKIP` treats a missing namespace as a successful no-op.
* Drop behavior: `RESTRICT` keeps non-empty namespaces from being dropped, and `CASCADE` drops child namespaces and tables first.

Namespace path components can't be empty. Each component can contain only letters, numbers,
underscores, hyphens, and periods.

## Namespaces in LanceDB Enterprise

In LanceDB Enterprise deployments, configure namespace-backed federated databases in a TOML file under your deployment's `config` directory.
LanceDB Enterprise supports both directory-based (`ns_impl = "dir"`) and REST-based (`ns_impl = "rest"`) namespace implementations.
The example below shows how to configure a directory-based namespace implementation in LanceDB Enterprise.

```toml theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
# Federated database configuration for DirectoryNamespace
# This example uses minio storage
[federated_dbs.federated_dir_test]
ns_impl = "dir"
root = "s3://<your-deployment>/<your-dir>"
"storage.region" = "us-east-1"
"storage.endpoint" = "http://localhost:9000"
"storage.access_key_id" = "minioadmin"
"storage.secret_access_key" = "minioadmin"
"storage.allow_http" = "true"
# Far future expiration (year 2100)
"storage.expires_at_millis" = "4102444800000"
```

The example above uses MinIO, but the same approach applies to other cloud object storage platforms based on your deployment.

For REST-based namespace servers, you can specify the namespace implementation as `"rest"` with forwarding prefixed headers
for authentication and context propagation.

```toml theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
[federated_dbs.federated_rest_test]
ns_impl = "rest"
uri = "http://<your_org>.internal.catalog.com"
forward_header_prefixes = ["X-forward"]
```

With `forward_header_prefixes = ["X-forward"]`, any incoming header starting with `X-forward` is forwarded to
`http://<your_org>.internal.catalog.com`. This is useful for auth propagation, for example sending
`X-forward-authorization: Bearer xxxx`.

For the LanceDB REST API itself, requests use `x-api-key` for API-key authentication. If your endpoint
serves more than one database, LanceDB can also use headers such as `x-lancedb-database` or
`x-lancedb-database-prefix` to route the request to the right database context.

## Related references

* [Client SDK API references](/api-reference)
* [REST API Reference](/api-reference/rest)
* [Namespaces and the Catalog Model](/namespaces)
