findmy.reports.account

Contents

findmy.reports.account#

Module containing most of the code necessary to interact with an Apple account.

Attributes#

Classes#

AccountStateMapping

JSON mapping representing state of an Apple account instance.

BaseAppleAccount

Base class for an Apple account.

AsyncAppleAccount

An async implementation of BaseAppleAccount().

AppleAccount

A sync implementation of BaseappleAccount().

Module Contents#

findmy.reports.account.logger#
class findmy.reports.account.AccountStateMapping#

Bases: TypedDict

Inheritance diagram of findmy.reports.account.AccountStateMapping

JSON mapping representing state of an Apple account instance.

type: Literal['account']#
ids: _AccountStateMappingIds#
account: _AccountStateMappingAccount#
login: _AccountStateMappingLoginState#
anisette: findmy.reports.anisette.AnisetteMapping#
class findmy.reports.account.BaseAppleAccount(loop: asyncio.AbstractEventLoop | None = None)#

Bases: findmy.util.abc.Closable, findmy.util.abc.Serializable[AccountStateMapping], abc.ABC

Inheritance diagram of findmy.reports.account.BaseAppleAccount

Base class for an Apple account.

property login_state: findmy.reports.state.LoginState#
Abstractmethod:

The current login state of the account.

property account_name: str | None#
Abstractmethod:

The name of the account as reported by Apple.

This is usually an e-mail address. May be None in some cases, such as when not logged in.

property first_name: str | None#
Abstractmethod:

First name of the account holder as reported by Apple.

May be None in some cases, such as when not logged in.

property last_name: str | None#
Abstractmethod:

Last name of the account holder as reported by Apple.

May be None in some cases, such as when not logged in.

abstractmethod login(username: str, password: str) findmy.util.types.MaybeCoro[findmy.reports.state.LoginState]#

Log in to an Apple account using a username and password.

abstractmethod get_2fa_methods() findmy.util.types.MaybeCoro[collections.abc.Sequence[findmy.reports.twofactor.BaseSecondFactorMethod]]#

Get a list of 2FA methods that can be used as a secondary challenge.

Currently, only SMS-based 2FA methods are supported.

abstractmethod sms_2fa_request(phone_number_id: int) findmy.util.types.MaybeCoro[None]#

Request a 2FA code to be sent to a specific phone number ID.

Consider using BaseSecondFactorMethod.request() instead.

abstractmethod sms_2fa_submit(phone_number_id: int, code: str) findmy.util.types.MaybeCoro[findmy.reports.state.LoginState]#

Submit a 2FA code that was sent to a specific phone number ID.

Consider using BaseSecondFactorMethod.submit() instead.

abstractmethod td_2fa_request() findmy.util.types.MaybeCoro[None]#

Request a 2FA code to be sent to a trusted device.

Consider using BaseSecondFactorMethod.request() instead.

abstractmethod td_2fa_submit(code: str) findmy.util.types.MaybeCoro[findmy.reports.state.LoginState]#

Submit a 2FA code that was sent to a trusted device.

Consider using BaseSecondFactorMethod.submit() instead.

abstractmethod fetch_location_history(keys: findmy.keys.HasHashedPublicKey) findmy.util.types.MaybeCoro[list[findmy.reports.reports.LocationReport]]#
abstractmethod fetch_location_history(keys: findmy.accessory.RollingKeyPairSource) findmy.util.types.MaybeCoro[list[findmy.reports.reports.LocationReport]]
abstractmethod fetch_location_history(keys: collections.abc.Sequence[findmy.keys.HasHashedPublicKey | findmy.accessory.RollingKeyPairSource]) findmy.util.types.MaybeCoro[dict[findmy.keys.HasHashedPublicKey | findmy.accessory.RollingKeyPairSource, list[findmy.reports.reports.LocationReport]]]

Fetch location history for :class:`HasHashedPublicKey`s and :class:`RollingKeyPairSource`s.

Note that location history for devices is provided on a best-effort basis and may not be fully complete or stable. Multiple consecutive calls to this method may result in different location reports, especially for reports further in the past. However, each one of these reports is guaranteed to be in line with the data reported by Apple, and the most recent report will always be included in the results.

Unless you really need to use this method, and use fetch_location() instead.

