Configuration

xlwings Lite is configured via the following settings. You set them either as environment variables or by using the xlwings-lite CLI when deploying on a Linux VM. XLWINGS_LICENSE_KEY is required; all others are optional.

General

Variable

Default

Description

XLWINGS_LICENSE_KEY

—

Your xlwings license key (request a trial key).

XLWINGS_HOSTNAME

—

e.g., xlwings-lite.mycompany.com. Set this if the downloaded manifest.xml doesn’t use the correct URL.

PORT

8000

Sets the port on which the container, i.e., application runs.

Python packages

Variable

Default

Description

XLWINGS_ENABLE_PYPI

true

If true, allows installing packages directly from https://pypi.org/. Ignored when XLWINGS_PYPI_INDEX_URL is set.

XLWINGS_PYPI_INDEX_URL

—

Full URL of a private PyPI index (e.g., Nexus, Artifactory, devpi, Azure Artifacts) — the same URL you’d pass to pip install --index-url. Example: https://nexus.example.com/repository/pypi-proxy/simple/. For an authenticated index, the credential can be embedded in the URL (e.g., a token: https://<token>@host/.../simple/); it is forwarded to the index and never exposed to the browser.

XLWINGS_PYPI_AUTH_MODE

basic

How the container authenticates to XLWINGS_PYPI_INDEX_URL. basic uses credentials embedded in the URL (or none). Set to azure-managed-identity to authenticate to an Azure Artifacts feed using the Azure platform’s managed identity instead of a token — the container fetches a short-lived Microsoft Entra token at runtime, so no secret is stored. Requires hosting on Azure, see Azure Container Apps guide.

XLWINGS_PYODIDE_DEFAULT_VERSION

314.0.1

The Pyodide version used for newly created workbooks. Existing workbooks keep the version they were pinned to. Available versions: 0.27.5, 314.0.1.

Local package index

Every deployment also has its own package index, served by the container from the folder /srv/static/vendor/pypi/packages. It contains the wheels you add with xlwings-lite packages add (see Download PyPI packages locally) and the published plugins. On other hosting platforms, mount persistent storage at that path to use it, see e.g. Enabling plugins (optional).

xlwings Lite looks for each package in this order:

  1. The packages that are bundled with Pyodide

  2. The local package index.

  3. The private package index (XLWINGS_PYPI_INDEX_URL) if one is configured, otherwise PyPI if it’s enabled.

So a plugin or package in the local package index wins over one with the same name on the private index or PyPI, but not over one that comes with Pyodide.

CORS proxy

Variable

Default

Description

XLWINGS_CORS_PROXY_HOSTS

—

Comma-separated allowlist of hostnames that user Python code can reach via the built-in CORS proxy. Supports exact matches and *.domain.com wildcards (e.g., api.example.com,*.trusted.com). Unset (the default) disables the proxy unless XLWINGS_CORS_PROXY_ALLOW_ALL_HOSTS is true.

XLWINGS_CORS_PROXY_ALLOW_ALL_HOSTS

false

If true (exactly, in lowercase), proxies requests to every host without having to list them one by one, ignoring XLWINGS_CORS_PROXY_HOSTS. See the notes below before enabling this.

The proxy is transparent: users write their requests against the original URL, e.g., requests.get("https://api.example.com/data"), and the add-in routes cross-origin HTTPS requests to allowed hosts through the container, on the add-in’s own origin, so the browser’s CORS rules don’t apply. There is no URL prefix to add. Requests to hosts that aren’t allowed go directly from the browser, so they still work if the target server sends CORS headers itself. The proxy handles https:// targets on the default port 443 only. Redirects to the same host or to another allowed host stay on the proxy, while the browser follows redirects to other hosts directly. Requests with an Authorization header only stay on the proxy for redirects to the same host, so the header isn’t forwarded to another host. Like a direct cross-origin request, a proxied request carries no cookies, and responses can’t set any. The proxy doesn’t forward the add-in’s origin or the user’s IP address to the target host, and it sends no CORS headers, so other websites open in the user’s browser can’t read responses through it.

