Python Script Runner: pip, Dataset Rows In & Out avatar

Python Script Runner: pip, Dataset Rows In & Out

Pricing

from $1.50 / 1,000 code runs

Go to Apify Store
Python Script Runner: pip, Dataset Rows In & Out

Python Script Runner: pip, Dataset Rows In & Out

Run your own Python code on Apify with pip packages. Send JSON or Dataset rows in, get rows out in a Dataset plus logs and errors. Callable from the API, n8n, Make, Zapier or AI agents.

Pricing

from $1.50 / 1,000 code runs

Rating

0.0

(0)

Developer

Enis Bodlli

Enis Bodlli

Maintained by Community

Actor stats

0

Bookmarked

2

Total users

1

Monthly active users

8 days ago

Last modified

Features

Limited permissions

Share

Run your own Python code on Apify, with any pip packages you list. Send JSON rows or an Apify Dataset in, and get rows out in a Dataset, with the logs, the error and its traceback in one OUTPUT record. Call it from the Apify API, n8n, Make, Zapier or an AI agent whenever a workflow needs a few lines of Python: clean a scraper's output, compute a field, reshape JSON, call an API with your key, or build an Excel file with pandas.

  • Three ways to call your code. main(input, rows) once for the whole batch, main(row, input) for each row with a per-row _ok and _error, or a plain script that calls push().
  • pandas, numpy, requests, httpx, BeautifulSoup, lxml, openpyxl, dateutil and PyYAML preinstalled, and anything else from PyPI through requirements.
  • $2 per 1,000 code runs ($1.50 on Gold), with 20 GB-seconds of compute and 100 output rows included in each run. Input that is refused costs nothing.

The easiest way to try it: keep the example input and press Start. The example code marks which of three products cost more than the median, and you get three rows in about 4 seconds.

What you get

Each value your code returns or passes to push() becomes one Dataset row, with your own fields:

[
{ "item": "apple", "price": 1.2, "aboveMedian": false },
{ "item": "bread", "price": 2.5, "aboveMedian": false },
{ "item": "cheese", "price": 6.9, "aboveMedian": true }
]

In per-row mode each row also says whether that row worked:

[
{ "double": 4, "_index": 0, "_ok": true },
{ "_ok": false, "_error": "KeyError: 'value'", "_index": 1 },
{ "double": 8, "_index": 2, "_ok": true }
]

The run's key-value store holds OUTPUT: the status, stdout and stderr, the error type, message and traceback, timings, the Python version, the packages installed and the row counts.

What you can do with it

  • Post-process another Actor's results: pass its Dataset ID, transform or filter the rows in pandas, and get a clean Dataset back.
  • Add a Python step to n8n, Make or Zapier without hosting a server.
  • Give an AI agent a Python tool through the Apify MCP server: it sends code and rows and reads back structured rows and errors.
  • Call an API with your own key: put the key in secrets, read it with os.environ.

How to use it

  1. Write your code in Code. Define def main(input, rows): and return a list of dicts, a dict, or a pandas DataFrame. Or leave out main and call push(row) or push(list_of_rows) yourself.
  2. Put your data in Rows (a JSON array of objects), or choose a Dataset, or both. The Input object is passed to main as input for settings such as thresholds or URLs.
  3. Pick Call mode: once, perRow or script.
  4. Add packages under Requirements, one PyPI specifier per line, such as tabulate or rapidfuzz>=3. Only package names, extras and version clauses are accepted.
  5. Press Start, or call the Actor through the API and read the default Dataset.

In every mode the names push, INPUT and ROWS exist in your code's globals.

How long it takes

The example finishes in about 4 seconds on Apify. Installing a small package such as tabulate adds 2 to 3 seconds; large packages add more and count towards the compute in the run.

Pricing

Pay per event, with Bronze, Silver and Gold discounts:

