Skip to main content

Async Python client for the Apple Business API

Project description

applebusiness

Async Python client for the Apple Business API.

Install

pip install applebusiness

Requires Python 3.14+.

Authentication

You need an API key generated in Apple Business Manager. The client uses the OAuth 2.0 client-credentials flow with a JWT client assertion signed by your private key. See Implementing OAuth for the Apple School Manager and Apple Business API.

You'll need:

  • key_id — the key identifier from Apple Business Manager
  • client_id — your API account's client ID
  • private_key_pem — the PEM-encoded EC private key

Usage

import asyncio
from applebusiness import Client

async def main():
    async with Client(key_id, client_id, private_key_pem) as client:
        devices = await client.get_org_devices()
        for device in devices.data:
            print(device.id, device.attributes.serialNumber)

asyncio.run(main())

Token caching

By default, OAuth tokens are cached in memory on the Client instance. To share tokens across processes (e.g. via Redis), subclass Client and override _get_cached_token / _set_cached_token:

class RedisClient(Client):
    async def _get_cached_token(self):
        raw = await redis.get("ab-token")
        return json.loads(raw) if raw else None

    async def _set_cached_token(self, token):
        await redis.set("ab-token", json.dumps(token), ex=token["expires_in"])

Coverage

The client implements every Apple Business API endpoint documented as of this release:

  • Devicesget_org_devices, get_org_device, get_org_device_apple_care_coverage, get_mdm_devices, get_mdm_device_details
  • Device Management Servicesget_mdm_servers, get_mdm_server_device_ids, get_org_device_assigned_server_id, get_org_device_assigned_server, assign_devices_to_server, unassign_devices_from_server, get_org_device_activity
  • Usersget_users, get_user
  • User Groupsget_user_groups, get_user_group, get_user_group_user_ids
  • Apps & Packagesget_apps, get_app, get_packages, get_package
  • Blueprintsget_blueprints, create_blueprint, get_blueprint, update_blueprint, delete_blueprint, and get_blueprint_<rel>_ids add_<rel>_to_blueprint / remove_<rel>_from_blueprint for apps, configurations, packages, org_devices, users, user_groups
  • Configurationsget_configurations, create_configuration, get_configuration, update_configuration, delete_configuration
  • Auditget_audit_events

All responses are returned as typed Pydantic models (importable from the top-level applebusiness package).

Activity polling

assign_devices_to_server and unassign_devices_from_server poll the resulting orgDeviceActivity until it leaves IN_PROGRESS. The polling timeout defaults to 300 seconds and raises TimeoutError when exceeded. To skip polling, pass wait=False; to wait indefinitely, pass timeout=None.

Errors

Non-2xx responses raise applebusiness.ClientError, which exposes the HTTP status and parsed ErrorResponse body.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

applebusiness-0.1.2.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

applebusiness-0.1.2-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file applebusiness-0.1.2.tar.gz.

File metadata

  • Download URL: applebusiness-0.1.2.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for applebusiness-0.1.2.tar.gz
Algorithm Hash digest
SHA256 7a1d0757a92f3990caf3a3c26abba28abfeb4698550294e2bc0262ab9e5a8b8c
MD5 2ac0259affb5183db34fb635049a20b0
BLAKE2b-256 20ef5c28f170fa70a2a932b238f0e01e8ceac1e19bc693e6eb8170d6b5415446

See more details on using hashes here.

Provenance

The following attestation bundles were made for applebusiness-0.1.2.tar.gz:

Publisher: publish.yml on merlinz01/applebusiness

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file applebusiness-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: applebusiness-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for applebusiness-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a78a178f953105d75883ad826dcfd082b64c06e55464a60e3eec2910c3e8f27d
MD5 ea8a16c991ef5d00a82c1bf140ebd689
BLAKE2b-256 d326ac0b6092c5d0ce59466781c396734ff65583958d05b8207f4005509a0d3d

See more details on using hashes here.

Provenance

The following attestation bundles were made for applebusiness-0.1.2-py3-none-any.whl:

Publisher: publish.yml on merlinz01/applebusiness

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page