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 |
|---|---|---|
|
— |
Your xlwings license key (request a trial key). |
|
— |
e.g., |
|
|
Sets the port on which the container, i.e., application runs. |
Python packages
Variable |
Default |
Description |
|---|---|---|
|
|
If |
|
— |
Full URL of a private PyPI index (e.g., Nexus, Artifactory, devpi, Azure Artifacts) — the same URL you’d pass to |
|
|
How the container authenticates to |
|
|
The Pyodide version used for newly created workbooks. Existing workbooks keep the version they were pinned to. Available versions: |
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:
The packages that are bundled with Pyodide
The local package index.
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 |
|---|---|---|
|
— |
Comma-separated allowlist of hostnames that user Python code can reach via the built-in CORS proxy. Supports exact matches and |
|
|
If |
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_HOSTSis 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=trueis 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., withcurl, 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 |
|---|---|---|
|
— |
Client ID of the Microsoft Entra app registration. Set it together with |
|
— |
Tenant ID of the app registration. |
|
— |
A client secret of the app registration for database connections that log in as the signed-in user. Use this or |
|
— |
Client ID of a user-assigned Azure managed identity trusted by the app registration through a federated identity credential. Replaces |
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 scopeaccess_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 |
|---|---|---|
|
— |
Space-separated |
|
— |
With single sign-on, which signed-in users may use which connection: space-separated |
|
— |
A static token that may use every connection, regardless of |
|
— |
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., |
|
— |
Space- or comma-separated connections that Wingman’s own runs (dry runs and Edit workbook) may use, e.g., |
|
|
Maximum duration of a statement, and of a commit. While a statement runs, the user’s task pane doesn’t respond. |
|
|
Maximum number of rows a query may return. Larger results fail with |
|
|
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 |
|
|
Maximum number of open transactions per container. Beyond it, opening a transaction fails at once with |
|
|
Maximum number of open transactions per signed-in user. The static token is exempt, since everyone using it shares it. |
|
|
Size of each database connection pool, per container. A PostgreSQL URL’s |
|
|
Maximum number of database connections per connection that logs in as the signed-in user, across all users and per container. |
|
— |
Who reuses their database connections on a MySQL or Oracle connection, as space- or comma-separated |
|
|
Maximum number of reused database connections per MySQL or Oracle connection, across all users and per container. |
|
|
Set to |
|
|
Whether the audit log includes the SQL text of statements: |
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:
In the app registration, add the database’s delegated permission under API permissions: Azure SQL Database >
user_impersonationfor Azure SQL, or Azure OSSRDBMS Database >user_impersonationfor Azure Database for PostgreSQL. Then grant admin consent.Add a client secret to the app registration and set it as
XLWINGS_ENTRA_CLIENT_SECRET, or configure managed-identity federation on Azure.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
postgresdatabase: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.
Write the connection’s URL without user and password, e.g.,
sales=sqlserver://sql-example.database.windows.net?database=salesorsales=postgres://pg-example.postgres.database.azure.com:5432/sales?sslmode=require, and list it inXLWINGS_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 SESSIONandALTER SESSIONsettings (e.g., NLS formats or the current schema), and Oracle package variables.Locks that a rollback doesn’t release: MySQL’s
LOCK TABLESandGET_LOCK(), and Oracle’sDBMS_LOCKuser 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.
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.
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 isapi://AzureADTokenExchange. See Microsoft’s setup instructions.Set
XLWINGS_ENTRA_MANAGED_IDENTITY_CLIENT_IDto the managed identity’s client ID, leaveXLWINGS_ENTRA_CLIENT_SECRETunset, and restart xlwings Lite. KeepXLWINGS_ENTRA_CLIENT_IDset 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.
|
When |
|---|---|
|
A statement ran, or one statement with many parameter sets ( |
|
A transaction was opened or ended by the user’s code. A |
|
The gateway rolled back a transaction that was idle or open for too long ( |
|
A commit didn’t finish within |
|
A request was refused before anything ran. |
|
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 |
|
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 theuuidfield of the request’s access log line.expiredandcleanup_rollbackhappen without a request and have none.duration: seconds since the request started.principal: the signed-in user as<tenant ID>/<object ID>, orstaticforXLWINGS_DB_TOKEN, anduser: 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, andtransaction: the transaction’s ID, which ties a statement to how its transaction ended.outcome:okorerror. Errors addcategoryandcode, plussqlstate(PostgreSQL, MySQL) andnumber(SQL Server, MySQL, Oracle); successful statements addrowcount, and batchesparameter_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:
hashlogs the SHA-256 hash of the SQL text assql_sha256, which groups repeated statements. It isn’t anonymization: a statement with predictable values in its text can be recovered by hashing candidates.fulllogs 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 |
|---|---|---|
|
— |
Who may publish with single sign-on, as comma- or space-separated subjects: |
|
— |
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 |
|---|---|---|
|
|
If |