Upgrading to v2
This page summarizes most of 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
,KeyValueStore
andRequestQueue
classes from theapify.storages
module or using the shortcuts exposed by theActor
class) in any way. - There is a difference in the
RequestQueue.add_request
method: it accepts anapify.Request
object 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_url
helper which prefills theunique_key
andid
attributes, or instantiating it directly, e.g.,Request(url='https://example.tld', ...)
. - For simple use cases,
add_request
also 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
StorageClientManager
class is a significant change. If you need to change the storage client, usecrawlee.service_container
instead.
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.main
method has been removed as it brings no benefits compared to usingasync with Actor
. - The
Actor.add_webhook
,Actor.start
,Actor.call
andActor.start_task
methods now accept instances of theapify.Webhook
model instead of an untypeddict
. Actor.start
,Actor.call
,Actor.start_task
,Actor.set_status_message
andActor.abort
return instances of theActorRun
model instead of an untypeddict
.- Upon entering the context manager (
async with Actor
), theActor
puts the default logging configuration in place. This can be disabled using theconfigure_logging
parameter. - The
config
parameter ofActor
has been renamed toconfiguration
. - Event handlers registered via
Actor.on
will 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
(ProxyConfiguration
is still exported fromapify
)apify.config
(Configuration
is still exported fromapify
)apify.actor
(Actor
is still exported fromapify
)apify.event_manager
apify.consts