Model sync from MySQL to Snowflake
Set your Polytomic API key as an environment variable:
export POLYTOMIC_API_KEY=YOUR-API-TOKEN
This example covers three steps:
- Create a MySQL Connection.
- Create a model over a MySQL table.
- Create a sync to Snowflake.
1. Create a MySQL Connection
The following request creates a MySQL Connection. See the connection configuration reference for the required fields.
cURL
Python
Typescript
Go
curl --request POST \--url https://app.polytomic.com/api/connections \--header "accept: application/json" \--header "content-type: application/json" \--header "X-Polytomic-Version: 2025-09-18" \--header "Authorization: Bearer ${POLYTOMIC_API_KEY}" \-d '{"name": "MySQL Connection","type": "mysql","configuration": {"hostname": "localhost","port": 3306,"dbname": "company","account": "user","passwd": "secret"}}'
import osfrom polytomic.client import Polytomicclient = Polytomic(token=os.getenv("POLYTOMIC_API_KEY"),)resp = client.connections.create(name="MySQL Connection",type="mysql",configuration={"hostname": "localhost","port": 3306,"dbname": "company","account": "user","passwd": "secret"})print(resp.data)
import { PolytomicClient } from 'polytomic';const polytomic = new PolytomicClient({token: "POLYTOMIC_API_KEY",});polytomic.connections.create({name: "MySQL Connection",type: "mysql",configuration: {hostname: "localhost",port: 3306,dbname: "company",account: "user",passwd: "secret"},}).then((res) => {console.log(res)})
import ("context""fmt"polytomic "github.com/polytomic/polytomic-go"polytomicgoclient "github.com/polytomic/polytomic-go/client""github.com/polytomic/polytomic-go/option")client := polytomicgoclient.NewClient(option.WithToken(os.Getenv("POLYTOMIC_API_TOKEN")),)resp, err := client.Connections.Create(context.TODO(),&polytomic.CreateConnectionRequestSchema{Name: "MySQL Connection",Type: "mysql",Configuration: map[string]any{"hostname": "localhost","port": 3306,"dbname": "company","account": "user","passwd": "secret",},},)if err != nil {panic(err)}fmt.Println(resp)
2. Create a model
Next, create a model over the customers table on the MySQL Connection.
First, use the source endpoint to list the tables available on the Connection:
cURL
Python
Typescript
Go
curl --request GET \--url https://app.polytomic.com/api/connections/{YOUR-CONNECTION-ID}/modelsync/source \--header "content-type: application/json" \--header "X-Polytomic-Version: 2025-09-18" \--header "Authorization: Bearer ${POLYTOMIC_API_KEY}"
The response looks like:
{"data": {"items": {"query": {"items": null,"requires_one_of": null,"has_items": false},"table": {"items": ["company.accounts","company.customers","company.teams"],"requires_one_of": null,"has_items": true},"tracking_columns": {"items": null,"requires_one_of": null,"has_items": false},"view": {"items": null,"requires_one_of": null,"has_items": false}},"requires_one_of": ["query","table","view"]}}
import osfrom polytomic.client import Polytomicclient = Polytomic(token=os.getenv("POLYTOMIC_API_KEY"),)resp = client.model_sync.get_source(id="YOUR-CONNECTION-ID")print(resp.data)
import { PolytomicClient } from 'polytomic';const polytomic = new PolytomicClient({token: "POLYTOMIC_API_KEY",});polytomic.modelSync.getSource("YOUR-CONNECTION-ID").then((res) => {console.log(res)})
import ("context""fmt"polytomic "github.com/polytomic/polytomic-go"polytomicgoclient "github.com/polytomic/polytomic-go/client""github.com/polytomic/polytomic-go/option")client := polytomicgoclient.NewClient(option.WithToken(os.Getenv("POLYTOMIC_API_TOKEN")),)resp, err := client.ModelSync.GetSource(context.TODO(),"YOUR-CONNECTION-ID",&polytomic.ModelSyncGetSourceRequest{},)if err != nil {panic(err)}fmt.Println(resp)
Sources
Drill into each level with query parameters — for example, ?table=company.accounts. In this case, requires_one_of on table is null, so no further drill-down is needed.
Now create a model over company.customers:
cURL
Python
Typescript
Go
curl --request POST \--url https://app.polytomic.com/api/models \--header "accept: application/json" \--header "content-type: application/json" \--header "X-Polytomic-Version: 2025-09-18" \--header "Authorization: Bearer ${POLYTOMIC_API_KEY}" \-d '{"name": "Customer Model","configuration": {"table": "company.customers"},"connection_id": "YOUR-CONNECTION-ID"}'
import osfrom polytomic.client import Polytomicclient = Polytomic(token=os.getenv("POLYTOMIC_API_KEY"),)resp = client.models.create(name="Customer Model",configuration={"table": "company.customers"},connection_id="YOUR-CONNECTION-ID")print(resp.data)
import { PolytomicClient } from 'polytomic';const polytomic = new PolytomicClient({token: "POLYTOMIC_API_KEY",});polytomic.models.create({name: "Customer Model",configuration: {table: "company.customers"},connection_id: "YOUR-CONNECTION-ID"}).then((res) => {console.log(res)})
import ("context""fmt"polytomic "github.com/polytomic/polytomic-go"polytomicgoclient "github.com/polytomic/polytomic-go/client""github.com/polytomic/polytomic-go/option")client := polytomicgoclient.NewClient(option.WithToken(os.Getenv("POLYTOMIC_API_TOKEN")),)resp, err := client.Models.Create(context.TODO(),&polytomic.CreateModelRequest{Name: "Customer Model",Configuration: map[string]any{"table": "company.customers",},ConnectionID: "YOUR-CONNECTION-ID",},)if err != nil {panic(err)}fmt.Println(resp)
Replace YOUR-CONNECTION-ID with the Connection ID returned in Step 1.
3. Create a sync
Next, create a sync from the customer model to a new Snowflake target.
Create a target Connection
Create a Snowflake Connection to use as the sync target:
cURL
Python
Typescript
Go
curl --request POST \--url https://app.polytomic.com/api/connections \--header "accept: application/json" \--header "content-type: application/json" \--header "X-Polytomic-Version: 2025-09-18" \--header "Authorization: Bearer ${POLYTOMIC_API_KEY}" \-d '{"name": "Snowflake Connection","type": "snowflake","configuration": {"account": "account","dbname": "database","password": "secret-password","username": "user"}}'
import osfrom polytomic.client import Polytomicclient = Polytomic(token=os.getenv("POLYTOMIC_API_KEY"),)resp = client.connections.create(name="Snowflake Connection",type="snowflake",configuration={"account": "account","dbname": "database","password": "secret-password","username": "user"})print(resp.data)
import { PolytomicClient } from 'polytomic';const polytomic = new PolytomicClient({token: "POLYTOMIC_API_KEY",});polytomic.connections.create({name: "Snowflake Connection",type: "snowflake",configuration: {account: "account",dbname: "database",password: "secret-password",username: "user"},}).then((res) => {console.log(res)})
import ("context""fmt"polytomic "github.com/polytomic/polytomic-go"polytomicgoclient "github.com/polytomic/polytomic-go/client""github.com/polytomic/polytomic-go/option")client := polytomicgoclient.NewClient(option.WithToken(os.Getenv("POLYTOMIC_API_TOKEN")),)resp, err := client.Connections.Create(context.TODO(),&polytomic.CreateConnectionRequestSchema{Name: "Snowflake Connection",Type: "snowflake",Configuration: map[string]any{"account": "account","username": "user","password": "secret-password","dbname": "database",},},)if err != nil {panic(err)}fmt.Println(resp)
Enumerate the target
Targets enumerate the same way sources do:
cURL
Python
Typescript
Go
curl --request GET \--url https://app.polytomic.com/api/connections/YOUR-CONNECTION-ID/modelsync/target \--header "accept: application/json" \--header "content-type: application/json" \--header "X-Polytomic-Version: 2025-09-18" \--header "Authorization: Bearer ${POLYTOMIC_API_KEY}"
The response looks like:
{"data": {"items": {"schema": {"items": null,"requires_one_of": ["table","view"],"has_items": false},"table": {"items": null,"requires_one_of": null,"has_items": false},"view": {"items": null,"requires_one_of": null,"has_items": false}},"requires_one_of": ["schema"]}}
import osfrom polytomic.client import Polytomicclient = Polytomic(token=os.getenv("POLYTOMIC_API_KEY"),)resp = client.model_sync.get_target(id="YOUR-CONNECTION-ID")print(resp.data)
import { PolytomicClient } from 'polytomic';const polytomic = new PolytomicClient({token: "POLYTOMIC_API_KEY",});polytomic.modelSync.getTarget("YOUR-CONNECTION-ID").then((res) => {console.log(res)})
import ("context""fmt"polytomic "github.com/polytomic/polytomic-go"polytomicgoclient "github.com/polytomic/polytomic-go/client""github.com/polytomic/polytomic-go/option")client := polytomicgoclient.NewClient(option.WithToken(os.Getenv("POLYTOMIC_API_TOKEN")),)resp, err := client.ModelSync.GetTarget(context.TODO(),"YOUR-CONNECTION-ID",&polytomic.ModelSyncGetTargetRequest{},)if err != nil {panic(err)}fmt.Println(resp)
Drill down recursively using the requires_one_of field. For example:
cURL
Python
Typescript
Go
curl --request GET \--url https://app.polytomic.com/api/connections/YOUR-CONNECTION-ID/modelsync/target?type=schema \--header "accept: application/json" \--header "content-type: application/json" \--header "X-Polytomic-Version: 2025-09-18" \--header "Authorization: Bearer ${POLYTOMIC_API_KEY}"
The response looks like:
{"data": {"items": {"schema": {"items": ["__pt_new_schema","CUSTOMERS","TEAMS"],"requires_one_of": ["table"],"has_items": true},"table": {"items": null,"requires_one_of": null,"has_items": false}},"requires_one_of": ["schema"]}}
import osfrom polytomic.client import Polytomicclient = Polytomic(token=os.getenv("POLYTOMIC_API_KEY"),)resp = client.model_sync.get_target(id="YOUR-CONNECTION-ID",type="schema")print(resp.data)
import { PolytomicClient } from 'polytomic';const polytomic = new PolytomicClient({token: "POLYTOMIC_API_KEY",});polytomic.modelSync.getTarget("YOUR-CONNECTION-ID", {type: "schema"}).then((res) => {console.log(res)})
import ("context""fmt"polytomic "github.com/polytomic/polytomic-go"polytomicgoclient "github.com/polytomic/polytomic-go/client""github.com/polytomic/polytomic-go/option")client := polytomicgoclient.NewClient(option.WithToken(os.Getenv("POLYTOMIC_API_TOKEN")),)resp, err := client.ModelSync.GetTarget(context.TODO(),"YOUR-CONNECTION-ID",&polytomic.ModelSyncGetTargetRequest{Type: polytomic.String("schema"),},)if err != nil {panic(err)}fmt.Println(resp)
The schema level requires a table. Enumerate tables by adding another query parameter:
cURL
Python
Typescript
Go
curl --request GET \--url https://app.polytomic.com/api/connections/YOUR-CONNECTION-ID/modelsync/target?type=table&search=CUSTOMERS \--header "accept: application/json" \--header "content-type: application/json" \--header "X-Polytomic-Version: 2025-09-18" \--header "Authorization: Bearer ${POLYTOMIC_API_KEY}"
The response looks like:
{"data": {"items": {"schema": {"items": null,"requires_one_of": ["table"],"has_items": false},"table": {"items": ["__pt_new_target","CUSTOMERS.COMPANIES","CUSTOMERS.CONTACTS"],"requires_one_of": null,"has_items": true}},"requires_one_of": ["schema"]}}
import osfrom polytomic.client import Polytomicclient = Polytomic(token=os.getenv("POLYTOMIC_API_KEY"),)resp = client.model_sync.get_target(id="YOUR-CONNECTION-ID",type="table",search="CUSTOMERS")print(resp.data)
import { PolytomicClient } from 'polytomic';const polytomic = new PolytomicClient({token: "POLYTOMIC_API_KEY",});polytomic.modelSync.getTarget("YOUR-CONNECTION-ID", {type: "table", search: "CUSTOMERS"}).then((res) => {console.log(res)})
import ("context""fmt"polytomic "github.com/polytomic/polytomic-go"polytomicgoclient "github.com/polytomic/polytomic-go/client""github.com/polytomic/polytomic-go/option")client := polytomicgoclient.NewClient(option.WithToken(os.Getenv("POLYTOMIC_API_TOKEN")),)resp, err := client.ModelSync.GetTarget(context.TODO(),"YOUR-CONNECTION-ID",&polytomic.ModelSyncGetTargetRequest{Type: polytomic.String("table"),Search: polytomic.String("CUSTOMERS"),},)if err != nil {panic(err)}fmt.Println(resp)
Query target fields
Finally, query the available fields on the target. POST to the fields endpoint for the target resource:
cURL
Python
Typescript
Go
curl --request POST \--url https://app.polytomic.com/api/connections/YOUR-CONNECTION-ID/modelsync/target/fields \--header 'X-Polytomic-Version: 2025-09-18' \--header "Authorization: Bearer ${POLYTOMIC_API_KEY}" \--header 'content-type: application/json' \-d '{"target": "CUSTOMERS.CONTACTS"}'
The response lists the available sync modes and every field on the target along with its metadata. For example:
{"data": {"id": "CUSTOMERS.CONTACTS","name": "CUSTOMERS.CONTACTS","modes": [{"mode": "create","description": "Create records when they don’t exist; don’t update existing ones","label": "Create","requires_identity": true,"supports_target_filters": false,"supports_field_sync_mode": false},{"mode": "update","description": "Update existing records only; don’t create new ones","label": "Update","requires_identity": true,"supports_target_filters": false,"supports_field_sync_mode": false},{"mode": "updateOrCreate","description": "Update records when they exist and create them when they don’t","label": "Update or Create","requires_identity": true,"supports_target_filters": false,"supports_field_sync_mode": false},{"mode": "replace","description": "Replace all existing rows","label": "Replace","requires_identity": false,"supports_target_filters": false,"supports_field_sync_mode": false},{"mode": "append","description": "Append rows to the end of the table","label": "Append","requires_identity": false,"supports_target_filters": false,"supports_field_sync_mode": false}],"properties": {"supports_field_creation": true},"refreshed_at": "0001-01-01T00:00:00Z","fields": [{"id": "EMAIL","name": "EMAIL","description": "","required": false,"filterable": false,"createable": true,"updateable": true,"association": false,"supports_identity": true,"identity_functions": [{"id": "Equality","label": "Equality"}],"source_type": "VARCHAR(16777216)","type": "string"},{"id": "FIRST_NAME","name": "FIRST_NAME","description": "","required": false,"filterable": false,"createable": true,"updateable": true,"association": false,"supports_identity": true,"identity_functions": [{"id": "Equality","label": "Equality"}],"source_type": "VARCHAR(16777216)","type": "string"},{"id": "LAST_NAME","name": "LAST_NAME","description": "","required": false,"filterable": false,"createable": true,"updateable": true,"association": false,"supports_identity": true,"identity_functions": [{"id": "Equality","label": "Equality"}],"source_type": "VARCHAR(16777216)","type": "string"}]}}
import osfrom polytomic.client import Polytomicclient = Polytomic(token=os.getenv("POLYTOMIC_API_KEY"),)resp = client.model_sync.get_target_fields(id="YOUR-CONNECTION-ID",target="CUSTOMERS.CONTACTS")print(resp.data)
import { PolytomicClient } from 'polytomic';const polytomic = new PolytomicClient({token: "POLYTOMIC_API_KEY",});polytomic.modelSync.getTargetFields("YOUR-CONNECTION-ID", {target: "CUSTOMERS.CONTACTS"}).then((res) => {console.log(res)})
import ("context""fmt"polytomic "github.com/polytomic/polytomic-go"polytomicgoclient "github.com/polytomic/polytomic-go/client""github.com/polytomic/polytomic-go/option")client := polytomicgoclient.NewClient(option.WithToken(os.Getenv("POLYTOMIC_API_TOKEN")),)resp, err := client.ModelSync.GetTargetFields(context.TODO(),"YOUR-CONNECTION-ID",&polytomic.ModelSyncGetTargetFieldsRequest{Target: "CUSTOMERS.CONTACTS",},)if err != nil {panic(err)}fmt.Println(resp)
Create the sync
Map fields from the source model to the target and create the sync:
cURL
Python
Typescript
Go
curl --request POST \--url https://app.polytomic.com/api/syncs \--header 'X-Polytomic-Version: 2025-09-18' \--header "Authorization: Bearer ${POLYTOMIC_API_KEY}" \--header 'content-type: application/json' \--data '{"name": "MySQL to Snowflake Sync","mode": "replace","fields": [{"source": {"field": "email","model_id": "YOUR-SOURCE-MODEL-ID"},"target": "EMAIL"},{"source": {"field": "first_name","model_id": "YOUR-SOURCE-MODEL-ID"},"target": "FIRST_NAME"},{"source": {"field": "last_name","model_id": "YOUR-SOURCE-MODEL-ID"},"target": "LAST_NAME"}],"schedule": {"frequency": "continuous"},"target": {"connection_id": "YOUR-TARGET-CONNECTION-ID","object": "CUSTOMERS.CONTACTS"}}'
import osfrom polytomic.client import Polytomicfrom polytomic import Identity, SyncField, Schedule, Source, Target, ScheduleFrequencyclient = Polytomic(token=os.getenv("POLYTOMIC_API_KEY"),)resp = client.model_sync.create(name="MySQL to Snowflake Sync",mode="replace",identity=Identity(source=Source(field= "email",model_id= "YOUR-SOURCE-MODEL-ID"),target="Email",),fields=[SyncField(source=Source(field="first_name",model_id="YOUR-SOURCE-MODEL-ID"),target="FirstName",),SyncField(source=Source(field="last_name",model_id="YOUR-SOURCE-MODEL-ID"),target="LastName",),],schedule=Schedule(frequency=ScheduleFrequency.CONTINUOUS,),target=Target(connection_id="YOUR-TARGET-CONNECTION-ID",object="CUSTOMERS.CONTACTS"))print(resp.data)
import { Polytomic, PolytomicClient } from 'polytomic';const polytomic = new PolytomicClient({token: "POLYTOMIC_API_KEY",});polytomic.modelSync.create({name: "MySQL to Snowflake Sync",mode: Polytomic.ModelsyncSyncTargetMode.Replace,identity: {source: {field: "email",model_id: "YOUR-MODEL-ID"},target: "Email",function: Polytomic.SchemaIdentityFunction.Equality},fields: [{source: {field: "first_name",model_id: "YOUR-MODEL-ID"},target: "FirstName"},{source: {field: "last_name",model_id: "YOUR-MODEL-ID"},target: "LastName"}],schedule: {frequency: Polytomic.ScheduleFrequency.Continuous},target: {connection_id: "YOUR-TARGET-CONNECTION-ID",object: "CUSTOMERS.CONTACTS"}}).then((resp) => {console.log(resp);})
import ("context""fmt"polytomic "github.com/polytomic/polytomic-go"polytomicgoclient "github.com/polytomic/polytomic-go/client""github.com/polytomic/polytomic-go/option")client := polytomicgoclient.NewClient(option.WithToken(os.Getenv("POLYTOMIC_API_TOKEN")),)object := "CUSTOMERS.CONTACTS"resp, err := client.ModelSync.Create(context.TODO(),&polytomic.CreateSyncRequest{Name: "MySQL to Snowflake Sync",Mode: polytomic.ModelsyncSyncTargetModeReplace,Identity: &polytomic.Identity{Source: &polytomic.Source{Field: "email",ModelID: "YOUR-MODEL-ID",},Target: "Email",Function: polytomic.SchemaIdentityFunctionEquality,},Fields: []*polytomic.SyncField{{Source: &polytomic.Source{Field: "first_name",ModelID: "YOUR-MODEL-ID",},Target: "FirstName",},{Source: &polytomic.Source{Field: "last_name",ModelID: "YOUR-MODEL-ID",},Target: "LastName",},},Schedule: &polytomic.Schedule{Frequency: polytomic.ScheduleFrequencyContinuous.Ptr(),},Target: &polytomic.Target{ConnectionID: "YOUR-TARGET-CONNECTION-ID",Object: &object,},},)if err != nil {panic(err)}fmt.Println(resp)
