trame-server: server implementation of trame 
trame-server is the server implementation of trame. This Python library provide the server implementation of the shared state and controller along with the definition of the web server. The web server aims to be flexible so it can be use within a Jupyter environment or as a standalone desktop application.
This package is not supposed to be used by itself but rather should come as a dependency of trame. For any specificity, please refer to the trame documentation.
Installing
trame-server can be installed with pip:
pip install trame-server
Usage
The Trame Tutorial is the place to go to learn how to use the library and start building your own application.
The API Reference documentation provides API-level documentation.
Environments variables
TRAME_LOG_NETWORK : Path to log file for capturing network exchange. (default: None)
TRAME_WS_MAX_MSG_SIZE : Maximum size in bytes of any ws message. (default: 10MB)
TRAME_WS_HEART_BEAT : Time in second before assuming the server is non-responsive. (default: 30s)
TRAME_DESKTOP_DEBUG : If defined it will allow user to inspect the web content in desktop mode
TRAME_SERVER : If set to true, this will prevent browser from opening by default
WebSocket authentication
Clients must provide a secret to connect to the WebSocket. The secret comes from (in order of precedence):
--authKeyFile PATH : File whose (stripped) content is used as the secret.
--authKey KEY : Secret provided directly on the command line (visible to other users of the machine in the process list).
--authKey auto : A random secret generated every time the server starts.
Otherwise, wslink’s well-known default secret, which every client already knows. Set a secret (--authKey auto is the simplest) to keep other web pages from driving your app.
The browser client reads the secret from the ?secret=... URL parameter. The browser opened automatically and the desktop window (--app) include it whenever it is not the default, and so do the URLs printed at startup. With --authKey auto:
App running at: - Local: http://localhost:8080/?secret=qcNXdzVSWzM9kiVkgSqh9Nk1lPiX0fBDTDaFtmCkx_M - Network: http://127.0.0.1:8080/?secret=qcNXdzVSWzM9kiVkgSqh9Nk1lPiX0fBDTDaFtmCkx_M
The browser opened automatically gets the URL on its command line, which other users of the machine can see in the process list. On a shared machine, add --server and open the printed URL yourself.
When a page is loaded with the right secret, the server also sets an HttpOnly cookie, so reloading the page or opening the app in another tab keeps working once the client has removed the secret from its URL. The cookie only authenticates WebSocket connections opened by the app’s own pages: other pages and programs must send the secret themselves, and are then accepted wherever they come from. The cookie requires the default aiohttp backend. A browser keeps the cookies of the 20 trame servers of a host it opened most recently: opening one more removes the oldest cookie, and that app then needs its URL with the secret again to reconnect.
Add --hide-secret to keep the secret out of the console output, and therefore out of any captured logs: for example with --authKeyFile, or behind a launcher, which saves the output of each process in a log file. The printed URLs then show ?secret=<secret> instead.
When building a client URL yourself (iframe, testing, …), use server.url_query_params once the server is started to get the parameters to append (e.g. {"secret": "..."}, or {} with the default secret).
To accept other tokens as well, or to add conditions, replace the protocol’s validateToken: wslink calls it with the value each client sends as its secret (the ?secret=... URL parameter for the browser client). Do it in a function registered with server.add_protocol_to_configure() before starting the server: trame calls it at startup with its protocol. Keep trame’s own check to extend it rather than replace it:
issued_tokens = {"token-for-alice", "token-for-bob"}
def accept_issued_tokens(protocol):
trame_check = protocol.validateToken # the secret, or the cookie
async def validate_token(token, client_id):
return await trame_check(token, client_id) or token in issued_tokens
protocol.validateToken = validate_token
server.add_protocol_to_configure(accept_issued_tokens)
The replacement must be a coroutine taking (token, client_id). Combined with or, it keeps accepting everything trame accepts, which without --authKey includes wslink’s well-known default secret.
Life cycle callbacks
Life cycle events are directly managed on the application controller and are prefixed with on_*.
on_server_start : Executed at server.start() call while passing the server as argument.
on_server_bind : WSLinkServer is getting bound to trame so you can attach your own routes. Its instance will be passed as argument to callback.
on_server_ready : All protocols initialized and available for client to connect
on_client_connected : Connection established to server
on_client_exited : Linked to browser “beforeunload” event
on_server_exited : Trame is exiting its event loop
on_error : JS error forwarded (msg:str) on the python
on_exception : Server exception occurred when interacting with the UI, in a @state.change listener (sync or async) or in a controller task (ctrl.add_task). The exception instance is provided as arg.
on_server_reload : If callback registered it can be use to hot_reload methods like the UI.
License
trame-server is made available under the Apache License, Version 2.0. For more details, see LICENSE
Community
Trame | Discussions | Issues | Contact Us
Enjoying trame?
Share your experience with a testimonial or with a brand approval.
Development
Install the library in dev mode
# Create venv and install all dependencies
uv sync --all-extras --dev
# Activate environment
source .venv/bin/activate
# Install commit analysis
pre-commit install
pre-commit install --hook-type commit-msg
# Run pre-commit checks
pre-commit run --all-files
Metadata
Release files for trame-server 4.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| trame_server-4.1.3.tar.gz | 48.1 kB | With provenance | Details for trame_server-4.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| trame_server-4.1.3-py3-none-any.whl | Python 3 | none | any | Details for trame_server-4.1.3-py3-none-any.whl |
Total release size: 103.9 kB
Release files / trame_server-4.1.3.tar.gz
| Download URL | trame_server-4.1.3.tar.gz |
|---|---|
| Size | 48.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ba865232498c251aa1bac146f9fd20bb3ca6874179a1139103b07813773b674a
|
|
BLAKE2b-256 checksum How to use checksums |
1ab8fe131013253c9afa3f12b9b82fb1942bd6ca7d9a2548661fa34a37217ff4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.
Transparency logRelease files / trame_server-4.1.3-py3-none-any.whl
| Download URL | trame_server-4.1.3-py3-none-any.whl |
|---|---|
| Size | 55.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e8ad48529fe18d84597a2a036c53f46cb0c4269675d526d40b5ef7bb53557d43
|
|
BLAKE2b-256 checksum How to use checksums |
211738a7a3f088245460acf8109b0cd7b8eb645329eccbf377cc4695e9b2aa28
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.
Transparency logSecurity for trame-server 4.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for trame_server-4.1.3.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.