Skip to main content
This page lists every name in apostate.__all__ for the Python package 0.4.3. Behaviour that differs in the next release is marked “from 0.4.4”. Python shows how to use them together.
The package needs Python 3.10 or later and installs Patchright, the driver it launches the browser with. pip install "apostate[playwright]" also installs Playwright, the alternative driver.

Launching

Every launch function resolves the options, looks up the locale and timezone of the connection’s exit, finds or downloads the browser, and starts it through the driver. They share the launch options.

launch

Returns a Browser: Playwright’s Browser, with pages in a normal profile. The browser runs on a temporary profile that the driver deletes when the browser closes or the program exits. Every other attribute is Playwright’s Browser: version, is_connected(), browser_type and the rest. Browser is a context manager, so with launch() as browser: closes it. launch() refuses user_data_dir and --user-data-dir in args with ConfigurationError. Use launch_persistent_context() to keep a profile. From 0.4.4, several browsers can be open at once in one thread with the sync API. Every launch(), launch_context() and launch_persistent_context() in a thread shares that thread’s driver, and the driver stops when the last of those browsers closes. In 0.4.3 a second launch while one is open fails with Sync API inside the asyncio loop. There, close the first browser before launching the next, or launch each browser in its own thread or with the async API.

launch_persistent_context

Creates user_data_dir if it does not exist and returns Playwright’s BrowserContext bound to it. The first launch stores a seed in user_data_dir/apostate/identity, and every later launch without fingerprint presents the same machine. Seeds and identity has the details.
  • options are the launch options.
  • context_options are Playwright context options, such as viewport or permissions. They are merged with options.
  • The context has apostate_driver and apostate_driver_name, as Browser does, and apostate_diagnostics from 0.4.4. close() also stops the driver and the virtual display.

launch_context

Launches the browser and returns the BrowserContext of its temporary profile. It is a normal profile, not off-the-record. context_options apply to it at launch. Closing it closes the browser, which deletes the profile. The context has one extra attribute, apostate_browser, which is the Browser it came from. From 0.4.4 the diagnostics are at context.apostate_browser.apostate_diagnostics.

Async versions

The same functions for Playwright’s async API. AsyncBrowser has the members of Browser, with new_page(), new_context() and close() as coroutines, and works with async with. Each async launch starts its own driver, so several can be open in one event loop.

Launch options

Every launch function takes these as keywords. Any other keyword goes to Playwright’s launch_persistent_context, so its launch options (slow_mo, env, ignore_default_args, downloads_path and the rest) and its context options (viewport, permissions, accept_downloads and the rest) both work. The package’s own options, such as locale and proxy, are not passed on. Four details:
  • The window sets the viewport. Pass viewport to fix one. viewport=None means no viewport.
  • env is merged over the environment the package builds. That environment has LANGUAGE, LC_ALL, LC_MESSAGES and LANG set to the persona’s locale, and TZ set to the timezone. Host mode keeps yours.
  • The package removes --disable-component-update from Playwright’s default switches, so the Widevine CDM registers. Pass it in args to keep the switch. On macOS that keeps the CDM out. On Linux the browser loads the CDM beside its executable either way. See the Linux Widevine module.
  • From 0.4.4 the package passes chromium_sandbox=True unless you pass chromium_sandbox, where the sandbox can start: macOS, Windows, and Linux as a regular user outside a container, with no seccomp filter and with user namespaces allowed. Elsewhere Playwright passes --no-sandbox, and a headed first tab shows a 56-pixel bar for it. See A bar on the first tab.
  • From 0.4.4 the package passes color_scheme="null" unless you pass color_scheme, so a page reads the persona’s own prefers-color-scheme. In 0.4.3 Playwright emulates light. Pass color_scheme="null" there. See prefers-color-scheme in the 0.4.3 packages.
