Skip to content

chore: Bump minimum Python version to 3.10 #493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/pre_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,26 @@ jobs:
name: Lint check
uses: apify/workflows/.github/workflows/python_lint_check.yaml@main
with:
python-versions: '["3.9", "3.10", "3.11", "3.12", "3.13"]'
python-versions: '["3.10", "3.11", "3.12", "3.13"]'

type_check:
name: Type check
uses: apify/workflows/.github/workflows/python_type_check.yaml@main
with:
python-versions: '["3.9", "3.10", "3.11", "3.12", "3.13"]'
python-versions: '["3.10", "3.11", "3.12", "3.13"]'

unit_tests:
name: Unit tests
uses: apify/workflows/.github/workflows/python_unit_tests.yaml@main
with:
python-versions: '["3.9", "3.10", "3.11", "3.12", "3.13"]'
python-versions: '["3.10", "3.11", "3.12", "3.13"]'

integration_tests:
name: Integration tests
uses: apify/workflows/.github/workflows/python_integration_tests.yaml@main
secrets: inherit
with:
python-versions: '["3.9", "3.13"]'
python-versions: '["3.10", "3.13"]'

update_changelog:
name: Update changelog
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,26 @@ jobs:
name: Lint check
uses: apify/workflows/.github/workflows/python_lint_check.yaml@main
with:
python-versions: '["3.9", "3.10", "3.11", "3.12", "3.13"]'
python-versions: '["3.10", "3.11", "3.12", "3.13"]'

type_check:
name: Type check
uses: apify/workflows/.github/workflows/python_type_check.yaml@main
with:
python-versions: '["3.9", "3.10", "3.11", "3.12", "3.13"]'
python-versions: '["3.10", "3.11", "3.12", "3.13"]'

unit_tests:
name: Unit tests
uses: apify/workflows/.github/workflows/python_unit_tests.yaml@main
with:
python-versions: '["3.9", "3.10", "3.11", "3.12", "3.13"]'
python-versions: '["3.10", "3.11", "3.12", "3.13"]'

integration_tests:
name: Integration tests
uses: apify/workflows/.github/workflows/python_integration_tests.yaml@main
secrets: inherit
with:
python-versions: '["3.9", "3.13"]'
python-versions: '["3.10", "3.13"]'

update_changelog:
name: Update changelog
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/run_code_checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ jobs:
name: Lint check
uses: apify/workflows/.github/workflows/python_lint_check.yaml@main
with:
python-versions: '["3.9", "3.10", "3.11", "3.12", "3.13"]'
python-versions: '["3.10", "3.11", "3.12", "3.13"]'

type_check:
name: Type check
uses: apify/workflows/.github/workflows/python_type_check.yaml@main
with:
python-versions: '["3.9", "3.10", "3.11", "3.12", "3.13"]'
python-versions: '["3.10", "3.11", "3.12", "3.13"]'

unit_tests:
name: Unit tests
uses: apify/workflows/.github/workflows/python_unit_tests.yaml@main
with:
python-versions: '["3.9", "3.10", "3.11", "3.12", "3.13"]'
python-versions: '["3.10", "3.11", "3.12", "3.13"]'

docs_check:
name: Docs check
Expand All @@ -35,4 +35,4 @@ jobs:
uses: apify/workflows/.github/workflows/python_integration_tests.yaml@main
secrets: inherit
with:
python-versions: '["3.9", "3.13"]'
python-versions: '["3.10", "3.13"]'
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Here you'll find a contributing guide to get started with development.

## Environment

For local development, it is required to have Python 3.9 (or a later version) installed.
For local development, it is required to have Python 3.10 (or a later version) installed.

