Upgrading to v2
This page summarizes the breaking changes between Apify Python SDK v1.x and v2.0.
Python version support
Support for Python 3.8 has been dropped. The Apify Python SDK v2.x now requires Python 3.9 or later. Make sure your environment is running a compatible version before upgrading.
Storages
- The SDK now uses crawlee for local storage emulation. This change should not affect intended usage (working with
Dataset,KeyValueStoreandRequestQueueclasses from theapify.storagesmodule or using the shortcuts exposed by theActorclass) in any way. - There is a difference in the
RequestQueue.add_requestmethod: it accepts anapify.Requestobject instead of a free-form dictionary.- A quick way to migrate from dict-based arguments is to wrap it with a
Request.model_validate()call. - The preferred way is using the
Request.from_urlhelper which prefills theunique_keyandidattributes, or instantiating it directly, e.g.,Request(url='https://example.tld', ...). - For simple use cases,
add_requestalso accepts plain strings that contain an URL, e.g.queue.add_request('https://example.tld').
- A quick way to migrate from dict-based arguments is to wrap it with a
- Removing the
StorageClientManagerclass is a significant change. If you need to change the storage client, usecrawlee.service_containerinstead.
Configuration
The apify.Configuration class now uses pydantic_settings to load configuration from environment variables. This eliminates the need for the helper functions which handled environment variables in apify._utils.
Attributes suffixed with _millis were renamed to remove said suffix and have the datetime.timedelta type now.
Actor
- The
Actor.mainmethod has been removed as it brings no benefits compared to usingasync with Actor. - The
Actor.add_webhook,Actor.start,Actor.callandActor.start_taskmethods now accept instances of theapify.Webhookmodel instead of an untypeddict. Actor.start,Actor.call,Actor.start_task,Actor.set_status_messageandActor.abortreturn instances of theActorRunmodel instead of an untypeddict.- Upon entering the context manager (
async with Actor), theActorputs the default logging configuration in place. This can be disabled using theconfigure_loggingparameter. - The
configparameter ofActorhas been renamed toconfiguration. - Event handlers registered via
Actor.onwill now receive Pydantic objects instead of untyped dicts. For example, where you would doevent['isMigrating'], you should now useevent.is_migrating
Scrapy integration
The apify.scrapy.utils.open_queue_with_custom_client function is not necessary anymore and has been removed.
Subpackage visibility
The following modules were made private:
apify.proxy_configuration(ProxyConfigurationis still exported fromapify)apify.config(Configurationis still exported fromapify)apify.actor(Actoris still exported fromapify)apify.event_managerapify.consts