Choosing between the two settings:

  • XLWINGS_CORS_PROXY_HOSTS is the strict option. Only the listed hosts can be reached through the container, and everything else stays subject to the browser’s CORS rules.

  • XLWINGS_CORS_PROXY_ALLOW_ALL_HOSTS=true is the convenient option: every web API works without maintaining a list. The trade-off is that every cross-origin request is now made by the container rather than the user’s machine. Any web filter or firewall that your company enforces on user traffic doesn’t apply to these requests, unless the container’s outbound traffic goes through the same controls. The proxy also doesn’t require signing in: anyone who can reach xlwings Lite over the network, e.g., with curl, can use it to reach any HTTPS host the container can reach, including internal ones.

Single sign-on

With single sign-on, xlwings Lite signs users in with their Microsoft 365 account through Office. The database gateway uses it to decide which connections each user may use, and the local package index to decide who may publish plugins.

Variable

Default

Description

XLWINGS_ENTRA_CLIENT_ID

—

Client ID of the Microsoft Entra app registration. Set it together with XLWINGS_ENTRA_TENANT_ID; without it, single sign-on is off.

XLWINGS_ENTRA_TENANT_ID

—

Tenant ID of the app registration.

XLWINGS_ENTRA_CLIENT_SECRET

—

A client secret of the app registration for database connections that log in as the signed-in user. Use this or XLWINGS_ENTRA_MANAGED_IDENTITY_CLIENT_ID.

XLWINGS_ENTRA_MANAGED_IDENTITY_CLIENT_ID

—

Client ID of a user-assigned Azure managed identity trusted by the app registration through a federated identity credential. Replaces XLWINGS_ENTRA_CLIENT_SECRET for database connections that log in as the signed-in user. Azure public cloud only; the two options are mutually exclusive.

The app registration needs:

  • An exposed API with the Application ID URI api://<host>/<client ID>, where <host> is the host users load xlwings Lite from (e.g., xlwings-lite.example.com), and the scope access_as_user.

  • Version 2 access tokens.

  • Office’s client IDs as pre-authorized applications, and admin consent.

Single sign-on works with Microsoft 365 work and school accounts only.

Database gateway

The database gateway lets user code connect to PostgreSQL, SQL Server, MySQL and Oracle through SQLAlchemy and pandas, see Database gateway. It runs in the container and holds the database credentials, so they never reach the browser. Without XLWINGS_DB_CONNECTIONS, the gateway is off. Users see the connections they may use in the Databases view of the task pane, see Your connections.

Variable

Default

Description

XLWINGS_DB_CONNECTIONS

—

Space-separated name=url pairs, e.g., sales=postgres://user:password@db.example.com:5432/sales crm=sqlserver://user:password@sql.example.com:1433?database=crm. Users connect by name. In user names and passwords, percent-encode characters that have a meaning in URLs, e.g., @ as %40, / as %2F, : as %3A, ? as %3F, # as %23, % as %25, and a space as %20: mysql://report:p%40ss%2Fword@mysql.example.com/shop for the password p@ss/word. Supported URL schemes: postgres:// (or postgresql://), sqlserver://, mysql://, and oracle://, e.g., mysql://user:password@mysql.example.com:3306/shop?tls=true, where the query takes the Go MySQL driver’s parameters, or oracle://user:password@oracle.example.com:1521/SALESPDB with the service name as the path and the go-ora driver’s options as the query, e.g., ?SSL=enable for TLS, or ?ENCRYPTION=required&DATA%20INTEGRITY=required for Oracle’s native network encryption and integrity checks. Write spaces in option names as %20, since spaces separate the connections. For Oracle Autonomous AI Database, use its TLS connection string’s host, port (1521) and service name with ?SSL=enable, which needs no wallet if the database doesn’t require mutual TLS. With mutual TLS, unzip the database’s wallet into a folder, mount it into the container, and add &WALLET=<folder in the container> to the URL, with port 1522; the wallet’s auto-login file (cwallet.sso) needs no password.

XLWINGS_DB_ACCESS_RULES

—

With single sign-on, which signed-in users may use which connection: space-separated name=subject[,subject...] entries, where a subject is role:<app role value>, group:<group object ID>, or * (every user of the tenant), e.g., sales=role:DB.Sales,group:3f2a... reports=*. Connections without an entry are closed to signed-in users. Every entry must name a configured connection, or the container doesn’t start.

XLWINGS_DB_TOKEN

—

