Skip to main content

Getting started

Your first program​

This program builds an operator, writes a file, reads it back, inspects its metadata, and deletes it. It runs against the in-memory service with no credentials, so you can run it right after installing.

Use Python 3.11 or later and install from PyPI:

pip install opendal

Or install from Anaconda main:

conda install opendal

Or install from conda-forge:

conda install conda-forge::opendal
import opendal

# Configure a service, then build an operator from it.
op = opendal.Operator("memory")

# The same verbs work on every service.
op.write("hello.txt", b"Hello, World!")

data = op.read("hello.txt") # returns bytes
print(data.decode())

meta = op.stat("hello.txt")
print(f"size = {meta.content_length} bytes")

op.delete("hello.txt")

Note that write takes bytes and read returns bytes.

Point it at a real backend​

Only the service changes; the operations stay identical. The scheme is the first argument, and configuration is passed as keyword arguments:

import opendal

op = opendal.Operator("s3", bucket="my-bucket", region="us-east-1")

op.write("hello.txt", b"Hello from S3!")
print(op.read("hello.txt"))

Connecting to your storage covers configuration and credentials. Services lists the backends and their configuration keys.

Build with additional services​

PyPI wheels ship the largest verified service set for each target. Every wheel includes the common services-all group. The 64-bit Linux, macOS, and Windows wheels also include Foyer. The 64-bit Linux and macOS wheels include SFTP. See the wheel service matrix for target architectures.

To add D1 to the common service set, run this from bindings/python in an active virtual environment with Maturin installed:

maturin develop --release --features services-all,services-d1

The Python layers are built in. Exposing a new Rust layer requires Python binding code.

Async usage​

OpenDAL has a first-class async API. Use AsyncOperator with the same verbs, awaiting each call:

import asyncio
import opendal

async def main():
op = opendal.AsyncOperator("s3", bucket="my-bucket", region="us-east-1")
await op.write("hello.txt", b"Hello, World!")
data = await op.read("hello.txt")
print(data.decode())

asyncio.run(main())

Both operators expose the same operations. Convert between them with op.to_async_operator() and op.to_operator() when you need the other form.