Settings¶
xlwings Server can be configured via
.envfile in the root of the repository for sensitive settings during local developmentEnvironment variables for sensitive settings when deployed
pyproject.toml, under[tool.xlwings_server]for settings that aren’t sensitive and the same across all environments (e.g,. dev, prod, etc.).
Using Settings in Code¶
In templates, you access settings like so:
{{ settings.environment }}, i.e., lower-case and without the leadingXLWINGS_.In Python code, you have access to settings as follows:
from xlwings_server import settings settings.environment
Custom Settings¶
To extend the built-in settings (see below) with your own, run the following command on a Terminal:
uv run xlwings-server add config
This adds the config.py file in the root of your repository, where you can add your own settings. Note that this uses Pydantic Settings.
Built-in Settings¶
Please refer to the .env file, which is thoroughly commented. The .env file is created by running uv run xlwings-server init.
Edit the .env file¶
Most of the setting in the .env file are commented out (line starts with a # sign). This means that they use their default value, which is shown in the comment. To change a value, remove the the # and change the value accordingly. E.g., to disable the examples you edit the .env file from:
# XLWINGS_ENABLE_EXAMPLES=true
to:
XLWINGS_ENABLE_EXAMPLES=false
Server Environments¶
A server environment is a separate installation of xlwings Server that serves a specific purpose. Each server environment requires an own .env file or set of environment variables. It is important to configure the name of the environment via XLWINGS_ENVIRONMENT. Allowed values are:
dev: for developmentqa: a deployed version for testingstaging: a deployed version for testinguat: a deployed version for testingprod: the deployed version that is used by the end-users in production
qa, staging and uat serve the same purpose, but different names are offered so that you can stick to the naming convention that you are used to.
Here’s what happens based on the name of the server environment:
The manifest under the
/manifestendpoint shows the correctId.Except for the
prodenvironment, the manifest shows the environment name in the ribbon tab and appends it to the namespace of custom functions. This helps prevent any name clashes when you have the add-in installed for more than 1 environment or just switch between environments.The
devenvironment configures the server to automatically reload when the code changes and shows the details of all Python exceptions in Excel.The
prodenvironment only shows the details ofXlwingsErrorexceptions and does append anything to the name of the ribbon or the name of the custom function namespace.
Environment Variables¶
Instead of using a .env file, you can provide the settings via environment variables. If you are using a hosted solution, they are often called secrets. If you provide both an environment variable and a value in the .env file, the environment variable wins.
Backup¶
The .env file is ignored by Git as it may contain sensitive credentials. You should therefore back it up in a secure location such as a password manager.