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

# Session.add_external_table()

<span id="atoti.Session.add_external_table" />

> Session.add\_external\_table(<br />
>     *external\_table*: [ExternalTable](./atoti.directquery.ExternalTable#atoti.ExternalTable)\[ExternalDatabaseConnectionConfigT],<br />
>     /,<br />
>     *table\_name*: [str](https://docs.python.org/3/library/stdtypes.html#str) | [None](https://docs.python.org/3/library/constants.html#None) = `None`,<br />
>     \*,<br />
>     *columns*: [Mapping](https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping)\[[str](https://docs.python.org/3/library/stdtypes.html#str), [str](https://docs.python.org/3/library/stdtypes.html#str)] = `frozendict({})`,<br />
>     *config*: ExternalTableConfig\[ExternalDatabaseConnectionConfigT] | [None](https://docs.python.org/3/library/constants.html#None) = `None`,<br />
> ) → [Table](./atoti.Table#atoti.Table)

Add a table from an external database to the session.

### Parameters

<h4 id="atoti.Session.add_external_table.external_table">
  *external\_table*
</h4>

The external database table from which to build the session table.
Instances of such tables are obtained through an external database connection.

<h4 id="atoti.Session.add_external_table.table_name">
  *table\_name*
</h4>

The name to give to the table in the session.
If `None`, the name of the external table is used.

<h4 id="atoti.Session.add_external_table.columns">
  *columns*
</h4>

Mapping from external column names to local column names.
If empty, the local columns will share the names of the external columns.

<h4 id="atoti.Session.add_external_table.config">
  *config*
</h4>

The config to add the external table.
Each [DirectQuery plugin](../getting_started/plugins#directquery) has its own `TableConfig` class.

***

```pycon theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
>>> external_database = session.connect_to_external_database(connection_config)
>>> external_table = external_database.tables["TUTORIAL", "SALES"]
>>> list(external_table)
['SALE_ID', 'DATE', 'SHOP', 'PRODUCT', 'QUANTITY', 'UNIT_PRICE']
```

Add the external table, filtering out some columns and renaming the remaining ones:

```pycon theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
>>> from atoti_directquery_snowflake import TableConfig
>>> table = session.add_external_table(
...     external_table,
...     columns={
...         "SALE_ID": "Sale ID",
...         "DATE": "Date",
...         "PRODUCT": "Product",
...         "QUANTITY": "Quantity",
...     },
...     config=TableConfig(keys={"Sale ID"}),
...     table_name="sales_renamed",
... )
>>> table.head().sort_index()
              Date Product  Quantity
Sale ID
S0007   2022-02-01   BED_2       1.0
S0008   2022-01-31   BED_2       1.0
S0009   2022-01-31   BED_2       1.0
S0010   2022-01-31   BED_2       3.0
S0019   2022-02-02   HOO_5       1.0
```
