Start with Python
A simple Python example of core Actor and Apify SDK features. It reads and validates user input with schema, computes a result and saves it to storage.
from apify import Actor
async def main():
async with Actor:
# Get the value of the actor input
actor_input = await Actor.get_input() or {}
# Structure of input is defined in .actor/input_schema.json
first_number = actor_input.get('first_number')
second_number = actor_input.get('second_number')
print(f'First number: {first_number}')
print(f'Second number: {second_number}')
# 馃憠 Complete the code so that result is
# the sum of first_number and second_number.
# 馃憞馃憞馃憞馃憞馃憞馃憞馃憞馃憞馃憞馃憞
result = None
# 馃憜馃憜馃憜馃憜馃憜馃憜馃憜馃憜馃憜馃憜
print(f'The result is: {result}')
# Structure of output is defined in .actor/actor.json
await Actor.push_data([
{
'first_number': first_number,
'second_number': second_number,
'sum': result,
},
])
Start with Python template
A simple Python example of core Actor and Apify SDK features. It reads and validates user input with schema, computes a result and saves it to storage.
Getting Started
Install Apify CLI
Using Homebrew
brew install apify/tap/apify-cli
Using NPM
npm -g install apify-cli
Create a new Actor using this template
apify create my-python-actor -t python-start
Run the Actor locally
cd my-python-actor apify run
Deploy on Apify
Log in to Apify
You will need to provide your Apify API Token to complete this action.
apify login
Deploy your Actor
This command will deploy and build the Actor on the Apify Platform. You can find your newly created Actor under Actors -> My Actors.
apify push
Documentation reference
To learn more about Apify and Actors, take a look at the following resources:
Related templates
Example of a web scraper that uses Python Requests to scrape HTML from URLs provided on input, parses it using BeautifulSoup and saves results to storage.
Crawler example that uses headless Chrome driven by Playwright to scrape a website. Headless browsers render JavaScript and can help when getting blocked.
Scraper example built with Selenium and headless Chrome browser to scrape a website and save the results to storage. A popular alternative to Playwright.
This example Scrapy spider scrapes quotes filtered by input parameters. It shows how to use Apify SDK for Python and Scrapy pipelines to save results.
Already have a solution in mind?
Sign up for a free Apify account and deploy your code to the platform in just a few minutes! If you want a head start without coding it yourself, browse our Store of existing solutions.