{
  "openapi": "3.0.1",
  "info": {
    "title": "Python Code Runner - pip, pandas & Dataset In/Out",
    "description": "Run your Python main() on rows from a Dataset, JSON or n8n in one API call. pip packages from a requirements field, pandas and openpyxl preinstalled, encrypted secrets as environment variables, rows back with per-item status.",
    "version": "0.1",
    "x-build-id": "yAwsXkRKFtRfSzADw"
  },
  "servers": [
    {
      "url": "https://api.apify.com/v2"
    }
  ],
  "paths": {
    "/acts/automa-flow~python-code-runner/run-sync-get-dataset-items": {
      "post": {
        "operationId": "run-sync-get-dataset-items-automa-flow-python-code-runner",
        "x-openai-isConsequential": false,
        "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
        "tags": [
          "Run Actor"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/inputSchema"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Enter your Apify token here"
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/acts/automa-flow~python-code-runner/runs": {
      "post": {
        "operationId": "runs-sync-automa-flow-python-code-runner",
        "x-openai-isConsequential": false,
        "summary": "Executes an Actor and returns information about the initiated run in response.",
        "tags": [
          "Run Actor"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/inputSchema"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Enter your Apify token here"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/runsResponseSchema"
                }
              }
            }
          }
        }
      }
    },
    "/acts/automa-flow~python-code-runner/run-sync": {
      "post": {
        "operationId": "run-sync-automa-flow-python-code-runner",
        "x-openai-isConsequential": false,
        "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
        "tags": [
          "Run Actor"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/inputSchema"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Enter your Apify token here"
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "inputSchema": {
        "type": "object",
        "required": [
          "code"
        ],
        "properties": {
          "code": {
            "title": "Python code",
            "minLength": 1,
            "maxLength": 200000,
            "type": "string",
            "description": "Your Python 3.12 source. It must define main, sync or async: main(rows, ctx) in allItems mode, main(row, ctx) in eachItem mode. main may take fewer parameters. Return a dict, a list of dicts, a pandas DataFrame or None. Keep API keys out of the code: put them in Secrets."
          },
          "callMode": {
            "title": "Call mode",
            "enum": [
              "allItems",
              "eachItem"
            ],
            "type": "string",
            "description": "allItems calls main(rows, ctx) once with all input rows (Run Once for All Items). eachItem calls main(row, ctx) once per row, and one failing row does not stop the others (Run Once for Each Item).",
            "default": "allItems"
          },
          "rows": {
            "title": "Input rows",
            "maxItems": 10000,
            "type": "array",
            "description": "Up to 10,000 JSON objects passed to main, for example the items of the previous n8n or Make step. Use rows or a Dataset, not both. The sample rows are dropped when a Dataset is picked."
          },
          "datasetId": {
            "title": "Dataset ID",
            "pattern": "^[A-Za-z0-9][A-Za-z0-9_-]{2,127}$",
            "type": "string",
            "description": "Apify Dataset whose rows are passed to main instead of rows. The run gets read access to this Dataset only. In an integration, set it to {{resource.defaultDatasetId}}."
          },
          "datasetOffset": {
            "title": "Dataset offset",
            "minimum": 0,
            "type": "integer",
            "description": "First Dataset row to read (0-based). RUN_SUMMARY gives nextDatasetOffset when more rows remain.",
            "default": 0
          },
          "maxRows": {
            "title": "Max Dataset rows",
            "minimum": 1,
            "maximum": 100000,
            "type": "integer",
            "description": "How many Dataset rows to read in this run (1-100,000). Default 10,000.",
            "default": 10000
          },
          "fields": {
            "title": "Dataset fields to keep",
            "maxItems": 50,
            "type": "array",
            "description": "Optional top-level field names to read from each Dataset row (up to 50). Leave empty for whole rows; fewer fields use less memory.",
            "items": {
              "type": "string"
            }
          },
          "input": {
            "title": "Parameters (ctx.input)",
            "type": "object",
            "description": "Any JSON object your code reads as ctx.input, such as a threshold or a date. With no rows and no Dataset, main([], ctx) runs as a script.",
            "default": {}
          },
          "requirements": {
            "title": "pip requirements",
            "maxLength": 4000,
            "type": "string",
            "description": "Extra PyPI packages, one per line as in requirements.txt: a name with optional extras, version and marker, such as tabulate==0.9.0. Up to 30 lines. Wheels from PyPI only: options (-r, --index-url), URLs, git links and local paths are refused. pandas, numpy, openpyxl and more are already installed."
          },
          "secrets": {
            "title": "Secrets (environment variables)",
            "maxProperties": 20,
            "type": "object",
            "description": "Up to 20 values your code reads with os.environ, for example {\"API_KEY\": \"...\"}. Stored encrypted and removed from logs, status rows and RUN_SUMMARY. Keys use A-Z, 0-9 and _ and cannot start with APIFY_, ACTOR_, PYTHON, LD_, UV_ or PIP_."
          },
          "timeoutSeconds": {
            "title": "Code timeout (seconds)",
            "minimum": 1,
            "maximum": 900,
            "type": "integer",
            "description": "Wall time for starting Python and running main (all rows in eachItem mode), 1-900. A synchronous API call waits at most 300 s, so start longer jobs asynchronously.",
            "default": 60
          },
          "installTimeoutSeconds": {
            "title": "Install timeout (seconds)",
            "minimum": 10,
            "maximum": 300,
            "type": "integer",
            "description": "Wall time for installing the requirements, 10-300.",
            "default": 120
          },
          "maxOutputRows": {
            "title": "Max output rows",
            "minimum": 1,
            "maximum": 100000,
            "type": "integer",
            "description": "Rows written to the Dataset at most (1-100,000). Rows above it are dropped and counted, and the run ends OUTPUT_LIMIT.",
            "default": 10000
          },
          "maxRowBytes": {
            "title": "Max row size (bytes)",
            "minimum": 1024,
            "maximum": 4194304,
            "type": "integer",
            "description": "Largest returned row as JSON, 1,024 to 4,194,304 bytes. A larger row fails its unit with OUTPUT_INVALID.",
            "default": 1048576
          },
          "maxLogBytes": {
            "title": "Max logged output (bytes)",
            "minimum": 0,
            "maximum": 1048576,
            "type": "integer",
            "description": "How much of your code's print output (stdout and stderr) is logged, 0 to 1,048,576 bytes. Secret values are redacted.",
            "default": 262144
          },
          "logUserOutput": {
            "title": "Log print output",
            "type": "boolean",
            "description": "Write your code's print output to the run log (redacted and capped).",
            "default": true
          },
          "statusRows": {
            "title": "Status rows",
            "enum": [
              "failures",
              "all",
              "none"
            ],
            "type": "string",
            "description": "failures writes a _status row only for a failed or empty unit, all writes one per unit, none writes none (RUN_SUMMARY still has every count).",
            "default": "failures"
          },
          "failRunOnError": {
            "title": "Fail the run on a code error",
            "type": "boolean",
            "description": "When on, the run ends FAILED after storing rows and RUN_SUMMARY if the status is not SUCCESS or NO_ROWS, so an n8n or Make step stops on a code error.",
            "default": false
          },
          "maxInputBytes": {
            "title": "Max input size (bytes)",
            "minimum": 1048576,
            "maximum": 268435456,
            "type": "integer",
            "description": "Largest input passed to main, as JSON lines, 1 MiB to 256 MiB. A Dataset read stops at this size and RUN_SUMMARY gives the next offset.",
            "default": 67108864
          },
          "resource": {
            "title": "Integration resource",
            "type": "object",
            "description": "Present on some webhook bodies. A dataset id here is not read: set datasetId to {{resource.defaultDatasetId}}."
          },
          "payload": {
            "title": "Integration payload",
            "type": "object",
            "description": "Added by Actor-to-Actor integrations. A nested dataset id is not read: set datasetId to {{resource.defaultDatasetId}}."
          }
        }
      },
      "runsResponseSchema": {
        "type": "object",
        "properties": {
          "data": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "actId": {
                "type": "string"
              },
              "userId": {
                "type": "string"
              },
              "startedAt": {
                "type": "string",
                "format": "date-time",
                "example": "2025-01-08T00:00:00.000Z"
              },
              "finishedAt": {
                "type": "string",
                "format": "date-time",
                "example": "2025-01-08T00:00:00.000Z"
              },
              "status": {
                "type": "string",
                "example": "READY"
              },
              "meta": {
                "type": "object",
                "properties": {
                  "origin": {
                    "type": "string",
                    "example": "API"
                  },
                  "userAgent": {
                    "type": "string"
                  }
                }
              },
              "stats": {
                "type": "object",
                "properties": {
                  "inputBodyLen": {
                    "type": "integer",
                    "example": 2000
                  },
                  "rebootCount": {
                    "type": "integer",
                    "example": 0
                  },
                  "restartCount": {
                    "type": "integer",
                    "example": 0
                  },
                  "resurrectCount": {
                    "type": "integer",
                    "example": 0
                  },
                  "computeUnits": {
                    "type": "integer",
                    "example": 0
                  }
                }
              },
              "options": {
                "type": "object",
                "properties": {
                  "build": {
                    "type": "string",
                    "example": "latest"
                  },
                  "timeoutSecs": {
                    "type": "integer",
                    "example": 300
                  },
                  "memoryMbytes": {
                    "type": "integer",
                    "example": 1024
                  },
                  "diskMbytes": {
                    "type": "integer",
                    "example": 2048
                  }
                }
              },
              "buildId": {
                "type": "string"
              },
              "defaultKeyValueStoreId": {
                "type": "string"
              },
              "defaultDatasetId": {
                "type": "string"
              },
              "defaultRequestQueueId": {
                "type": "string"
              },
              "buildNumber": {
                "type": "string",
                "example": "1.0.0"
              },
              "containerUrl": {
                "type": "string"
              },
              "usage": {
                "type": "object",
                "properties": {
                  "ACTOR_COMPUTE_UNITS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_WRITES": {
                    "type": "integer",
                    "example": 1
                  },
                  "KEY_VALUE_STORE_LISTS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_INTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_EXTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_SERPS": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_UNBLOCKER_UNITS": {
                    "type": "integer",
                    "example": 0
                  }
                }
              },
              "usageTotalUsd": {
                "type": "number",
                "example": 0.00005
              },
              "usageUsd": {
                "type": "object",
                "properties": {
                  "ACTOR_COMPUTE_UNITS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_WRITES": {
                    "type": "number",
                    "example": 0.00005
                  },
                  "KEY_VALUE_STORE_LISTS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_INTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_EXTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_SERPS": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_UNBLOCKER_UNITS": {
                    "type": "integer",
                    "example": 0
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}