Skip to main content
Version: Next

ActorServerClient

Sub-client for the server interface of a specific Actor.

Provides methods to work with the web server of a Server Actor, e.g. send it requests or get its OpenAPI specification. Obtain an instance via an appropriate method on the ActorClient class.

Hierarchy

Index

Methods

__init__

  • __init__(*, base_url, public_base_url, http_client, resource_path, client_registry, resource_id, params, api_base_url): None
  • Initialize the resource client.


    Parameters

    • keyword-onlybase_url: str

      API base URL.

    • keyword-onlypublic_base_url: str

      Public CDN base URL.

    • keyword-onlyhttp_client: HttpClient

      HTTP client for making requests.

    • keyword-onlyresource_path: str

      Resource endpoint path (e.g., 'actors', 'datasets').

    • keyword-onlyclient_registry: ClientRegistry

      Bundle of client classes for dependency injection.

    • optionalkeyword-onlyresource_id: str | None = None

      Optional resource ID for single-resource clients.

    • optionalkeyword-onlyparams: QueryParams | None = None

      Optional default parameters for all requests.

    • optionalkeyword-onlyapi_base_url: str | None = None

      Base URL of the API itself, for clients of top-level resources. Defaults to base_url.

    Returns None

get_openapi_spec

  • get_openapi_spec(*, timeout): dict[str, Any] | None
  • Return the OpenAPI specification of the Actor's server.

    The specification is the web server schema from the Actor's definition, taken from the build that serves the server interface: the build set in actor_standby.build, or latest if none is set. Use it to generate an HTTP client for the server, and point that client at the URL returned by get_url.

    https://docs.apify.com/platform/actors/development/actor-definition/web-server-schema


    Parameters

    • optionalkeyword-onlytimeout: Timeout = 'short'

      Timeout for each API HTTP request.

    Returns dict[str, Any] | None

    The OpenAPI specification of the Actor's server, or None if the Actor's definition doesn't include one.

get_url

  • get_url(*, timeout): str
  • Return the URL of the Actor's server.

    The URL is the Actor's standby_url, fetched from the API by the first call of this method or get_openapi_spec and reused by later calls on this client. Use it to call the server with another HTTP client, for example one generated from the server's OpenAPI specification.

    https://docs.apify.com/platform/actors/running/standby


    Parameters

    • optionalkeyword-onlytimeout: Timeout = 'short'

      Timeout for the API HTTP request.

    Returns str

    The URL of the Actor's server.

request

  • request(path, *, method, params, headers, data, json, compression, stream, timeout): HttpResponse
  • Send an HTTP request to the Actor's server.

    The request goes to the URL returned by get_url and carries the client's token in the X-Apify-Authorization header, which the platform consumes, so it never reaches the Actor's code. Headers you pass, Authorization included, reach the Actor's server as they are. The first request to an idle Actor waits for the platform to start a server run, which is why the timeout defaults to long.

    The method returns any response of the server, error statuses included. A rate-limit (429) or Service Unavailable (503) response is retried with the client's retry settings, and the last one is returned once the retries run out. The Actor's code can return these statuses too, and then it gets the request again. A redirect is returned as it is, since following it would send the token to a host the Actor's code picked. Request bodies are sent uncompressed unless compression is set, since the Actor's server may not decode a compressed body.

    https://docs.apify.com/platform/actors/running/standby


    Parameters

    • optionalpath: str = '/'

      The path on the Actor's server, for example /search. It is always resolved against the server URL, so the request, and the token with it, cannot be sent to another host. Pass the query in params. A fragment (#...) is dropped, since it is never sent to the server.

    • optionalkeyword-onlymethod: HttpMethod = 'GET'

      HTTP method of the request.

    • optionalkeyword-onlyparams: QueryParams | None = None

      Query parameters of the request, converted the same way as for API calls: booleans become true or false, a list of strings becomes one comma-separated value, a datetime becomes an ISO 8601 string in UTC, and None values are left out.

    • optionalkeyword-onlyheaders: dict[str, str] | None = None

      Additional headers of the request.

    • optionalkeyword-onlydata: (str | bytes) | None = None

      Raw request body. Cannot be used together with json.

    • optionalkeyword-onlyjson: JsonSerializable | None = None

      JSON-serializable request body. Cannot be used together with data.

    • optionalkeyword-onlycompression: (HttpCompressionAlgorithm | HttpCompressor) | None = None

      Compression algorithm for the request body, as a string literal or an HttpCompressor instance. The body is compressed under the same conditions as for API calls. Set it only if the Actor's server decodes the resulting Content-Encoding.

    • optionalkeyword-onlystream: bool = False

      Whether to return the response with the body unread, so it can be read in chunks with iter_bytes (aiter_bytes in the async client). The response holds its connection open until you close it.

    • optionalkeyword-onlytimeout: Timeout = 'long'

      Timeout for the HTTP request. With stream, it bounds the wait for the server to start responding.

    Returns HttpResponse

    The response of the Actor's server.

Properties

resource_id

resource_id: str | None

Get the resource ID.