Python Script Runner: pip, Dataset Rows In & Out
Pricing
from $1.50 / 1,000 code runs
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
Maintained by CommunityActor stats
0
Bookmarked
2
Total users
1
Monthly active users
8 days ago
Last modified
Categories
Features
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_okand_error, or a plain script that callspush(). - 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 withos.environ.
How to use it
- Write your code in Code. Define
def main(input, rows):and return a list of dicts, a dict, or a pandas DataFrame. Or leave outmainand callpush(row)orpush(list_of_rows)yourself. - Put your data in Rows (a JSON array of objects), or choose a Dataset, or both. The
Input object is passed to
mainasinputfor settings such as thresholds or URLs. - Pick Call mode:
once,perRoworscript. - Add packages under Requirements, one PyPI specifier per line, such as
tabulateorrapidfuzz>=3. Only package names, extras and version clauses are accepted. - 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:
| Event | Price | Silver | Gold |
|---|---|---|---|
| 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}
| Field | What it does |
|---|---|
code | Your Python code (required). |
callMode | once, perRow or script. Default once. |
rows | JSON objects passed in as rows. |
datasetId | An Apify Dataset whose items are added after rows; datasetOffset skips the first ones. |
maxInputRows | Most rows read in total. Default 10,000. |
input | A JSON object passed to main as input. |
requirements | PyPI packages to install for this run. |
secrets | Encrypted environment variables, such as {"MY_API_KEY": "..."}. Their values are replaced by *** in logs and errors. |
timeoutSeconds | Time your code may run, up to 3,600 s. Default 120. |
installTimeoutSeconds | Time pip may take. Default 180. |
maxOutputRows | Most rows stored; the rest are counted as dropped. Default 10,000. |
maxLogKb | Most stdout and stderr kept, each, as head and tail. Default 256 KB. |
failRunOnError | Make 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. |
allowApifyApi | Pass 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,_okand_errorin 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
datasetOffsetin 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
onceorscriptmode that was interrupted runs again from the start;perRowmode 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
- Podcast & Audio Transcriber: podcasts, MP3s and videos to text with Whisper, with timed segments and subtitles.
- Video Frame Extractor: frames, scene changes and contact sheets from videos.
- ATS Job Postings: Workday, Greenhouse, Lever & Ashby: every open job of the companies you choose.
- Website Contact Scraper: emails, phones and social profiles from company websites.
- Email Validator & List Cleaner: syntax and domain checks for a mailing list.

