Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ openai = ["openai-agents>=0.6.1"]
pydantic_ai = ["pydantic-ai-slim>=1.68.0"]
langchain = ["langchain>=1.0.0", "langgraph>=1.0.0", "langchain-core>=1.0.0"]
tracing = ["opentelemetry-api>=1.36.0"]
zstd = [
"backports.zstd ; python_version < '3.14'",
]

[build-system]
requires = ["maturin>=1.6,<2.0"]
Expand Down
48 changes: 28 additions & 20 deletions python/restate/aws_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
import asyncio
import base64
import os
import contextlib
from typing import cast, Union, Any
from types import ModuleType

from restate.server_types import (
ASGIApp,
Expand Down Expand Up @@ -162,17 +164,22 @@ def lambda_handler(event: RestateLambdaRequest, _context: Any) -> RestateLambdaR
return lambda_handler


def _check_zstd_available() -> bool:
"""Return True if zstd compression is available (Python 3.14+)."""
try:
def _get_zstd_module() -> ModuleType | None:
"""Return the module to be used for zstd compression."""
with contextlib.suppress(ImportError):
import compression.zstd # type: ignore[import-not-found]

return compression.zstd is not None
except ImportError:
return False
return compression.zstd

with contextlib.suppress(ImportError):
import backports.zstd # type: ignore[import-not-found]

ZSTD_AVAILABLE = _check_zstd_available()
return backports.zstd

return None


ZSTD_AVAILABLE = _get_zstd_module() is not None


def is_lambda_compression_supported():
Expand All @@ -184,23 +191,24 @@ def is_lambda_compression_supported():

def zstd_compress(data: bytes | bytearray) -> bytes:
"""Compress data using zstd."""
try:
import compression.zstd # type: ignore[import-not-found]
except ImportError as e:
zstd = _get_zstd_module()

if zstd is None:
raise RuntimeError(
"zstd compression requested but compression.zstd is not available. "
"Python 3.14+ is required for zstd compression support."
) from e
return compression.zstd.compress(data)
"zstd compression requested but compression.zstd or backports.zstd is not available. "
"Install the zstd optional default dependency.",
)
return zstd.compress(data)


def zstd_decompress(data: bytes) -> bytes:
"""Decompress zstd-compressed data."""
try:
import compression.zstd # type: ignore[import-not-found]
except ImportError as e:
zstd = _get_zstd_module()

if zstd is None:
raise RuntimeError(
"Received zstd-compressed request but compression.zstd is not available. "
"Python 3.14+ is required for zstd compression support."
) from e
return compression.zstd.decompress(data)
"Install the zstd optional default dependency.",
)

return zstd.decompress(data)
Loading
Loading