Back to template gallery

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.

Language

python

Run on Apify
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:

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.