import { useParams } from 'common' import { Eye, EyeOff } from 'lucide-react' import { useMemo, useState } from 'react' import { Accordion, AccordionContent, AccordionItem, AccordionTrigger, Card, CardFooter, CardHeader, CardTitle, } from 'ui' import { CodeBlock } from 'ui-patterns/CodeBlock' import { useAnalyticsBucketWrapperInstance } from '../useAnalyticsBucketWrapperInstance' import { getPyicebergSnippet } from './CreateTableInstructions.constants' import CommandRender from '@/components/interfaces/Functions/CommandRender' import { convertKVStringArrayToJson } from '@/components/interfaces/Integrations/Wrappers/Wrappers.utils' import { ButtonTooltip } from '@/components/ui/ButtonTooltip' import CopyButton from '@/components/ui/CopyButton' import { InlineLink } from '@/components/ui/InlineLink' import { useProjectSettingsV2Query } from '@/data/config/project-settings-v2-query' import { getDecryptedValues, useVaultSecretDecryptedValueQuery, } from '@/data/vault/vault-secret-decrypted-value-query' import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject' import { DOCS_URL } from '@/lib/constants' export const CreateTableInstructions = ({ hideHeader = false, className, }: { hideHeader?: boolean className?: string }) => { const { ref, bucketId } = useParams() const { data: project } = useSelectedProjectQuery() const [showKeys, setShowKeys] = useState(false) const [isFetchingSecretsOnCopy, setIsFetchingSecretsOnCopy] = useState(false) const { data: projectSettings } = useProjectSettingsV2Query({ projectRef: ref }) const { data: wrapperInstance } = useAnalyticsBucketWrapperInstance({ bucketId }) const wrapperValues = convertKVStringArrayToJson(wrapperInstance?.server_options ?? []) const s3AccessKeyVaultID = wrapperValues.vault_aws_access_key_id const s3SecretKeyVaultID = wrapperValues.vault_aws_secret_access_key const tokenVaultID = wrapperValues.vault_token const { data: decryptedS3AccessKey, isPending: isDecryptingS3AccessKey } = useVaultSecretDecryptedValueQuery( { projectRef: project?.ref, connectionString: project?.connectionString, id: s3AccessKeyVaultID, }, { enabled: showKeys } ) const { data: decryptedS3SecretKey, isPending: isDecryptingS3SecretKey } = useVaultSecretDecryptedValueQuery( { projectRef: project?.ref, connectionString: project?.connectionString, id: s3SecretKeyVaultID, }, { enabled: showKeys } ) const { data: decryptedToken, isPending: isDecryptingToken } = useVaultSecretDecryptedValueQuery( { projectRef: project?.ref, connectionString: project?.connectionString, id: tokenVaultID, }, { enabled: showKeys } ) const isFetchingSecretValues = showKeys && (isDecryptingS3AccessKey || isDecryptingS3SecretKey || isDecryptingToken) const snippetContent = useMemo( () => getPyicebergSnippet({ ref, warehouse: wrapperValues.warehouse, catalogUri: wrapperValues.catalog_uri, s3Endpoint: wrapperValues['s3.endpoint'], s3Region: projectSettings?.region, s3AccessKey: showKeys ? decryptedS3AccessKey : undefined, s3SecretKey: showKeys ? decryptedS3SecretKey : undefined, token: showKeys ? decryptedToken : undefined, }), [ decryptedS3AccessKey, decryptedS3SecretKey, decryptedToken, projectSettings?.region, ref, showKeys, wrapperValues, ] ) return ( {!hideHeader && ( Create your first table via Pyiceberg )}
1

Set up Python project with uv

'curl -LsSf https://astral.sh/uv/install.sh | sh', }, { comment: '2. Initialize a new Python project with uv', command: 'uv init ', jsx: () => 'uv init ', }, { comment: '3. Install required packages', command: 'uv add pyiceberg pyarrow pandas', jsx: () => 'uv add pyiceberg pyarrow pandas', }, ]} />
2

Replace main.py with the following snippet

The following snippet creates a namespace default, then creates a sample table events into that namespace.

{ if (!!decryptedS3AccessKey && !!decryptedS3SecretKey && !!decryptedToken) { return getPyicebergSnippet({ ref, warehouse: wrapperValues.warehouse, catalogUri: wrapperValues.catalog_uri, s3Endpoint: wrapperValues['s3.endpoint'], s3Region: projectSettings?.region, s3AccessKey: decryptedS3AccessKey, s3SecretKey: decryptedS3SecretKey, token: decryptedToken, }) } else { setIsFetchingSecretsOnCopy(true) const decryptedSecrets = await getDecryptedValues({ projectRef: project?.ref, connectionString: project?.connectionString, ids: [s3AccessKeyVaultID, s3SecretKeyVaultID, tokenVaultID], }) setIsFetchingSecretsOnCopy(false) return getPyicebergSnippet({ ref, warehouse: wrapperValues.warehouse, catalogUri: wrapperValues.catalog_uri, s3Endpoint: wrapperValues['s3.endpoint'], s3Region: projectSettings?.region, s3AccessKey: decryptedSecrets[s3AccessKeyVaultID], s3SecretKey: decryptedSecrets[s3SecretKeyVaultID], token: decryptedSecrets[tokenVaultID], }) } }} /> setShowKeys(!showKeys)} icon={showKeys ? : } tooltip={{ content: { side: 'bottom', text: showKeys ? 'Hide keys' : isFetchingSecretValues ? 'Retrieving keys' : 'Reveal keys', }, }} />
3

Run the Python script

'uv run main.py', }, ]} />

Connecting to bucket with other Iceberg clients? Read more in our{' '} documentation .

) }