A static token that may use every connection, regardless of XLWINGS_DB_ACCESS_RULES. For setups without single sign-on, users set it as the XLWINGS_DB_TOKEN environment variable in xlwings Lite. The gateway accepts it in addition to single sign-on tokens, so leave it unset if you use single sign-on.

XLWINGS_DB_USER_IDENTITY_CONNECTIONS

—

Space- or comma-separated connections that log in to the database as the signed-in user instead of with credentials in their URL, e.g., sales. Supported for Azure SQL and Azure Database for PostgreSQL, see Logging in as the signed-in user.

XLWINGS_DB_WINGMAN_CONNECTIONS

—

Space- or comma-separated connections that Wingman’s own runs (dry runs and Edit workbook) may use, e.g., sales. Other connections are refused for Wingman’s runs, while users can still run Wingman’s code themselves. Listing a connection allows Wingman to read its data and send the results to its AI provider. List only connections with read-only database credentials, see the note below.

XLWINGS_DB_STATEMENT_TIMEOUT

60s

Maximum duration of a statement, and of a commit. While a statement runs, the user’s task pane doesn’t respond.

XLWINGS_DB_MAX_ROWS

1000000

Maximum number of rows a query may return. Larger results fail with too_many_rows.

XLWINGS_DB_MAX_RESULT_BYTES

104857600

Maximum size of a query result in bytes (100 MB), estimated as JSON. The container holds each result in memory before sending it, so this protects it from running out of memory. Larger results fail with result_too_large.

XLWINGS_DB_MAX_SESSIONS

100

Maximum number of open transactions per container. Beyond it, opening a transaction fails at once with too_many_sessions.

XLWINGS_DB_MAX_SESSIONS_PER_USER

5

Maximum number of open transactions per signed-in user. The static token is exempt, since everyone using it shares it.

XLWINGS_DB_POOL_SIZE

10

Size of each database connection pool, per container. A PostgreSQL URL’s pool_max_conns parameter takes precedence. How many database connections one named connection can open per container depends on its pools: PostgreSQL and SQL Server connections have one pool, so up to this size. Connections that log in as the signed-in user have one pool per user, of this size, together capped by XLWINGS_DB_USER_IDENTITY_MAX_CONNECTIONS. MySQL and Oracle connections with the default connection reuse (users) have one pool per signed-in user, of this size, together capped by XLWINGS_DB_CONNECTION_REUSE_MAX_CONNECTIONS, plus a pool of this size for requests with the static token: up to 30 connections with the defaults. With all, they have only the per-user pools and their cap; with off, only the pool of this size. A database sees up to the sum over all named connections that point at it, times the number of containers.

XLWINGS_DB_USER_IDENTITY_MAX_CONNECTIONS

20

Maximum number of database connections per connection that logs in as the signed-in user, across all users and per container. XLWINGS_DB_POOL_SIZE applies per user.

XLWINGS_DB_CONNECTION_REUSE

—

Who reuses their database connections on a MySQL or Oracle connection, as space- or comma-separated name=mode entries: users (signed-in users; the default), all (also requests with the static token XLWINGS_DB_TOKEN, which then share them), or off (a new connection per request for everyone), e.g., crm=off reports=all. See Reusing MySQL and Oracle connections.

XLWINGS_DB_CONNECTION_REUSE_MAX_CONNECTIONS

20

Maximum number of reused database connections per MySQL or Oracle connection, across all users and per container. XLWINGS_DB_POOL_SIZE applies per user, up to this maximum. With the default users mode, requests with the static token have their own pool on top, see XLWINGS_DB_POOL_SIZE.

XLWINGS_DB_AUDIT

on

Set to off to turn off the audit log.

XLWINGS_DB_AUDIT_SQL

off

Whether the audit log includes the SQL text of statements: off, hash (its SHA-256 hash), or full (the text as sent, plus database error messages). See Audit log.

Important

The gateway doesn’t inspect SQL: a connection allows whatever its database credentials allow. To make a connection read-only, use a database user that may only read, e.g., one with only SELECT grants on PostgreSQL, MySQL or Oracle, or the db_datareader role on SQL Server. Where users need to write, add a separate connection with write access. This also applies to XLWINGS_DB_WINGMAN_CONNECTIONS: the list decides which connections Wingman’s runs may use, not what they do with them.

