{"library":"opendal","title":"OpenDAL Python Binding","description":"OpenDAL provides a unified data access layer, allowing Python applications to interact with various storage services (e.g., S3, Azure Blob, GCS, local filesystem) through a single API. It's a binding to the Apache OpenDAL Rust core, currently at version 0.46.0 of the Python package. The Python package typically follows the Rust core, though with some release lag, and provides both asynchronous and synchronous interfaces.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install opendal"],"cli":null},"imports":["from opendal import Operator","from opendal import BlockingOperator","from opendal import Error"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import opendal\nimport asyncio\nimport os\n\nasync def main():\n    # Configure OpenDAL for S3. Replace with your actual credentials or use a different scheme.\n    # Using os.environ.get for security and flexibility.\n    config = {\n        \"scheme\": \"s3\",\n        \"bucket\": os.environ.get(\"OPENDAL_S3_BUCKET\", \"your-s3-bucket\"),\n        \"region\": os.environ.get(\"OPENDAL_S3_REGION\", \"us-east-1\"),\n        \"access_key_id\": os.environ.get(\"OPENDAL_S3_ACCESS_KEY_ID\", \"\"),\n        \"secret_access_key\": os.environ.get(\"OPENDAL_S3_SECRET_ACCESS_KEY\", \"\"),\n    }\n    \n    try:\n        # Initialize the asynchronous Operator\n        op = opendal.Operator(config)\n        key = \"hello_opendal.txt\"\n        content_to_write = b\"Hello from OpenDAL Python!\"\n        \n        # Write data asynchronously\n        await op.write(key, content_to_write)\n        print(f\"Successfully wrote '{content_to_write.decode()}' to {key}\")\n        \n        # Read data asynchronously\n        read_content = await op.read(key)\n        print(f\"Successfully read '{read_content.decode()}' from {key}\")\n        \n        # Get metadata asynchronously\n        metadata = await op.stat(key)\n        print(f\"Metadata for {key}: size={metadata.content_length}, last_modified={metadata.last_modified}\")\n        \n        # Clean up\n        await op.delete(key)\n        print(f\"Successfully deleted {key}\")\n\n    except opendal.Error as e:\n        print(f\"OpenDAL Error: {e}\")\n    except Exception as e:\n        print(f\"An unexpected error occurred: {e}\")\n\nif __name__ == \"__main__\":\n    # Ensure the environment variables are set for S3 or use a simpler scheme like 'memory'.\n    # Example for 'memory' scheme (no credentials needed, replace config):\n    # op = opendal.Operator(\"memory\")\n    asyncio.run(main())","lang":"python","description":"This quickstart demonstrates how to initialize an OpenDAL S3 operator and perform basic asynchronous operations: write, read, get metadata, and delete. Ensure your S3 bucket, region, and credentials are set as environment variables or provided directly in the configuration. For a simpler start, replace the config with `op = opendal.Operator(\"memory\")`.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}