EventPriceSilverGold
Code run (includes 20 GB-seconds and 100 rows)$0.002$0.00176$0.0015
Extra GB-minute, each one started past the included 20 GB-seconds$0.01$0.0088$0.0075
100 extra output rows, each block started past the first 100$0.002$0.00176$0.0015
Actor start (Apify's standard event, per GB of memory)$0.00005

A GB-second is memory in GB times seconds: at the default 512 MB, a 40-second run is included.

Worked examples at the regular price:

  • 1,000 runs like the example (a few seconds, under 100 rows each) cost $2.05.
  • One run that cleans 5,000 rows in 10 seconds costs $0.002 + 49 x $0.002 = $0.10.
  • One 3-minute pandas job at 2 GB is 360 GB-seconds: $0.002 + 6 x $0.01 = $0.062.

Your maximum charge per run is respected: once it is reached, the code is stopped, the rows already stored stay, and OUTPUT says charge-limit. A run whose code raises an error still costs the code run and the compute it used, because the code did run.

Input

{
"code": "def main(input, rows):\n import pandas as pd\n df = pd.DataFrame(rows)\n df['total'] = df['price'] * input['qty']\n return df",
"callMode": "once",
"rows": [{ "item": "apple", "price": 1.2 }, { "item": "bread", "price": 2.5 }],
"input": { "qty": 3 },
"requirements": [],
"timeoutSeconds": 120
}
FieldWhat it does
codeYour Python code (required).
callModeonce, perRow or script. Default once.
rowsJSON objects passed in as rows.
datasetIdAn Apify Dataset whose items are added after rows; datasetOffset skips the first ones.
maxInputRowsMost rows read in total. Default 10,000.
inputA JSON object passed to main as input.
requirementsPyPI packages to install for this run.
secretsEncrypted environment variables, such as {"MY_API_KEY": "..."}. Their values are replaced by *** in logs and errors.
timeoutSecondsTime your code may run, up to 3,600 s. Default 120.
installTimeoutSecondsTime pip may take. Default 180.
maxOutputRowsMost rows stored; the rest are counted as dropped. Default 10,000.
maxLogKbMost stdout and stderr kept, each, as head and tail. Default 256 KB.
failRunOnErrorMake the run fail when your code or the install fails. Default off: the run succeeds and OUTPUT holds the error, which suits workflows that branch on it.
allowApifyApiPass this run's Apify token to your code, for example to call other Actors. Default off.

Output

  • Default Dataset: your rows, nothing added except _index, _ok and _error in per-row mode.
  • OUTPUT in the default key-value store:
{
"status": "ok",
"callMode": "once",
"rowsIn": 3,
"rowsOut": 3,
"rowsDropped": 0,
"perRowErrors": 0,
"durationMs": 62,
"installMs": 0,
"packagesInstalled": [],
"python": "3.11.2",
"stdout": "",
"stderr": "",
"error": null
}

status is one of ok, code-error, install-failed, timeout, charge-limit, output-too-large or aborted.

Limits

  • Python 3.11 on Debian. Packages that need system libraries not in the image may fail to install.
  • Values that are not JSON become text; NaN and infinity become null. One row may be at most 9 MB (Apify's Dataset limit), and the stored output at most 200 MB per run.
  • Rows are held in memory: for very large inputs raise the memory or use datasetOffset in batches.
  • Your code runs in its own process inside this Actor's container. The Apify token is not in its environment unless you turn on allowApifyApi, but the container is not a security sandbox against your own code; run only code you trust.
  • Network access is open, so your code can call APIs. What it fetches, and what you do with the data, is your responsibility under the sites' terms and the law.
  • A run that is restarted keeps the rows already stored and is not charged twice for them. Code in once or script mode that was interrupted runs again from the start; perRow mode continues from the next row.

FAQ

Is it safe to put API keys in the input?

Use the secrets field: Apify stores it encrypted, and the Actor replaces each secret value with *** in stdout, stderr and error messages. Do not print keys in a changed form (for example base64), because only the exact values are masked.

Why did my run succeed when my code raised an error?

By default the error goes into OUTPUT so a workflow can read it and decide. Turn on failRunOnError to make the run fail instead.

Which packages are already installed?

pandas, numpy, requests, httpx, beautifulsoup4, lxml, openpyxl, python-dateutil and PyYAML. Listing them again in requirements is not needed.

Can I return a pandas DataFrame?

Yes. A DataFrame returned from main or passed to push() becomes one row per record.

Can an AI agent use it?

Yes. Through the Apify MCP server or the API, an agent sends code and rows and reads the Dataset and OUTPUT, which carry structured errors instead of a free-text log.

Can I run it on a schedule or from n8n, Make or Zapier?

Yes. Any Apify integration can start it with JSON input and read the Dataset when the run finishes.

More Actors from this developer