Layers#
This page documents all layers in OpenDAL.
- class opendal.layers.CapabilityOverrideLayer(overrides)#
Bases:
LayerA layer that overrides the full capability exposed by an operator.
- class opendal.layers.Layer#
Bases:
objectBase class for all layers.
A layer wraps an operator to intercept operations on the underlying storage, adding behavior such as retries, timeouts, concurrency limits, or content-type detection.
This class is not meant to be instantiated directly. Use a concrete subclass such as RetryLayer or TimeoutLayer and apply it with Operator.layer or AsyncOperator.layer.
- class opendal.layers.ConcurrentLimitLayer(limit)#
Bases:
LayerA layer that limits the number of concurrent operations.
Notes
All operators wrapped by this layer will share a common semaphore. This allows you to reuse the same layer across multiple operators, ensuring that the total number of concurrent requests across the entire application does not exceed the limit.
- static __new__(limit)#
- Parameters:
limit – Maximum number of concurrent operations. Must be greater than zero.
- class opendal.layers.MimeGuessLayer#
Bases:
LayerA layer that guesses MIME types for objects based on their paths or content.
This layer uses the mime_guess crate (see https://crates.io/crates/mime_guess) to infer the
Content-Type.Notes
This layer will not override a
Content-Typethat has already been set, either manually or by the backend service. It is only applied if no content type is present.A
Content-Typeis not guaranteed. If the file extension is uncommon or unknown, the content type will remain unset.- static __new__()#
Create a MIME guessing layer.
- class opendal.layers.RetryLayer(max_times=None, factor=None, jitter=False, max_delay=None, min_delay=None)#
Bases:
LayerA layer that retries operations that fail with temporary errors.
Operations are retried if they fail with an error for which Error.is_temporary returns True. If all retries are exhausted, the error is marked as persistent and then returned.
Notes
After an operation on a Reader or Writer has failed through all retries, the object is in an undefined state. Reusing it can lead to exceptions.
- static __new__(max_times=None, factor=None, jitter=False, max_delay=None, min_delay=None)#
- Parameters:
max_times – Maximum number of retry attempts. Defaults to 3.
factor – Finite backoff factor of at least 1.0. Defaults to 2.0.
jitter – Whether to apply jitter to the backoff.
max_delay – Maximum delay in seconds. Must be finite and non-negative. Defaults to 60.0.
min_delay – Minimum delay in seconds. Must be finite and non-negative. Defaults to 1.0.
- class opendal.layers.TimeoutLayer(timeout=None, io_timeout=None)#
Bases:
LayerA layer that adds timeouts to operations.
Timeouts prevent slow or stalled work from hanging indefinitely, for example when a TCP connection stops emitting IO events. Control operations (such as stat and delete) and IO operations (such as read and write) are bounded by separate timeouts.
Notes
A small amount of overhead is added to IO operations to implement the timeout correctly.
- static __new__(timeout=None, io_timeout=None)#
- Parameters:
timeout – Positive finite timeout in seconds for control operations. Defaults to 60.0.
io_timeout – Positive finite timeout in seconds for I/O operations. Defaults to 10.0.