A failed GeoIP lookup does not raise. It prints apostate: ... on stderr, sends no switch for the field it could not fill, and the persona uses en-US and the host’s timezone there. From 0.4.4 the warning is also in apostate_diagnostics["warnings"]. Errors shows the text.

driver_info

Reports which driver a launch would use, without starting a browser.

DRIVERS

The drivers the package can launch with, in preference order: ("patchright", "playwright").

DriverSelection

A named tuple, DriverSelection(name, factory), of the chosen driver’s name and its sync_playwright or async_playwright entry point.

LaunchPlan

A frozen dataclass that holds a resolved launch: config (LaunchConfig), profile (dict), resolution (ProfileResolution or None), geoip (GeoIPResult or None) and diagnostics (dict, including warnings).

Binary management

The launch functions call these for you. Call them to install ahead of time or to find out which browser a launch would use. Installation explains the cache, discovery and verification.

ensure_binary

Returns the path of a runnable browser executable. It looks in this order, and downloads only when nothing answers:
  1. APOSTATE_BINARY, taken as given.
  2. This package’s own install in the cache, when its record still matches the executable’s SHA-256.
  3. The well-known locations: /Applications and ~/Applications on macOS, ~/.cache/apostate and /opt/apostate on Linux, %LOCALAPPDATA%\apostate on Windows. A browser found there is used only when an Apostate build record or catalogue sits beside it and it reports Chromium 152.0.7977.83.
  4. The release archive, downloaded, checked against the manifest’s SHA-256 before it is opened, and extracted into the cache.

binary_info

Returns what apostate info prints. It never raises for a missing release.

discover_binary

The browser a launch would use without downloading, or None. search_roots replaces the well-known locations, and an empty list searches none.

discovery_report

The same search, with what was searched and why each candidate was refused. A reason is one of these:
  • no Apostate payload beside it (build/MANIFEST.lock or resources/profiles/catalogue.json): a browser with no Apostate build record or catalogue beside it, such as stock Chromium.
  • reports Chromium <version>, not 152.0.7977.83: an Apostate build of another version.
  • version could not be established, or not executable.
  • the configured path does not name a file, APOSTATE_BINARY does not name a file, or ... names a directory with no browser inside it (expected Chromium.app, chrome or chrome.exe): a path you named that holds no browser.

clear_cache

Deletes the whole cache directory, with every version and target in it and the stored Widevine CDM. It refuses a cache directory that is a symlink with BinaryError.

target_platform

Returns linux-x64, linux-arm64, macos-arm64 or windows-x64. With no value it names this host, and raises BinaryError on a host with no build, such as an Intel Mac. It also takes darwin-arm64, mac-arm64, osx-arm64, win-x64, linux-aarch64 and linux-amd64.

BinaryManager

The class behind the functions above. ensure(*, target=None, artifact=None, keep_archive=None, force=False), info(*, target=None), discover(*, target=None, binary_path=None), discovery(*, target=None, binary_path=None) and clear() match ensure_binary, binary_info, discover_binary, discovery_report and clear_cache. assert_published(*, target=None) raises UnpublishedArtifactError when no browser for the target is on disk or published. cache_dir holds the resolved cache path.

DiscoveredBinary

A named tuple, DiscoveredBinary(executable, source, chromium_version, payload_root). executable and payload_root are Path objects. source is argument, environment, cache or well-known.

Profiles and resolver

The browser composes the machine from the seed. The resolver only decides which path a launch takes: a seed and persona sent as switches, host mode, or a profile you wrote sent as --apostate-profile. How it works explains composition.

resolve_profile

Resolves the launch selectors without starting anything. geoip is a lookup result as a mapping, used for the locale and timezone that were not passed.

ProfileResolution

A frozen dataclass. to_dict() returns the fields below, with browser_version under the key browser_build.

resolve

resolve_profile for a LaunchConfig you already have.

DeterministicResolver

