Skip to main content

Huawei OBS Directory

The following code demonstrates how to load objects from the Huawei OBS (Object Storage Service) as documents.

# Install the required package
# pip install esdk-obs-python
from langchain_community.document_loaders import OBSDirectoryLoader
API Reference:OBSDirectoryLoader
endpoint = "your-endpoint"
# Configure your access credentials\n
config = {"ak": "your-access-key", "sk": "your-secret-key"}
loader = OBSDirectoryLoader("your-bucket-name", endpoint=endpoint, config=config)
loader.load()

Specify a Prefix for Loading

If you want to load objects with a specific prefix from the bucket, you can use the following code:

loader = OBSDirectoryLoader(
"your-bucket-name", endpoint=endpoint, config=config, prefix="test_prefix"
)
loader.load()

Get Authentication Information from ECS

If your langchain is deployed on Huawei Cloud ECS and Agency is set up, the loader can directly get the security token from ECS without needing access key and secret key.

config = {"get_token_from_ecs": True}
loader = OBSDirectoryLoader("your-bucket-name", endpoint=endpoint, config=config)
loader.load()

Use a Public Bucket

If your bucket's bucket policy allows anonymous access (anonymous users have listBucket and GetObject permissions), you can directly load the objects without configuring the config parameter.

loader = OBSDirectoryLoader("your-bucket-name", endpoint=endpoint)
loader.load()

Was this page helpful?


You can leave detailed feedback on GitHub.