The `devicecheck` Python library provides a wrapper for the Apple DeviceCheck API, allowing developers to manage device state and assert app integrity to reduce fraudulent use of services. It supports both synchronous and asynchronous operations. The library is actively maintained, with regular releases, currently at version 1.3.3.
pip install devicecheckVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize the `DeviceCheck` client and validate a device token. It uses environment variables for sensitive Apple credentials, which is a recommended security practice. Remember to obtain `team_id`, `bundle_id`, `key_id`, and the `private_key` path from your Apple Developer account, and set `dev_environment` appropriately for your testing or production environment. The `device_token` must be generated by your iOS application on a physical device.
Refer to the library's GitHub README or documentation for updated decorator usage patterns.
Always set `dev_environment=False` in production deployments and `True` (or omit if default desired) for development/sandbox environments. Use environment variables for configuration.
Test DeviceCheck functionality on actual iOS hardware. Use mock environment variables (e.g., `MOCK_DEVICE_CHECK_DECORATOR_TOKEN`) for local development if real device testing is not feasible for every iteration.
For asyncio, use `from devicecheck.asyncio import AsyncioDeviceCheck`. The rest of the asynchronous network methods will need to be `await`ed.
Store the private key path or content in an environment variable (`APPLE_PRIVATE_KEY_PATH` or `APPLE_PRIVATE_KEY_CONTENT`) and retrieve it at runtime. Ensure proper access controls are on the `.p8` file.
Install the library using pip: `pip install devicecheck` or ensure the correct import statement: `from devicecheck import DeviceCheck` or `from devicecheck.asyncio import AsyncioDeviceCheck`.
Verify that your `team_id`, `bundle_id`, `key_id`, and `private_key` are correct and match the values from your Apple Developer account. Ensure the private key is in the correct format and has not been revoked or expired.
Check the parameters you are passing to the `devicecheck` library methods, particularly when generating or validating tokens. Ensure all required fields are present and correctly formatted according to Apple's DeviceCheck API specifications. Refer to the library's documentation for parameter details.
Ensure the `private_key` argument is a valid string representation of your .p8 key file content and that it is correctly passed to the `DeviceCheck` constructor. Double-check for any leading/trailing whitespace or corrupted characters.
No dependency data recorded yet.