With single sign-on, the gateway accepts the signed-in user’s token. Its app registration also needs the app roles you use in XLWINGS_DB_ACCESS_RULES, assigned to users or groups.

If you run several containers, route all /db/* requests of a user to the same container (sticky sessions). Transactions live in the container that opened them, and on any other container they fail with unknown_transaction.

Logging in as the signed-in user

By default, the gateway logs in to the database with the user and password in the connection’s URL, so the database sees the same database user for everyone. Connections listed in XLWINGS_DB_USER_IDENTITY_CONNECTIONS instead log in as the signed-in user: the gateway exchanges the user’s single sign-on token for a database token with Microsoft Entra ID’s on-behalf-of flow and logs in with it. The database’s own permissions, row-level security and auditing then apply to the real user. XLWINGS_DB_ACCESS_RULES still decides who may use the connection at all.

This works with Azure SQL Database and Azure Database for PostgreSQL (flexible server). It needs single sign-on, and the static token XLWINGS_DB_TOKEN can’t use these connections. To set it up:

  1. In the app registration, add the database’s delegated permission under API permissions: Azure SQL Database > user_impersonation for Azure SQL, or Azure OSSRDBMS Database > user_impersonation for Azure Database for PostgreSQL. Then grant admin consent.

  2. Add a client secret to the app registration and set it as XLWINGS_ENTRA_CLIENT_SECRET, or configure managed-identity federation on Azure.

  3. Create the users in the database and grant them what they need:

    • Azure SQL, connected as the server’s Microsoft Entra admin: CREATE USER [alice@example.com] FROM EXTERNAL PROVIDER;. A Microsoft Entra group works too, e.g., CREATE USER [Sales Analysts] FROM EXTERNAL PROVIDER;.

    • Azure Database for PostgreSQL, connected as a Microsoft Entra admin to the postgres database: SELECT * FROM pgaadauth_create_principal('alice@example.com', false, false);. The gateway logs in with the user’s sign-in name (preferred_username) as the role name, so every user needs their own role.

  4. Write the connection’s URL without user and password, e.g., sales=sqlserver://sql-example.database.windows.net?database=sales or sales=postgres://pg-example.postgres.database.azure.com:5432/sales?sslmode=require, and list it in XLWINGS_DB_USER_IDENTITY_CONNECTIONS.

The gateway keeps a pool of database connections per user and connection, with up to XLWINGS_DB_POOL_SIZE connections each, and up to XLWINGS_DB_USER_IDENTITY_MAX_CONNECTIONS connections across all users. When a user needs a new connection and the limit is reached, the gateway first closes connections nobody is using, then waits for one until XLWINGS_DB_STATEMENT_TIMEOUT (on SQL Server, at most 15 seconds), and fails with too_many_connections. A transaction keeps its connection until it ends. Idle connections close after a minute, and a user’s pool after 5 minutes without use. Database tokens are cached per user until shortly before they expire. If Microsoft Entra ID refuses the exchange, e.g., because admin consent is missing, the user’s code fails with obo_failed and Entra’s error code.

Reusing MySQL and Oracle connections

PostgreSQL and SQL Server connections are pooled: the drivers reset a connection before the next user gets it. The MySQL and Oracle drivers can’t, so the gateway never hands a MySQL or Oracle connection from one user to another. Instead, each signed-in user’s connections stay open for that user’s later requests, as a connection pool on a desktop would. Opening a connection takes several round trips, more with TLS, so this matters most for databases that aren’t close to the container: against a hosted Oracle database 12 ms away, it made small requests three to eight times faster, and about two seconds faster per request against one with a 330 ms round trip.

XLWINGS_DB_CONNECTION_REUSE sets this per connection name: users (the default) for signed-in users, all to also reuse connections for requests with the static token XLWINGS_DB_TOKEN, or off to open a new connection for every request or transaction. All users of the static token count as one user, so with all they share connections and what’s left on them; by default, each of their requests opens its own. Connections are never shared between Wingman’s runs and code the user runs, but all of a user’s Wingman runs share theirs.

When a connection comes back, the gateway rolls back what’s still open and restores what it depends on: on MySQL autocommit and the server’s default isolation level, on Oracle the session time zone. Everything else a statement sets stays on the connection and may reach the same user’s later requests on that connection name, from any script or workbook, while other requests get other connections:

  • Temporary tables and their rows, MySQL user variables, SET SESSION and ALTER SESSION settings (e.g., NLS formats or the current schema), and Oracle package variables.

  • Locks that a rollback doesn’t release: MySQL’s LOCK TABLES and GET_LOCK(), and Oracle’s DBMS_LOCK user locks. They stay held until a later request on the same connection releases them or the connection closes, and can block other users meanwhile. A connection closes after a minute without use, but as long as it keeps being reused, it stays open, with its locks.

Code that needs session state should create it inside a transaction (with engine.begin():), which keeps one connection from its start to its end. After an error, timeout or lost connection, the gateway closes the connection instead of reusing it. If your users’ code relies on starting with a clean session outside transactions, set the connection to off.

XLWINGS_DB_CONNECTION_REUSE_MAX_CONNECTIONS caps the reused connections of each connection name across its users, as XLWINGS_DB_USER_IDENTITY_MAX_CONNECTIONS does for logins as the signed-in user: when it’s reached, the gateway first closes connections nobody is using, then waits, and fails with too_many_connections. The cap applies per connection name: names that point at the same database count separately.

Authenticating the gateway with a managed identity

On Azure public cloud, the gateway can authenticate its app registration without a client secret. The user’s database login still uses the on-behalf-of flow; the managed identity supplies the gateway’s app credential.

  1. Create a user-assigned managed identity in the same tenant as the app registration and assign it to the Azure compute resource hosting xlwings Lite. System-assigned identities aren’t supported for this federation setup.

  2. In the app registration, open Certificates & secrets > Federated credentials > Add credential, choose Managed Identity, and select that identity. The issuer is https://login.microsoftonline.com/<tenant ID>/v2.0, the subject is the managed identity’s principal (object) ID, and the audience is api://AzureADTokenExchange. See Microsoft’s setup instructions.

  3. Set XLWINGS_ENTRA_MANAGED_IDENTITY_CLIENT_ID to the managed identity’s client ID, leave XLWINGS_ENTRA_CLIENT_SECRET unset, and restart xlwings Lite. Keep XLWINGS_ENTRA_CLIENT_ID set to the app registration’s client ID.

The gateway fetches and caches a platform token for api://AzureADTokenExchange and sends it as client_assertion when exchanging the user’s SSO token. Azure Artifacts uses the same managed-identity implementation with its own resource audience and XLWINGS_PYPI_AZURE_CLIENT_ID setting. The two credentials are cached separately. Delegated database permissions and admin consent are still required as described above.

Audit log

The gateway writes one line per statement, transaction event and refused request to the container’s log output, as JSON with the logger name http.handlers.sql_gateway.audit, so you can route these lines apart from the access log in your log platform. It’s on by default; XLWINGS_DB_AUDIT=off turns it off.

event

When

statement, batch

A statement ran, or one statement with many parameter sets (executemany).

begin, commit, rollback

A transaction was opened or ended by the user’s code. A commit with rolled_back: true rolled back instead because an earlier statement had failed.

expired, cleanup_rollback

The gateway rolled back a transaction that was idle or open for too long (reason: idle or lifetime), or open when the container restarted or reloaded its configuration.

commit_timeout

A commit didn’t finish within XLWINGS_DB_STATEMENT_TIMEOUT; it may or may not have been applied.

forbidden, wingman_not_allowed, unknown_transaction, too_many_sessions

A request was refused before anything ran.

obo_failed, too_many_connections

On a connection that logs in as the signed-in user, Microsoft Entra ID refused the token exchange, or all the connection’s database connections were in use. An obo_failed line adds entra_error_codes, e.g., [65001].

unauthorized, token_expired, invalid_token

A request was refused because its token was missing, expired or invalid.

Each line has these fields, where they apply:

  • request_id: the same ID as the uuid field of the request’s access log line. expired and cleanup_rollback happen without a request and have none.

  • duration: seconds since the request started.

  • principal: the signed-in user as <tenant ID>/<object ID>, or static for XLWINGS_DB_TOKEN, and user: the user’s sign-in name (preferred_username). For a refused token, only a token that was otherwise valid (e.g., expired) names its user.

  • wingman: whether the request came from one of Wingman’s own runs.

  • connection: the connection’s name, never its URL, and transaction: the transaction’s ID, which ties a statement to how its transaction ended.

  • outcome: ok or error. Errors add category and code, plus sqlstate (PostgreSQL, MySQL) and number (SQL Server, MySQL, Oracle); successful statements add rowcount, and batches parameter_sets.

For example:

{"level":"info","ts":1794213393.806,"logger":"http.handlers.sql_gateway.audit","msg":"audit","event":"statement","duration":0.029,"request_id":"71937559-0bd1-4025-a916-2610e6b9b00a","principal":"72f988bf-86f1-41af-91ab-2d7cd011db47/0b8e7c3a-4f5d-4e2b-9c1a-6d2f3e4a5b6c","user":"alice@example.com","wingman":false,"connection":"sales","transaction":"hAf9XM_7omYATYThEB-EzblP_2vQx8kL1mN3oP5qR7sT","outcome":"ok","rowcount":12}

The audit log never contains parameter values, tokens or connection URLs. By default, it also leaves out the SQL text and the database’s error messages, which can contain values, e.g., the duplicate key of a unique violation. Sign-in names and connection names are still personal or sensitive data, so restrict who can read the log. XLWINGS_DB_AUDIT_SQL adds the SQL text:

  • hash logs the SHA-256 hash of the SQL text as sql_sha256, which groups repeated statements. It isn’t anonymization: a statement with predictable values in its text can be recovered by hashing candidates.

  • full logs the SQL text as sent (sql), which contains values where users build SQL with f-strings instead of parameters, and the database’s error messages (message).

To write the audit log to its own file with rotation, add a log block to the global options of the container’s Caddyfile (/etc/caddy/Caddyfile in the image), with a volume for the file:

{
	log default {
		exclude http.handlers.sql_gateway.audit
	}
	log audit {
		output file /data/audit/audit.log {
			roll_size 100MiB
			roll_keep 10
		}
		include http.handlers.sql_gateway.audit
	}
}

Plugins

Plugin authors can publish plugins into the local package index with Publish Plugin in xlwings Lite. Users then find them in the Plugins view and add them to a workbook’s requirements.txt by name. Publishing is off by default: without one of the following settings, nobody may publish, and you add wheels to the package index yourself instead.

Variable

Default

Description

XLWINGS_PLUGIN_PUBLISHERS

—

Who may publish with single sign-on, as comma- or space-separated subjects: role:<app role value> for an app role of the app registration, group:<object ID> for a group, or * for every signed-in user, e.g., role:Plugins.Publish. Requires XLWINGS_ENTRA_CLIENT_ID and XLWINGS_ENTRA_TENANT_ID.

XLWINGS_PLUGIN_PUBLISH_TOKEN

—

A secret that allows publishing without single sign-on, for organizations without Microsoft Entra ID. Give it only to plugin authors, who store it as a Local environment variable in xlwings Lite. It’s shared among the authors, so the audit log can’t tell who used it. To revoke it, change the value and restart xlwings Lite.

You can set both. A request with a single sign-on token is judged by XLWINGS_PLUGIN_PUBLISHERS alone; the publish token is only checked for requests without one. The database gateway’s static token can’t publish.

If you use single sign-on, XLWINGS_PLUGIN_PUBLISHERS is the simplest setup: plugin authors publish with their Microsoft 365 sign-in, so nobody needs a publish token, and the audit log names each publisher. To let every signed-in user publish, set it to *. To limit publishing to a group of authors, create an app role such as Plugins.Publish, assign it to them, and set XLWINGS_PLUGIN_PUBLISHERS=role:Plugins.Publish.

To withdraw a version, delete its wheel from the storage you mounted at /srv/static/vendor/pypi/packages, see Local package index. On a Linux VM, that’s the host folder /var/lib/xlwings-lite/pypi/packages/.

Each upload and refusal is logged as one line with the logger name http.handlers.local_index.audit.

Tooling

Variable

Default

Description

XLWINGS_ENABLE_MISSING_ADDIN_CLEANUP

true

If true, exposes a “Clean up missing add-in references” menu item that strips orphaned add-in references from workbooks in /data. Only required if workbooks that were created with the cloud add-in complain about a missing add-in.