⬆️ Migrating to v5¶
Meerschaum v5 runs its core, CLI, jobs, Compose, HTTP API, and MCP server in Rust. Your existing tables, YAML configuration, Pipe definitions, and Python plugins stay compatible—check the deliberate changes below before upgrading.
Upgrade checklist¶
- Back up your configuration and database; keep your v4.1 venv for rollback.
- Confirm Python 3.11+ (only needed for Python plugins, the Python API, or extras).
- Install the extras you use (
meerschaum[polars],[pandas],[dash],[api], etc.). - Test a sync, downstream pipe, and scheduled job on a scratch
MRSM_ROOT_DIRagainst a copy of your database. - Review teams and permissions if you run a shared API server.
- Upgrade, run
mrsm doctor, and checkmrsm show jobs(re-enter any blank legacy command withmrsm edit jobs NAME).
See the v5 changelog for new features and Stack upgrades for PostgreSQL maintenance.
Upgrading an installation¶
Python 3.11+ and a zero-dependency wheel. Python 3.10, setup.py, and pyoxidizer portable archives are removed. pip install meerschaum ships a dependency-free maturin wheel containing the Rust core and Python SDK (mrsm and python -m meerschaum run the native CLI). For a standalone binary without Python, use cargo install meerschaum --locked (Rust 1.95+) or GitHub Releases.
| Extra | Installs | Needed when |
|---|---|---|
[polars] |
polars |
New-root default (dataframe: polars) or as_polars=True. |
[pandas] |
pandas, pyarrow |
Upgraded-root dataframe: pandas or as_pandas=True. |
[geo] |
shapely, pyproj, geopandas, geoarrow-types |
Python geometry objects or GeoDataFrames. |
[sql] |
SQLAlchemy, psycopg, PyMySQL |
Explicit conn.engine or SQLAlchemy sessions (native SQL needs none). |
[sql-mssql], [sql-oracle], [sql-duckdb], [sql-cockroachdb] |
Flavor drivers | Explicit SQLAlchemy access ([sql-duckdb] also enables shared Python DuckDB). |
[api] |
fastapi, uvicorn, a2wsgi, PyJWT, websockets, python-multipart |
Plugins using @api_plugin, @web_page, or Python MCP tools. |
[dash] |
dash, dash-bootstrap-components, dash-ace, dash-extensions, [api], pandas |
Web console (/dash) or @dash_plugin pages. |
[shell] / [gui] / [cli-tools] |
ptpython / pywebview / pgcli, mycli, litecli, gadwall |
mrsm python, mrsm start gui, or Python SQL shells. |
[full] |
pandas, polars, geo, sql, api, dash, shell |
All standard integrations (default Docker image; :slim ships base wheel only). |
Self-upgrades (mrsm upgrade mrsm). Upgrades the owning install (pip/uv/pipx, Cargo, or binary) in place without inferring the target from MRSM_PYTHON. Prompts are asked up front (upgrade, stack pull, stack restart; flags: --yes, --noask, --force, --no-pull, -A --pre, -A --version X.Y.Z, and -A --break-system-packages on PEP 668 distros).
Upgrading a --user install from 5.0.x
When uv is installed, 5.0.x's mrsm upgrade mrsm in a --user install tries to write to system site-packages. Upgrade to 5.1.0+ with pip directly:
DuckDB and Oracle drivers. Python hosts with meerschaum[sql-duckdb] and MRSM_DUCKDB_LIB unset share the Python DuckDB driver across Rust Pipe operations and SQLAlchemy. Standalone and base installs load libduckdb (v1.4+) via MRSM_DUCKDB_LIB, <root>/drivers/, system paths, or checksum-verified download (mrsm install driver duckdb, mrsm show drivers). Oracle now requires Instant Client (libclntsh) instead of thin mode.
Behavior changes at a glance¶
| Area | v4.1 | v5 |
|---|---|---|
| YAML & config | PyYAML tags (!!python/object) allowed; truncated writes |
Safe native YAML (rejects !!python/* except !!python/tuple); atomic 0600 writes. api.uvicorn.* → api.server.*. |
| Env vars | Any MRSM_<X>_<Y> became a connector; MRSM_NO_AUTO_INSTALL still fetched semver/uv |
Only built-in (sql, api, valkey, plugin, systemd) and @make_connector types become connectors. MRSM_NO_AUTO_INSTALL=1 blocks all implicit installs. |
| Timeouts | 30 s+ retries on unreachable servers | Fails fast on refused/DNS/auth errors, or after connect_timeout / MRSM_CONNECT_TIMEOUT (default 5 s). Raise for serverless DBs. |
| Python DB errors | read/exec/value and pipe.get_data/get_rowcount/get_sync_time returned None/0 |
Raise DB / 5xx errors; pass silent=True for v4 behavior. Unsynced pipes still read empty. |
| DataFrames | Always pandas; as_dask=True supported |
Fresh roots default to Polars; upgraded 4.x roots auto-pin dataframe: pandas. Dask removed (TypeError—use as_iterator=True or as_polars=True). |
| Null-like strings | 'None', 'NA', 'nan', '' stored/queried as NULL |
Literal text in declared text and text index columns (use None / '_None' for SQL NULL; Oracle '' stays NULL). |
Unique keys & mrsm pipes |
Duplicate pipe/user/plugin rows allowed; mrsm pipes shown |
Adds unique indexes uq_mrsm_pipes_keys, uq_mrsm_users_username, uq_mrsm_plugins_plugin_name (mrsm doctor flags duplicates). mrsm pipes hidden unless -c mrsm. |
| Debug & colors | dprint() to stdout; colors when piped; --nopretty exited 0 |
--debug / dprint() write to stderr (secrets redacted). Colors disable when piped (NO_COLOR/FORCE_COLOR). --nopretty exits 1 on failure. |
| CLI & editors | --engine laps, CLI daemons, pyvim fallback |
--loop replaces --engine laps; CLI daemons retired; editors use $VISUAL → $EDITOR → vi. mrsm python script.py [args] runs the script. |
| Auth & limits | Open defaults; failed scope reads granted all; no body limit | First user is admin; self-registration off; default role editor. Permissions fail closed (503). Pre-v5 JWTs/sessions re-login once (API keys stay). Request limits enforced (api:limits, 413). |
Jobs, CLI, and Compose¶
- Every root uses
systemd. On systemd hosts, v5 usessystemdfor all roots—including Compose projects (mrsm-<job>.service,mrsm-<project>.<job>.service,mrsm-<hash>.<job>.service), pinningMRSM_PYTHON. Existinglocaljobs move on the nextcompose uporrestart jobs; opt out withmeerschaum:executor: local. - Staggered startup & job health. Bulk starts stagger via
jobs.startup.*(--no-staggerskips).--looprepeats any action and tracks laps/health (Job health). - Stricter jobs & API redaction. Job names must be one path component. Remote jobs inherit the server's env (keeping Compose stamps),
GET /jobsredacts secrets, and console workers are scoped to owner, team managers, and admins. - Chains vs Pipelines.
a + b : <flags>action chains (and saved 4.1 chain jobs) keep running;start pipeline NAME/stop pipeline NAMEnow manage saved Pipelines. - Compose & copy.
mrsm compose explainis side-effect free (no DBs, caches, or installs), validates missing references, and runs a read-only engine plan (--fail-on-flushfor CI deploy gates);compose upchecks job ownership first and forwards--allow-protected;include:/parent:support multi-project trees (Compose).copy pipesexits1if any pipe fails, and--sync-data incrementalsyncs only new rows. - Interactive UX.
show datatruncates like pandas (--allprints all);show sizescounts shared tables once;show pipeslists failing pipes;bootstrap pipessuggests keys with a new SQL prompt order; Ctrl-C cleanly cancels and releases leases.
The syncing engine¶
v5 tracks pipe dependencies (parents, children, and {{ Pipe() }} references) for multi-pipe runs, dry-run plans, and resumable executions:
mrsm sync pipes -c sql:main -m daily_rollup --parents # ancestors first
mrsm sync pipes -c sql:main -m raw_events --children # downstream pipes
mrsm plan pipes -t reports --parents # dry run
mrsm sync pipes -t reports --parents --resume <run_id> # resume failed nodes
mrsm start pipeline daily # background Pipeline job
Bare sync pipes keeps v4 semantics, except every sync records a status row in mrsm_engine_sync_status (pipe.get_sync_status(), GET /engine/sync-status). Inside engine runs (--parents, --children, mrsm.Pipeline, or --loop with edges):
- Children never sync past their parents' minimum sync time.
- Definition changes sync forward by default. Editing
columns,fetch, or normalizedsqllogs a warning and advances the stored hash on the next sync, while explicitdtypesedits alter columns in place. Setflush: { mode: "clear" | "upsert" }(orsystem.engine.flush.auto: true) to opt into automatic flushing; unapproved flushes pause inflush_pending, and clearing flushes use atomic shadow-table swaps where supported. - Scheduled children follow parent updates rather than their own timer.
See Pipelines, Continuous mode, and Engine state.
Python library and SQL connectors¶
Public APIs (mrsm.Pipe, get_connector, get_config, pipe.sync, get_data, verify, filter_existing, enforce_dtypes) keep their v4 signatures:
mrsm.SyncResult:pipe.sync()returns a tuple subclass unpacking as(success, message)withinserted,updated,upserted,deleted,changed_intervals, andduration. PyArrow Tables/RecordBatches, tuples, and chunk generators all sync natively in Rust.- Native SQL:
SQLConnector.read(),exec(),exec_queries(),value(),to_sql(), and catalog helpers run in Rust withoutmeerschaum[sql].exec()returnsNativeResult(lastrowidisNone;commit=Falserolls back). Keep[sql]for.engineor explicit SQLAlchemy transactions (or setnative_sql: false). Avoid mixing.engine/sqlite3with native calls on the same SQLite/GeoPackage file. - DataFrames & timezones: Override the DataFrame library with
meerschaum.yaml'sdataframe,MRSM_DATAFRAME, oras_polars/as_pandas(Reading data). Pandas reads return Arrow-backed dtypes (double[pyarrow],large_string[pyarrow],timestamp[ns, tz=UTC][pyarrow]); PostgreSQL UTC tzinfo isdatetime.timezone.utcinstead ofZoneInfo('Etc/UTC'). Convert frames in pandas-only hooks withmeerschaum.utils.dataframe.to_pandas(df). - API & Valkey clients:
APIConnector.make_request()returns lightweightApiResponse(norequestsdependency);ValkeyConnector.clientfalls back to a built-in client unlessvalkeyis installed. - New helpers:
pipe.sync(..., replace=True)(Replacing a window),pipe.get_rowcount(estimate=True),pipe.verify_schema(),mrsm.Pipeline, and unknown-kwarg warnings inget_data().
Removed internals (raise ImportError naming the replacement):
| Removed | Replacement |
|---|---|
meerschaum.connectors.sql._pipes, _users, _plugins, _fetch, _partition, _compress, _maintenance |
Public SQLConnector methods (_sql, _create_engine, _uri, tables.get_tables, _users.valid_username stay) |
SQLConnector.get_add_columns_queries, get_alter_columns_queries, get_to_sql_dtype, create_pipe_table_from_df |
None (Rust generates DDL internally) |
meerschaum.actions.<module> and meerschaum.api.routes.* |
meerschaum.actions.actions['<name>'] / mrsm.entry([...]) |
Daemon(target=...), run_daemon, daemon_action, daemon_entry |
meerschaum.jobs.Job (read/control Daemon façade stays) |
meerschaum.utils.packages.dash |
List dash in required and call attempt_import('dash') |
meerschaum.utils.sql and standard plugin SDK helpers (SuccessTuple, attempt_import, Venv, make_connector, make_action, hooks, User, Token) are preserved.
Teams, access, and permissions¶
- Roles & registration: The first API user is admin; self-registration is then disabled unless
api.permissions.registration.users: true. Default role iseditor(api.permissions.default_role): Viewer reads; Editor manages pipes/SQL and starts jobs; Operator adds actions, web terminal (webterm:use), and job management. Legacyapi.permissions.actions.non_admin: truemaps to Operator;--securerestricts actions and terminal to admins. - Tokens & teams: Tokens are capped at their owner's current scopes (
scopes=[]grants nothing;*is stored literally). Every user belongs to Everyone, connectors acceptteams: [...], andaccessandlocksare now reserved pipe parameter keys. - Locks & protected connectors: Pipe locks apply locally and cannot be bypassed by
--force,-y, or--allow-protected(mrsm unlock pipes --locks sync). Connectors withprotected: trueblock all writes unless--allow-protected,MRSM_ALLOW_PROTECTED=1, orallow_protected()is active.
See Access and locks, Permissions, Teams, and Tokens.
Plugin authors¶
Data plugins (fetch, sync, register, setup), @make_action, hooks, @make_connector, and per-plugin venvs keep their v4 interfaces. Key updates:
- Worker processes &
-P: CLI and server runs execute Python plugins in a long-lived worker launched with-P(cwd is not onsys.path). Do not assume fresh module globals per command, and keep helper modules insideMRSM_PLUGINS_DIRor installed packages. - Declare dependencies: The base
mrsmvenv no longer pre-installspandas,requests,dash,plotly,rich,dask, etc. Declare everything inrequired = [...]. Audit and clean venvs withmrsm show venvsandmrsm prune venvs --dry; runmrsm install required <plugin>after upgrading Python minor versions. - Manifests & actions: Decorators cache in a plugin manifest (
mrsm reloadrebuilds it).@make_action(name='weather wait')supports multi-word actions, and any action repeats under--loopautomatically unless it defines aloopparameter. - Streaming & graph windows: Graph runs may pass chunk-aligned historical
begin/endwindows. CustomIS_INSTANCE = Trueconnectors can implementacquire_pipe_lease/release_pipe_lease. Legacy--listenkeeps working, or switch toIS_STREAMING = Truewithsubscribe(pipe, sink)for engine-managed micro-batching and post-commit acks:
IS_STREAMING = True
def subscribe(pipe, sink, **kw):
client.on_message = lambda m: sink.push([parse(m)], token=m.mid)
client.connect(...)
client.loop_forever()
- API plugins (
@api_plugin) & MCP: Python routes andmeerschaum.mcp.toolhandlers run in a Python API host behind the Rust proxy (needsmeerschaum[api]). Core routes live in Rust: replace core middleware withapi.permissions.rate_limitsor NGINX, and replace route-stripping hooks withapi.permissions.routes.allowlist/disabledor--public(Permissions). Plugin routes aren't in/openapi.json, andapi.dash.sessionsIDs must be UUID strings. New helpers:session_user,optional_session_user,mount_static(Web Pages),meerschaum.utils.cache(Caching), andmeerschaum.testing(Testing). - Dash plugins (
@dash_plugin/@web_page): Requiresmeerschaum[dash](declaredash-daqinrequiredif used)./dashis now the Overview; the old dashboard is at/dash/terminal. Console callbacks require a signed-in session—mark public ones with@dash_plugin(public=True)or@web_callback(..., public=True)(or setapi.dash.callbacks_require_session: false).
Option B: the page contract (recommended for new pages)¶
Return an HTML fragment from @web_page to build console pages that work identically in Python and Rust plugins. The console frames your fragment at /dash/<path> and bundles Plotly.js 4 (meerschaum.plugins.figure(fig)), MapLibre GL JS (<div data-mrsm-map='...'>, requires WebGL2), and HTMX locally—no CDN needed.
from html import escape
from fastapi.responses import HTMLResponse
from meerschaum.plugins import web_page, api_plugin, figure
import plotly.graph_objects as go
def counts_figure(site):
df = counts_pipe.get_data(params={'site': site} if site != 'all' else None)
return figure(go.Figure(go.Scatter(x=df['ts'], y=df['count'])))
@web_page('counts', login_required=True, page_group='Reports')
def counts_page():
opts = ''.join(f'<option value="{escape(v)}">{escape(l)}</option>' for v, l in site_options())
return f'''
<select name="site" hx-get="/acme/counts/figure" hx-target="#acme-fig" hx-trigger="change">
{opts}
</select>
<div id="acme-fig">{counts_figure('all')}</div>
'''
@api_plugin
def init_api(app):
@app.get('/acme/counts/figure', response_class=HTMLResponse)
def counts_figure_route(site: str = 'all'):
return counts_figure(site)
login_required=True(default) is enforced before your function runs (401otherwise). Page functions take no arguments; read query params orsession_userin@api_pluginroutes called by HTMX.- Use
mrsm-theme-*CSS classes for light/dark themes, and Plotly.js 4 trace names (scattermap/layout.mapinstead ofscattermapbox/layout.mapbox).
Rust plugins. Write native plugins as a single .rs file or Cargo cdylib using meerschaum-plugin (replaces a same-named Python plugin and runs on :slim images when prebuilt). See Rust plugins and the advanced guide.
Deployment¶
- Docker & stack: Multi-arch (
amd64/arm64)bmeares/meerschaum([full], withcurl/git/ssh) and:slim(base wheel +curl).mrsm stackpinsbmeares/meerschaum:<version>-full, mountscreate-extensions.sqlas a single file so TimescaleDB init/tuning runs on new volumes, stores secrets in<root>/stack/secrets/, and verifiesPG_VERSIONbefore startingdb. Update existing DBs withmrsm upgrade extensionsormrsm upgrade postgres(Stack, Stack upgrades). - Native HTTPS: Pass
--keyfile privkey.pem --certfile fullchain.pem(orapi.server.ssl_*) to serve HTTPS via rustls with automatic 30 s /SIGHUPcertificate reload (308redirect from plain HTTP, except/healthcheck). - Web terminal & GUI: Served by the Rust API on a private tmux server under
MRSM_ROOT_DIR(api.webterm.tmux.configto customize). Reverse proxies must forwardHost/X-Forwarded-Hostor WebSockets return403.mrsm start guiopenspywebviewagainst a local--no-authloopback API—avoid on shared machines. - Security & Windows: Plugin archives reject symlink/hardlink members; HTTP MCP SQL blocks internal
mrsm_*tables and SQL-text functions (MCP security). Windows runs the API host over loopback TCP (routes and Dash work), while background jobs (-d) still require Linux, macOS, Docker, or WSL. - Rollback: Keep v4.1 in a separate venv—both versions share the same root and instance layout (set
meerschaum:executor: localif moving back from systemd). Runmrsm deduplicate pipesto clean up legacy v4 SQLite/NULL-upsert duplicates.