Apify command line client (apify-cli)
Apify command line client (CLI) helps you to create, develop, build and run Apify Actor acts from a local computer.
Apify Actor is a serverless computing platform that enables the execution of arbitrary web scraping and automation jobs in the cloud. A single job is called an act.
While you can develop acts in a code editor directly in the Apify web application, for more complex projects it is more convenient to develop the acts locally and only push them to the Apify cloud for execution. This is where the CLI comes in.
Note that the acts running on the Apify platform are executed in Docker containers, so with an appropriate
you can build your acts in any programming language.
First, make sure you have Node.js version 7.10 or higher installed on your computer:
Install Apify CLI by running:
npm -g install apify-cli
Finally, you can test that the CLI was installed correctly:
The following examples show basic usage of the CLI.
Create a new act from scratch
apify create my-hello-world
First, you will be prompted to select a template with the boilerplate for the act, to help you get started quickly.
The command will create a directory called
my-hello-world that contains a Node.js project
for the act and a few configuration files.
Create a new act from existing project
cd ./my/awesome/projectapify init
This command will only set up local act development environment in an existing directory,
i.e. it will create the
apify.json file and
Run the act locally
cd my-hello-worldapify run
This command runs the act on your local machine. Now's your chance to develop the logic - or magic 😏
Login with your Apify account
Before you can interact with the Apify cloud, you need to create an Apify account
and log in to it using the above command. You will be prompted for
your Apify API token.
Note that the command will store the API token and other sensitive information to
Push the act to the Apify cloud
This command creates a ZIP archive with your project, uploads it to the Apify cloud and builds an act from it.
Run an act on the Apify cloud
Runs the act corresponding to the current directory on the Apify platform.
This command can also be used to run other acts, for example:
apify call apify/hello-world
So what's in this
This file associates your local development project with an act on the Apify platform. It contains information such as act name or ID, version and build tag. Make sure you commit this file to the Git repository.
To see all CLI commands simply run:
To get information about a specific command run:
apify help COMMAND
This section contains printouts of
apify help for all commands.
Apify command line client to help you create, develop, build and run Actor acts.VERSIONapify-cli/0.1.13 darwin-x64 node-v8.4.0USAGE$ apify [COMMAND]COMMANDScall Runs the act remotely on the Apify platform.create Creates a new act project directory from a selected template.info Displays information about current Apify settings.init Initializes an act project in an existing directory.login Logs in to the Apify platform using the API token.logout Logs out of the Apify platform.push Uploads the act to the Apify platform and builds it there.run Runs the act locally in the current directory.
Runs the act remotely on the Apify platform.USAGE$ apify call [ACTID]ARGUMENTSACTID Name or ID of the act to run (e.g. "apify/hello-world" or"E2jjCZBezvAZnX8Rb"). If not provided, the command runs the remote actspecified in the "apify.json" file.OPTIONS-b, --build=build Tag or number of the build to run (e.g."latest" or "1.2.34").-m, --memory=memory Amount of memory allocated for the actrun, in megabytes.-t, --timeout=timeout Timeout for the act run in seconds.Zero value means there is no timeout.-w, --wait-for-finish=wait-for-finish Seconds for waiting to run to finish,if no value passed, it waits forever.DESCRIPTIONThe act is run under your current Apify account, therefore you need to belogged in by calling "apify login". It takes input for the act from defaultlocal key-value store by default.
Creates a new act project directory from a selected template.USAGE$ apify create ACTNAMEARGUMENTSACTNAME Name of the act and its directoryOPTIONS-t, --template=basic|puppeteer|puppeteer_crawler|plain_request_urls_listTemplate for the act. If not provided, the command will prompt for it.
Displays information about current Apify settings.USAGE$ apify infoDESCRIPTIONThis command prints information about Apify to the console.
Initializes an act project in an existing directory.USAGE$ apify init [ACTNAME]ARGUMENTSACTNAME Name of the act. If not provided, you will be prompted for it.DESCRIPTIONThe command only creates the "apify.json" file and the "apify_local" directoryin the current directory, but will not touch anything else.WARNING: If the files already exist, they will be overwritten!
Logs in to the Apify platform using the API token.USAGE$ apify loginOPTIONS-t, --token=token [Optional] Apify API tokenDESCRIPTIONThe token and other account information is stored to the ~/.apify directory,from where it is read by all other "apify" commands. To log out, call "apifylogout".
Logs out of the Apify platform.USAGE$ apify logoutDESCRIPTIONThe command deletes the API token and all other account information stored inthe ~/.apify directory. To log in again, call "apify login".
Uploads the act to the Apify platform and builds it there.USAGE$ apify push [ACTID]ARGUMENTSACTID ID of an existing act on the Apify platform where the files will bepushed. If not provided, the command will create or modify the act withthe name specified in "apify.json" file.OPTIONS-b, --build-tag=build-tag Build tag to be applied to thesuccessful act build. By default, it istaken from the "apify.json" file-v, --version-number=version-number Act version number to which the filesshould be pushed. By default, it istaken from the "apify.json" file.-w, --wait-for-finish=wait-for-finish Seconds for waiting to build to finish,if no value passed, it waits forever.DESCRIPTIONThe command creates a ZIP with files of the act from the current directory,uploads it to the Apify platform and builds it. The act settings are read fromthe "apify.json" file in the current directory, but they can be overriddenusing command-line options.WARNING: If the target act already exists in your Apify account, it will beoverwritten!
Runs the act locally in the current directory.USAGE$ apify runOPTIONS-p, --purge Shortcut that combines the --purge-queue,--purge-dataset and --purge-key-value-store options.--purge-dataset Deletes the local directory containing the defaultdataset before the run starts.--purge-key-value-store Deletes all records from the default key-value storein the local directory before the run starts, exceptfor the "INPUT" key.--purge-queue Deletes the local directory containing the defaultrequest queue before the run starts.DESCRIPTIONThe command runs a Node.js process with the act in the current directory. Itsets various APIFY_XYZ environment variables in order to provide a workingexecution environment for the act. For example, this causes the act input, aswell as all other data in key-value stores, datasets or request queues to bestored in the "apify_local" directory, rather than on the Apify platform.