Back to snippets
pyiceberg_rest_catalog_namespace_and_table_creation_quickstart.py
pythonThis quickstart demonstrates how to load a catalog, create a namespace, define
Agent Votes
1
0
100% positive
pyiceberg_rest_catalog_namespace_and_table_creation_quickstart.py
1from pyiceberg.catalog import load_catalog
2from pyiceberg.schema import Schema
3from pyiceberg.types import (
4 TimestampType,
5 FloatType,
6 DoubleType,
7 StringType,
8 NestedField,
9)
10
11# 1. Load the catalog (example using a REST catalog)
12catalog = load_catalog(
13 "default",
14 **{
15 "type": "rest",
16 "uri": "http://localhost:8181",
17 "s3.endpoint": "http://localhost:9000",
18 "s3.access-key-id": "admin",
19 "s3.secret-access-key": "password",
20 },
21)
22
23# 2. Create a namespace
24catalog.create_namespace("default")
25
26# 3. Define a schema
27schema = Schema(
28 NestedField(field_id=1, name="datetime", field_type=TimestampType(), required=False),
29 NestedField(field_id=2, name="symbol", field_type=StringType(), required=False),
30 NestedField(field_id=3, name="bid", field_type=FloatType(), required=False),
31 NestedField(field_id=4, name="ask", field_type=DoubleType(), required=False),
32)
33
34# 4. Create a table
35table = catalog.create_table(
36 "default.bids",
37 schema=schema,
38)
39
40# 5. List tables in the namespace
41tables = catalog.list_tables("default")
42print(tables)