tursodatabase/turso · error · ValueError

TursoSyncDialect does not support host/port in URL. The…

Error message

TursoSyncDialect does not support host/port in URL. The local database path goes after ':///', and remote_url is specified as a query parameter.

What it means

The same URL validator used by TursoSyncDialect rejects host and port components. The dialect is file-first: the local database path goes after ':///', and the remote endpoint is supplied as the remote_url query parameter. There is no host to connect to in the URL authority, so any host or port raises ValueError with that explanation.

Solutions

  1. Use the local path form: sqlite+turso_sync:///path/to/local.db
  2. Move the endpoint to a query parameter: ?remote_url=https://your-endpoint
  3. Put the token alongside it as ?auth_token=...

Example fix

# before
engine = create_engine("sqlite+turso_sync://db.example.com:443/app.db")

# after
engine = create_engine("sqlite+turso_sync:///app.db?remote_url=https://db.example.com&auth_token=<token>")
Defensive patterns

Strategy: validation

Validate before calling

from sqlalchemy.engine.url import make_url

url = make_url(database_url)
if url.host or url.port:
    remote = f"{url.drivername.split('+')[0]}://{url.host}"
    if url.port:
        remote += f":{url.port}"
    database_url = (
        f"sqlite+turso_sync:///{url.database}?remote_url={remote}"
    )
engine = create_engine(database_url)

Try / catch

try:
    engine = create_engine(database_url)
except ValueError as e:
    if "host/port" in str(e):
        raise ValueError("Use sqlite+turso_sync:///local.db?remote_url=... instead") from e
    raise

Prevention

When it happens

Trigger: create_engine('sqlite+turso_sync://localhost:8080/app.db') out of habit from server-database URLs; pasting a libsql:// or https:// endpoint into the SQLAlchemy URL instead of the remote_url parameter.

Common situations: Copy-pasting endpoints from libsql-sqlalchemy examples or cloud console connection strings; muscle memory from postgresql://mysql:// URLs.

Related errors


AI-assisted analysis of tursodatabase/turso@244cde92a7 (2026-08-20). Data as JSON: /api/errors/25ca270524bec0fb. Report an issue: GitHub.

Appendix: source

Thrown at bindings/python/turso/sqlalchemy/dialect.py:386

        return turso.sync

    def connect(self, *cargs, **cparams):
        """Remap sync_url to remote_url for libsql-sqlalchemy compatibility."""

        if "sync_url" in cparams and "remote_url" not in cparams:
            cparams["remote_url"] = cparams.pop("sync_url")
        return super().connect(*cargs, **cparams)

    @staticmethod
    def _validate_sync_url(opts: Dict[str, Any]) -> None:
        """Reject URL components that TursoSyncDialect doesn't support."""
        if opts.get("username") or opts.get("password"):
            raise ValueError(
                "TursoSyncDialect does not support username/password in URL. "
                "Use auth_token query parameter or connect_args instead."
            )
        if opts.get("host") or opts.get("port"):
            raise ValueError(
                "TursoSyncDialect does not support host/port in URL. "
                "The local database path goes after ':///', and remote_url "
                "is specified as a query parameter."
            )

    @staticmethod
    def _extract_sync_params(query_params: Dict[str, str]) -> Dict[str, Any]:
        """Extract and convert sync-specific query parameters into kwargs."""
        kwargs: Dict[str, Any] = {}

        auth_token = query_params.pop("auth_token", None)
        if auth_token:
            kwargs["auth_token"] = auth_token

        client_name = query_params.pop("client_name", None)
        kwargs["client_name"] = client_name or "turso-sqlalchemy"

        long_poll_timeout_ms = query_params.pop("long_poll_timeout_ms", None)

View on GitHub (pinned to 244cde92a7)