We use [uv](https://docs.astral.sh/uv/) for project management. Install it and set up your IDE accordingly.

Expand Down
2 changes: 1 addition & 1 deletion docs/01_overview/02_running_actors_locally.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ In this page, you'll learn how to create and run Apify Actors locally on your co

## Requirements

The Apify SDK requires Python version 3.9 or above to run Python Actors locally.
The Apify SDK requires Python version 3.10 or above to run Python Actors locally.

## Creating your first Actor

Expand Down
7 changes: 3 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ description = "Apify SDK for Python"
authors = [{ name = "Apify Technologies s.r.o.", email = "[email protected]" }]
license = { file = "LICENSE" }
readme = "README.md"
requires-python = ">=3.9"
requires-python = ">=3.10"
classifiers = [
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
Expand Down Expand Up @@ -188,7 +187,7 @@ asyncio_mode = "auto"
timeout = 1200

[tool.mypy]
python_version = "3.9"
python_version = "3.10"
plugins = ["pydantic.mypy"]
files = ["src", "tests", "docs", "website"]
check_untyped_defs = true
Expand All @@ -215,7 +214,7 @@ module = [
ignore_missing_imports = true

[tool.basedpyright]
pythonVersion = "3.9"
pythonVersion = "3.10"
typeCheckingMode = "standard"
include = ["src", "tests", "docs", "website"]

Expand Down
3 changes: 2 additions & 1 deletion src/apify/_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import sys
from contextlib import suppress
from datetime import datetime, timedelta, timezone
from typing import TYPE_CHECKING, Any, Callable, Literal, TypeVar, cast, overload
from typing import TYPE_CHECKING, Any, Literal, TypeVar, cast, overload

from lazy_object_proxy import Proxy
from more_itertools import flatten
Expand Down Expand Up @@ -39,6 +39,7 @@

if TYPE_CHECKING:
import logging
from collections.abc import Callable
from types import TracebackType

from typing_extensions import Self
Expand Down
5 changes: 2 additions & 3 deletions src/apify/_charging.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from dataclasses import dataclass
from datetime import datetime, timezone
from decimal import Decimal
from typing import TYPE_CHECKING, Protocol, Union
from typing import TYPE_CHECKING, Protocol

from pydantic import TypeAdapter

Expand All @@ -23,8 +23,7 @@

from apify._configuration import Configuration


run_validator: TypeAdapter[ActorRun | None] = TypeAdapter(Union[ActorRun, None])
run_validator = TypeAdapter[ActorRun | None](ActorRun | None)


@docs_group('Interfaces')
Expand Down
2 changes: 1 addition & 1 deletion src/apify/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from apify._utils import docs_group

if TYPE_CHECKING:
from typing_extensions import TypeAlias
from typing import TypeAlias


@docs_group('Data structures')
Expand Down
25 changes: 5 additions & 20 deletions src/apify/_platform_event_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import asyncio
from datetime import datetime
from typing import TYPE_CHECKING, Annotated, Any, Literal, Union
from typing import TYPE_CHECKING, Annotated, Any, Literal

import websockets.asyncio.client
from pydantic import BaseModel, Discriminator, Field, TypeAdapter
Expand Down Expand Up @@ -113,25 +113,10 @@ class UnknownEvent(BaseModel):
data: Annotated[dict[str, Any], Field(default_factory=dict)]


EventMessage = Union[
PersistStateEvent,
SystemInfoEvent,
MigratingEvent,
AbortingEvent,
ExitEvent,
EventWithoutData,
]


event_data_adapter: TypeAdapter[EventMessage | DeprecatedEvent | UnknownEvent] = TypeAdapter(
Union[
Annotated[
EventMessage,
Discriminator('name'),
],
DeprecatedEvent,
UnknownEvent,
]
EventMessage = PersistStateEvent | SystemInfoEvent | MigratingEvent | AbortingEvent | ExitEvent | EventWithoutData

event_data_adapter = TypeAdapter[EventMessage | DeprecatedEvent | UnknownEvent](
Annotated[EventMessage, Discriminator('name')] | DeprecatedEvent | UnknownEvent
)


Expand Down
5 changes: 4 additions & 1 deletion src/apify/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import builtins
import sys
from importlib import metadata
from typing import Callable, Literal
from typing import TYPE_CHECKING, Literal

if TYPE_CHECKING:
from collections.abc import Callable


def get_system_info() -> dict:
Expand Down
4 changes: 2 additions & 2 deletions src/apify/storages/_request_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import re
from asyncio import Task
from functools import partial
from typing import Annotated, Any, Union
from typing import Annotated, Any

from pydantic import BaseModel, Field, TypeAdapter

Expand Down Expand Up @@ -35,7 +35,7 @@ class _SimpleUrlInput(_RequestDetails):
url: str


url_input_adapter = TypeAdapter(list[Union[_RequestsFromUrlInput, _SimpleUrlInput]])
url_input_adapter = TypeAdapter(list[_RequestsFromUrlInput | _SimpleUrlInput])


@docs_group('Classes')
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import sys
import textwrap
from pathlib import Path
from typing import TYPE_CHECKING, Any, Callable, Protocol
from typing import TYPE_CHECKING, Any, Protocol

import pytest
from filelock import FileLock
Expand All @@ -22,7 +22,7 @@
from apify._models import ActorRun

if TYPE_CHECKING:
from collections.abc import Awaitable, Coroutine, Iterator, Mapping
from collections.abc import Awaitable, Callable, Coroutine, Iterator, Mapping
from decimal import Decimal

from apify_client.clients.resource_clients import ActorClientAsync
Expand Down
5 changes: 4 additions & 1 deletion tests/integration/test_actor_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ async def test_emit_and_capture_interval_events(
async def main() -> None:
import os
from datetime import datetime
from typing import Any, Callable
from typing import TYPE_CHECKING, Any

from apify_shared.consts import ActorEventTypes, ApifyEnvVars
from crawlee.events._types import Event, EventSystemInfoData

if TYPE_CHECKING:
from collections.abc import Callable

os.environ[ApifyEnvVars.PERSIST_STATE_INTERVAL_MILLIS] = '900'

was_system_info_emitted = False
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/actor/test_actor_lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import json
import sys
from datetime import datetime, timezone
from typing import TYPE_CHECKING, Any, Callable, cast
from typing import TYPE_CHECKING, Any, cast
from unittest.mock import AsyncMock, Mock

import pytest
Expand All @@ -19,6 +19,8 @@
from apify._actor import _ActorType

if TYPE_CHECKING:
from collections.abc import Callable

from lazy_object_proxy import Proxy


Expand Down
25 changes: 3 additions & 22 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import inspect
import os
from collections import defaultdict
from copy import deepcopy
from typing import TYPE_CHECKING, Any, Callable, get_type_hints
from typing import TYPE_CHECKING, Any, get_type_hints

import pytest

Expand All @@ -19,6 +18,7 @@
import apify._actor

if TYPE_CHECKING:
from collections.abc import Callable
from pathlib import Path


Expand Down Expand Up @@ -125,26 +125,7 @@ def patch(
if not client_method:
raise ValueError(f'ApifyClientAsync does not contain method "{method}"!')

try:
# Try to get the return type of the client method using `typing.get_type_hints()`
client_method_return_type = get_type_hints(client_method)['return']
except TypeError:
# There is a known issue with `typing.get_type_hints()` on Python 3.9. It raises a `TypeError`
# when `|` (Union) is used in the type hint, even with `from __future__ import annotations`. Since we
# only need the return type, we attempt the following workaround.

# 1. Create a deep copy of the client method object
client_method_copied = deepcopy(client_method)

# 2. Restrict the annotations to only include the return type
client_method_copied.__annotations__ = {'return': client_method.__annotations__['return']}

# 3. Try to get the return type again using `typing.get_type_hints()`
client_method_return_type = get_type_hints(client_method_copied)['return']

# TODO: Remove this fallback once we drop support for Python 3.9
# https://github.com/apify/apify-sdk-python/issues/151

client_method_return_type = get_type_hints(client_method)['return']
original_submethod = getattr(client_method_return_type, submethod, None)

if not original_submethod:
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/test_platform_event_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import json
import logging
from collections import defaultdict
from typing import Any, Callable
from typing import TYPE_CHECKING, Any
from unittest.mock import Mock

import pytest
Expand All @@ -17,6 +17,9 @@
from apify import Configuration
from apify._platform_event_manager import PlatformEventManager, SystemInfoEventData

if TYPE_CHECKING:
from collections.abc import Callable


@pytest.mark.skip(reason='There are issues with log propagation to caplog, see issue #462.')
async def test_lifecycle_local(caplog: pytest.LogCaptureFixture) -> None:
Expand Down
Loading