abstractmethod fetch_location(keys: findmy.keys.HasHashedPublicKey) findmy.util.types.MaybeCoro[findmy.reports.reports.LocationReport | None]#
abstractmethod fetch_location(keys: findmy.accessory.RollingKeyPairSource) findmy.util.types.MaybeCoro[findmy.reports.reports.LocationReport | None]
abstractmethod fetch_location(keys: collections.abc.Sequence[findmy.keys.HasHashedPublicKey | findmy.accessory.RollingKeyPairSource]) findmy.util.types.MaybeCoro[dict[findmy.keys.HasHashedPublicKey | findmy.accessory.RollingKeyPairSource, findmy.reports.reports.LocationReport | None] | None]

Fetch location for :class:`HasHashedPublicKey`s.

Returns a dictionary mapping :class:`HasHashedPublicKey`s to their location reports.

abstractmethod get_anisette_headers(with_client_info: bool = False, serial: str = '0') findmy.util.types.MaybeCoro[dict[str, str]]#

Retrieve a complete dictionary of Anisette headers.

Utility method for AnisetteProvider.get_headers() using this account’s user/device ID.

class findmy.reports.account.AsyncAppleAccount(anisette: findmy.reports.anisette.BaseAnisetteProvider, *, state_info: AccountStateMapping | None = None)#

Bases: BaseAppleAccount

Inheritance diagram of findmy.reports.account.AsyncAppleAccount

An async implementation of BaseAppleAccount().

property login_state: findmy.reports.state.LoginState#

See BaseAppleAccount.login_state().

property account_name: str | None#

See BaseAppleAccount.account_name().

property first_name: str | None#

See BaseAppleAccount.first_name().

property last_name: str | None#

See BaseAppleAccount.last_name().

to_json(path: str | pathlib.Path | None = None, /) AccountStateMapping#

Export the current state of the object as a JSON-serializable dictionary.

If an argument is provided, the output will also be written to that file.

The output of this method is guaranteed to be JSON-serializable, and passing the return value of this function as an argument to Serializable.from_json() will always result in an exact copy of the internal state as it was when exported.

You are encouraged to save and load object states to and from disk whenever possible, to prevent unnecessary API calls or otherwise unexpected behavior.

classmethod from_json(val: str | pathlib.Path | AccountStateMapping, /, *, anisette_libs_path: str | pathlib.Path | None = None) AsyncAppleAccount#

Restore state from a previous Closable.to_json() export.

If given a str or Path, it must point to a json file from Serializable.to_json(). Otherwise, it should be the Mapping itself.

See Serializable.to_json() for more information.

async close() None#

Close any sessions or other resources in use by this object.

Should be called when the object will no longer be used.

async login(username: str, password: str) findmy.reports.state.LoginState#

See BaseAppleAccount.login().

async get_2fa_methods() collections.abc.Sequence[findmy.reports.twofactor.AsyncSecondFactorMethod]#

See BaseAppleAccount.get_2fa_methods().

async sms_2fa_request(phone_number_id: int) None#

See BaseAppleAccount.sms_2fa_request().

async sms_2fa_submit(phone_number_id: int, code: str) findmy.reports.state.LoginState#

See BaseAppleAccount.sms_2fa_submit().

async td_2fa_request() None#

See BaseAppleAccount.td_2fa_request().

async td_2fa_submit(code: str) findmy.reports.state.LoginState#

See BaseAppleAccount.td_2fa_submit().

async fetch_raw_reports(devices: list[tuple[list[str], list[str]]]) list[findmy.reports.reports.LocationReport]#

Make a request for location reports, returning raw data.

async fetch_location_history(keys: findmy.keys.HasHashedPublicKey) list[findmy.reports.reports.LocationReport]#
async fetch_location_history(keys: findmy.accessory.RollingKeyPairSource) list[findmy.reports.reports.LocationReport]
async fetch_location_history(keys: collections.abc.Sequence[findmy.keys.HasHashedPublicKey | findmy.accessory.RollingKeyPairSource]) dict[findmy.keys.HasHashedPublicKey | findmy.accessory.RollingKeyPairSource, list[findmy.reports.reports.LocationReport]]

See BaseAppleAccount.fetch_location_history.

async fetch_location(keys: findmy.keys.HasHashedPublicKey) findmy.reports.reports.LocationReport | None#
async fetch_location(keys: findmy.accessory.RollingKeyPairSource) findmy.reports.reports.LocationReport | None
async fetch_location(keys: collections.abc.Sequence[findmy.keys.HasHashedPublicKey | findmy.accessory.RollingKeyPairSource]) dict[findmy.keys.HasHashedPublicKey | findmy.accessory.RollingKeyPairSource, findmy.reports.reports.LocationReport | None]

See BaseAppleAccount.fetch_location().

async get_anisette_headers(with_client_info: bool = False, serial: str = '0') dict[str, str]#

See BaseAppleAccount.get_anisette_headers().

class findmy.reports.account.AppleAccount(anisette: findmy.reports.anisette.BaseAnisetteProvider, *, state_info: AccountStateMapping | None = None)#

Bases: BaseAppleAccount

Inheritance diagram of findmy.reports.account.AppleAccount

A sync implementation of BaseappleAccount().

Uses AsyncappleAccount() internally.

async close() None#

See AsyncAppleAccount.close().

property login_state: findmy.reports.state.LoginState#

See AsyncAppleAccount.login_state().

property account_name: str | None#

See AsyncAppleAccount.login_state().

property first_name: str | None#

See AsyncAppleAccount.first_name().

property last_name: str | None#

See AsyncAppleAccount.last_name().

to_json(dst: str | pathlib.Path | None = None, /) AccountStateMapping#

Export the current state of the object as a JSON-serializable dictionary.

If an argument is provided, the output will also be written to that file.

The output of this method is guaranteed to be JSON-serializable, and passing the return value of this function as an argument to Serializable.from_json() will always result in an exact copy of the internal state as it was when exported.

You are encouraged to save and load object states to and from disk whenever possible, to prevent unnecessary API calls or otherwise unexpected behavior.

classmethod from_json(val: str | pathlib.Path | AccountStateMapping, /, *, anisette_libs_path: str | pathlib.Path | None = None) AppleAccount#

Restore state from a previous Closable.to_json() export.

If given a str or Path, it must point to a json file from Serializable.to_json(). Otherwise, it should be the Mapping itself.

See Serializable.to_json() for more information.

login(username: str, password: str) findmy.reports.state.LoginState#

See AsyncAppleAccount.login().

get_2fa_methods() collections.abc.Sequence[findmy.reports.twofactor.SyncSecondFactorMethod]#

See AsyncAppleAccount.get_2fa_methods().

sms_2fa_request(phone_number_id: int) None#

See AsyncAppleAccount.sms_2fa_request().

sms_2fa_submit(phone_number_id: int, code: str) findmy.reports.state.LoginState#

See AsyncAppleAccount.sms_2fa_submit().

td_2fa_request() None#

See AsyncAppleAccount.td_2fa_request().

td_2fa_submit(code: str) findmy.reports.state.LoginState#

See AsyncAppleAccount.td_2fa_submit().

fetch_location_history(keys: findmy.keys.HasHashedPublicKey) list[findmy.reports.reports.LocationReport]#
fetch_location_history(keys: findmy.accessory.RollingKeyPairSource) list[findmy.reports.reports.LocationReport]
fetch_location_history(keys: collections.abc.Sequence[findmy.keys.HasHashedPublicKey | findmy.accessory.RollingKeyPairSource]) dict[findmy.keys.HasHashedPublicKey | findmy.accessory.RollingKeyPairSource, list[findmy.reports.reports.LocationReport]]

See BaseAppleAccount.fetch_location_history.

fetch_location(keys: findmy.keys.HasHashedPublicKey) findmy.reports.reports.LocationReport | None#
fetch_location(keys: findmy.accessory.RollingKeyPairSource) findmy.reports.reports.LocationReport | None
fetch_location(keys: collections.abc.Sequence[findmy.keys.HasHashedPublicKey | findmy.accessory.RollingKeyPairSource]) dict[findmy.keys.HasHashedPublicKey | findmy.accessory.RollingKeyPairSource, findmy.reports.reports.LocationReport | None]

See BaseAppleAccount.fetch_location().

get_anisette_headers(with_client_info: bool = False, serial: str = '0') dict[str, str]#

See AsyncAppleAccount.get_anisette_headers().