Loads and checks the catalogue, and raises ProfileError when it does not match this package. resolve(config, *, geoip=None) returns a ProfileResolution. catalogue_summary() returns what load_catalogue() returns. Calling the resolver with a LaunchConfig returns the resolved profile, so an instance can be passed as resolver=.

load_catalogue

Returns the catalogue’s shape: catalogue_version, profile_schema_version, browser_build, model, anchors (the GPU families, each with id, platform, backend, members and rotation_status), axes and policies.

validate_profile

Checks a profile against config/profile.schema.json and returns a copy. Raises ProfileError naming up to four problems:

load_schema

The profile schema as a mapping.

LaunchConfig

The checked form of the launch options. Creating one validates and normalizes every field and raises ConfigurationError on a bad one. to_dict() and canonical_json() serialize it.

translate_options

Builds a LaunchConfig from launch options. Any other keyword raises ConfigurationError: unsupported launch option(s): ....

normalize_platform

Returns windows, macos, linux or None, and maps the aliases. Raises ConfigurationError for anything else.

host_persona

The host’s own platform: windows, macos or linux. This is not the persona a default launch presents on Linux. Pass it to default_persona_for_host() for that.

default_persona_for_host

The persona a launch with no fingerprint_platform presents on a host: macos for macos, windows for windows and for linux. An unknown token is returned unchanged.

DEFAULT_PERSONA_BY_HOST

The read-only mapping default_persona_for_host() uses: {'macos': 'macos', 'windows': 'windows', 'linux': 'windows'}.

GeoIP

resolve_geoip

Looks up the exit, through proxy when given, and returns the result. Unlike a launch, it raises GeoIPError when the lookup fails, and when require_locale or require_timezone is set and the answer lacks that field. provider is None for the built-in lookup, a callable, or an object with a lookup, resolve_prelaunch_geoip, lookup_exit_ip, resolve_geoip or resolve method. It is called with the keywords proxy, timeout and geoip that its signature names, or else with (proxy, timeout). It returns a mapping or a GeoIPResult.

GeoIPResult

to_dict() returns the same fields, with languages as a list.

GeoIPProvider

A typing.Protocol for a provider object: lookup(self, proxy: str | None = None, *, timeout: float = 20.0) -> Mapping[str, Any].

normalize_result

Turns a provider’s mapping into a GeoIPResult. It reads timezone, time_zone or tz; locale, language or default_locale; languages or accept_languages; country_code, countryCode, country_iso or country; region, region_code or regionCode; and ip, address or exit_ip. Only an IANA name, UTC or GMT counts as a timezone, and only a two-letter code as a country. With no locale, the country’s locale comes from config/country-locales.json, so DE gives de-DE.

redact_proxy

Removes the credential from a proxy URL: socks5://user:pass@proxy.example:1080 gives socks5://proxy.example:1080. An unparseable value gives <proxy>.

Widevine

The browser ships without the Widevine CDM. A launch copies one from a local Google Chrome, or downloads it from Google’s component update service and checks its SHA-256, then keeps it in the cache directory. Widevine explains when you need this.

ensure_widevine

Exported as ensure_widevine. Gives the browser at executable a CDM if it has none, and returns the browser’s CDM directory. On Linux it also writes the CDM’s location into user_data_dir. It returns None when executable is not inside an Apostate install or no CDM could be had, and never raises.

provision_widevine

Exported as provision_widevine. Installs a CDM into this package’s browser now, replacing any it has, and raises WidevineError when none can be had. source is a WidevineCdm directory, with or without a version directory inside. It returns platform, platform_verified (False for windows-x64, where Widevine has not been tried), source, version, store and installed.

discover_widevine

Exported as discover_widevine. Every CDM on this machine for target, newest first, each with path, version and bytes. It downloads nothing.

Constants

Exceptions

Every exception the package raises is an ApostateError. From 0.4.4 messages never contain a proxy credential. In 0.4.3 a LaunchError can echo the --apostate-profile value, which holds the credential base64-encoded. Errors lists the common messages and their fixes.