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 Managerclient_id— your API account's client IDprivate_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:
- Devices —
get_org_devices,get_org_device,get_org_device_apple_care_coverage,get_mdm_devices,get_mdm_device_details - Device Management Services —
get_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 - Users —
get_users,get_user - User Groups —
get_user_groups,get_user_group,get_user_group_user_ids - Apps & Packages —
get_apps,get_app,get_packages,get_package - Blueprints —
get_blueprints,create_blueprint,get_blueprint,update_blueprint,delete_blueprint, andget_blueprint_<rel>_idsadd_<rel>_to_blueprint/remove_<rel>_from_blueprintforapps,configurations,packages,org_devices,users,user_groups - Configurations —
get_configurations,create_configuration,get_configuration,update_configuration,delete_configuration - Audit —
get_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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file applebusiness-0.2.0.tar.gz.
File metadata
- Download URL: applebusiness-0.2.0.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb4d092128b8f811fe7747045064b82c196c6f0879e3f97b87a881d57e8102e5
|
|
| MD5 |
83a270976eab2828f0c63c6470635ea8
|
|
| BLAKE2b-256 |
50e0276b173f193fb63203c72052b5d725fc8ed57a8bced38391a04eeec9fd64
|
Provenance
The following attestation bundles were made for applebusiness-0.2.0.tar.gz:
Publisher:
publish.yml on merlinz01/applebusiness
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
applebusiness-0.2.0.tar.gz -
Subject digest:
bb4d092128b8f811fe7747045064b82c196c6f0879e3f97b87a881d57e8102e5 - Sigstore transparency entry: 1606156721
- Sigstore integration time:
-
Permalink:
merlinz01/applebusiness@1553e46260c9e221411888d065b550aa174fda82 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/merlinz01
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1553e46260c9e221411888d065b550aa174fda82 -
Trigger Event:
push
-
Statement type:
File details
Details for the file applebusiness-0.2.0-py3-none-any.whl.
File metadata
- Download URL: applebusiness-0.2.0-py3-none-any.whl
- Upload date:
- Size: 13.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
55c72bbaf7a92dea7837668ba0547d51277f1db602ca55145ea8f536192b3375
|
|
| MD5 |
fb08b5d02c7b7e0b081ef4bab12e61a8
|
|
| BLAKE2b-256 |
8219952ab7e051c3e44df52a8350b4d1b441a5e0ee51400ae19edbc76a878113
|
Provenance
The following attestation bundles were made for applebusiness-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on merlinz01/applebusiness
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
applebusiness-0.2.0-py3-none-any.whl -
Subject digest:
55c72bbaf7a92dea7837668ba0547d51277f1db602ca55145ea8f536192b3375 - Sigstore transparency entry: 1606156925
- Sigstore integration time:
-
Permalink:
merlinz01/applebusiness@1553e46260c9e221411888d065b550aa174fda82 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/merlinz01
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1553e46260c9e221411888d065b550aa174fda82 -
Trigger Event:
push
-
Statement type: