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
20 changes: 20 additions & 0 deletions bindings/python/docs/api/services.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Services

Each service exposes a typed configuration class. Pass an instance to
`Operator.from_config` or `AsyncOperator.from_config`:

```python
from opendal import Operator
from opendal.services import S3Config

op = Operator.from_config(S3Config(bucket="my-bucket"))
```

::: opendal.services
options:
show_source: false
heading_level: 2
show_signature: true
show_signature_annotations: true
separate_signature: true
merge_init_into_class: true
2 changes: 1 addition & 1 deletion bindings/python/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ clean:
stub-gen: setup
@echo "{{ BOLD }}--- Generating Python type stubs ---{{ NORMAL }}"
@cargo run --quiet --manifest-path=../../dev/Cargo.toml -- generate -l python
@uv run maturin develop --generate-stubs
@uv run maturin develop --generate-stubs --features services-all
## This is temporary till the functionalities land in pyo3-introspection. ref: https://github.com/PyO3/pyo3/issues/5137
@echo "{{ BOLD }}--- Post processing generated stubs ---{{ NORMAL }}"
@uv run python scripts/postprocess_stubs.py
Expand Down
1 change: 1 addition & 0 deletions bindings/python/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ nav:
- File: api/file.md
- Layers: api/layers.md
- Operator: api/operator.md
- Services: api/services.md
- Types: api/types.md

markdown_extensions:
Expand Down
60 changes: 59 additions & 1 deletion bindings/python/python/opendal/operator.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ from typing import Any, final
from .capability import Capability
from .file import AsyncFile, File
from .layers import Layer
from .services import Scheme
from .services import Scheme, ServiceConfig
from .types import Entry, Metadata, PresignedRequest

@final
Expand Down Expand Up @@ -162,6 +162,35 @@ class AsyncOperator:
An awaitable that returns True if the path exists, False otherwise.
"""
@classmethod
def from_config(cls, /, config: ServiceConfig) -> AsyncOperator:
"""
Create a new `AsyncOperator` from a typed service config.

The config binds its own scheme, so there is no scheme argument and no
way to pair a config with the wrong service.

Parameters
----------
config : ServiceConfig
A service config such as ``opendal.services.S3Config``.

Returns
-------
AsyncOperator
The new async operator.

Examples
--------
```python
import opendal
from opendal.services import S3Config

op = opendal.AsyncOperator.from_config(
S3Config(bucket="my-bucket")
)
```
"""
@classmethod
def from_uri(cls, /, uri: str, **kwargs) -> AsyncOperator:
"""
Create a new `AsyncOperator` from a URI string.
Expand Down Expand Up @@ -783,6 +812,35 @@ class Operator:
True if the path exists, False otherwise.
"""
@classmethod
def from_config(cls, /, config: ServiceConfig) -> Operator:
"""
Create a new blocking `Operator` from a typed service config.

The config binds its own scheme, so there is no scheme argument and no
way to pair a config with the wrong service.

Parameters
----------
config : ServiceConfig
A service config such as ``opendal.services.S3Config``.

Returns
-------
Operator
The new operator.

Examples
--------
```python
import opendal
from opendal.services import S3Config

op = opendal.Operator.from_config(
S3Config(bucket="my-bucket")
)
```
"""
@classmethod
def from_uri(cls, /, uri: str, **kwargs) -> Operator:
"""
Create a new blocking `Operator` from a URI string.
Expand Down
Loading
Loading