1from apify_client import ApifyClient
2
3
4
5client = ApifyClient("<YOUR_API_TOKEN>")
6
7
8run_input = {
9 "tables": [
10 {
11 "name": "accounts",
12 "csv": """id,name\r
1301,Ada\r
1401,Duplicate\r
1502,Lin\r
16""",
17 "primaryKey": ["id"],
18 "requiredColumns": ["name"],
19 },
20 {
21 "name": "orders",
22 "csv": """id,account_id,note
2310,01,child of duplicate
2411,99,orphan
2512,02,\"accepted, link\"
2613,02,\"multi
27line\"
28""",
29 "primaryKey": ["id"],
30 "requiredColumns": ["note"],
31 },
32 {
33 "name": "items",
34 "csv": """id,order_id,amount
35100,10,-12.5
36101,12,007
37102,11,3
38""",
39 "primaryKey": ["id"],
40 "requiredColumns": ["amount"],
41 },
42 ],
43 "foreignKeys": [
44 {
45 "table": "orders",
46 "columns": ["account_id"],
47 "referencesTable": "accounts",
48 "referencesColumns": ["id"],
49 "nullable": False,
50 },
51 {
52 "table": "items",
53 "columns": ["order_id"],
54 "referencesTable": "orders",
55 "referencesColumns": ["id"],
56 "nullable": False,
57 },
58 ],
59}
60
61
62run = client.actor("bread-kim/csv-foreign-key-import-gate").call(run_input=run_input)
63
64
65print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
66for item in client.dataset(run.default_dataset_id).iterate_items():
67 print(item)
68
69