PyIceberg
Below is an example of using PyIceberg ↗ to connect to R2 Data Catalog.
- Sign up for a Cloudflare account ↗.
- Create an R2 bucket and enable the data catalog.
- Create an R2 API token with both R2 and data catalog permissions.
- Install the PyIceberg ↗ and PyArrow ↗ libraries.
import pyarrow as pafrom pyiceberg.catalog.rest import RestCatalogfrom pyiceberg.exceptions import NamespaceAlreadyExistsError
# Define catalog connection details (replace variables)WAREHOUSE = "<WAREHOUSE>"TOKEN = "<TOKEN>"CATALOG_URI = "<CATALOG_URI>"
# Connect to R2 Data Catalogcatalog = RestCatalog( name="my_catalog", warehouse=WAREHOUSE, uri=CATALOG_URI, token=TOKEN,)
# Create default namespacecatalog.create_namespace("default")
# Create simple PyArrow tabledf = pa.table({ "id": [1, 2, 3], "name": ["Alice", "Bob", "Charlie"],})
# Create an Iceberg tabletest_table = ("default", "my_table")table = catalog.create_table( test_table, schema=df.schema,)
Was this helpful?
- Resources
- API
- New to Cloudflare?
- Products
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark