opendal
Apache OpenDAL™ Python binding
Installation
pip install opendal
Usage
import opendal
op = opendal.Operator("fs", root="/tmp")
op.write("test.txt", b"Hello World")
print(op.read("test.txt"))
print(op.stat("test.txt").content_length)
Or using the async API:
import asyncio
async def main():
op = opendal.AsyncOperator("fs", root="/tmp")
await op.write("test.txt", b"Hello World")
print(await op.read("test.txt"))
asyncio.run(main())
1# Licensed to the Apache Software Foundation (ASF) under one 2# or more contributor license agreements. See the NOTICE file 3# distributed with this work for additional information 4# regarding copyright ownership. The ASF licenses this file 5# to you under the Apache License, Version 2.0 (the 6# "License"); you may not use this file except in compliance 7# with the License. You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, 12# software distributed under the License is distributed on an 13# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14# KIND, either express or implied. See the License for the 15# specific language governing permissions and limitations 16# under the License. 17 18from ._opendal import * 19 20__doc__ = _opendal.__doc__ 21__all__ = _opendal.__all__
Operator
is the entry for all public blocking APIs
Create a new blocking Operator
with the given scheme
and options(**kwargs
).
Create a dir at given path.
Notes
To indicate that a path is a directory, it is compulsory to include
a trailing / in the path. Failure to do so may result in
NotADirectory
error being returned by OpenDAL.
Behavior
- Create on existing dir will succeed.
- Create dir is always recursive, works like
mkdir -p
AsyncOperator
is the entry for all public async APIs
Create a new AsyncOperator
with the given scheme
and options(**kwargs
).
Create a dir at given path.
Notes
To indicate that a path is a directory, it is compulsory to include
a trailing / in the path. Failure to do so may result in
NotADirectory
error being returned by OpenDAL.
Behavior
- Create on existing dir will succeed.
- Create dir is always recursive, works like
mkdir -p
Presign an operation for stat(head) which expires after expire_second
seconds.
Presign an operation for read which expires after expire_second
seconds.
A file-like object. Can be used as a context manager.
Read and return at most size bytes, or if size is not given, until EOF.
Read a single line from the file.
A newline character (\n
) is left at the end of the string, and is only omitted on the last line of the file if the file doesn’t end in a newline.
If size is specified, at most size bytes will be read.
Change the stream position to the given byte offset.
Offset is interpreted relative to the position indicated by whence
.
The default value for whence is SEEK_SET
. Values for whence
are:
SEEK_SET
or0
– start of the stream (the default); offset should be zero or positiveSEEK_CUR
or1
– current stream position; offset may be negativeSEEK_END
or2
– end of the stream; offset is usually negative
Return the new absolute position.
A file-like async reader. Can be used as an async context manager.
Read and return at most size bytes, or if size is not given, until EOF.
Change the stream position to the given byte offset.
offset is interpreted relative to the position indicated by whence
.
The default value for whence is SEEK_SET
. Values for whence
are:
SEEK_SET
or0
– start of the stream (the default); offset should be zero or positiveSEEK_CUR
or1
– current stream position; offset may be negativeSEEK_END
or2
– end of the stream; offset is usually negative
Return the new absolute position.
Capability is used to describe what operations are supported by current Operator.
write_multi_max_size is the max size that services support in write_multi.
For example, AWS S3 supports 5GiB as max in write_multi.
write_multi_min_size is the min size that services support in write_multi.
For example, AWS S3 requires at least 5MiB in write_multi expect the last one.