The Python SDK to work with the App Store Connect API from Apple.
Project description
applaud
applaud
is a Python client library for accessing App Store Connect API, generated by applaudgen.
Features
- Support App Store Connect API latest version 1.6
- Support
filter
,fileds
,include
,limit
,sort
,exists
and other query parameters - All endpoints / paths are implemented, include, but not limited to: App Information, TestFlight, Users and Roles, Sales and Finances
- Pythonic, all
camelCase
schema fields are represented assnake_case
class attributes - Embrace Python type hints
- Use Python Requests to hanlde HTTP sessions
- ErrorResponse can be catched as exception
Installation
Install with pip
:
pip install applaud
Install with Poetry:
poetry add applaud
Install with Pipenv:
pipenv install applaud
Usage
Calls to the API require authorization, so before we get started, you obtain keys to create the tokens from your organization’s App Store Connect account. See Creating API Keys for App Store Connect API to create your keys and tokens.
Connection
Connection
is the core class of applaud
, it holds a connection between client and remote service, generate a new token before it expires.
from applaud.connection import Connection
# Create a connection object using API keys
connection = Connection(APPSTORE_ISSUER_ID, APPSTORE_KEY_ID, APPSTORE_PRIVATE_KEY)
In most of cases, all tasks you'd like to perform on remote service should be initiated from a Connection
object. Connection
has a bunch of functions help you create …Endpoint
objects:
# Return an AppListEndpoint object
connection.apps()
Endpoint
A …Endpoint
class encapsulates all operations you can perform on a specific resource. For example, this snippet fetches first two (sort by app name) apps that "ready for sale" and have game center enabled versions:
# Return an AppsResponse object
connection.apps().filter(
app_store_versions_app_store_state=AppStoreVersionState.READY_FOR_SALE
).exists(
game_center_enabled_versions=True
).limit(
2
).sort(
name: SortOrder.ASC
).get()
…Endpoint.get()
The get()
operation initiates a HTTP GET
request on the endpoint's path. For example, the URL of List Apps service endpoint is:
GET https://api.appstoreconnect.apple.com/v1/apps
The corresponding code in applaud
:
# Return an AppsResponse object
response = connection.apps().get()
for app in response.data:
print(f'{app.attributes.name}: {app.attributes.bundle_id}')
Unlike other operations (create()
, update()
and delete()
), get()
operation can be chained by query parameters functions:
filter()
You use filter()
function to extract matching resources. For example:
filter[bundleId] Attributes, relationships, and IDs by which to filter.
[string]
The corresponding code in applaud
:
response = connection.apps().filter(
bundle_id="com.exmaple.app1"
).get()
# or
connection.apps().filter(
bundle_id=["com.exmaple.app1", "com.exmaple.app2"]
).get()
for app in response.data:
print(f'{app.attributes.name}: {app.attributes.bundle_id}')
include()
You use include()
function to ask relationship data to include in the response. For example:
include Relationship data to include in the response.
[string] Possible values: appClips, appInfos, appStoreVersions,
availableTerritories, betaAppLocalizations,
betaAppReviewDetail, betaGroups, betaLicenseAgreement,
builds, ciProduct, endUserLicenseAgreement,
gameCenterEnabledVersions, inAppPurchases, preOrder,
preReleaseVersions, prices
The corresponding code in applaud
:
response = connection.apps().include(
AppListEndpoint.Include.BETA_LICENSE_AGREEMENT
).get()
# or
response = connection.apps().include(
[AppListEndpoint.Include.BETA_LICENSE_AGREEMENT, AppListEndpoint.Include.PRICES]
).get()
fields()
You use fields()
function to ask fields data to return for included related resources in a get()
operation. Related resources specified in fields()
function MUST be included explicitly in include()
function, otherwise, the remote service may not return the fields data that you expect. For example:
fields[betaLicenseAgreements] Fields to return for included related types.
[string] Possible values: agreementText, app
The corresponding code in applaud
:
connection.apps().include(
AppListEndpoint.Include.BETA_LICENSE_AGREEMENT
).fields(
beta_license_agreement=[BetaLicenseAgreementField.AGREEMENT_TEXT, BetaLicenseAgreementField.APP]
).get()
limit()
You use limit()
function to restrict the maximum number of resources to return in a get()
operation. For example:
limit Number of resources to return.
integer Maximum Value: 200
The corresponding code in applaud
:
# Return a response contains 10 apps at most
connection.apps().limit(10).get()
# Raise a ValueError exception, the maxinmu allowed value is 400
connection.apps().limit(400).get()
You can also included limit the number of related resources to return, as in fields()
function, you MUST also specify the related resources explicitly in include()
function. For example:
limit[appStoreVersions] integer
Maximum Value: 50
The corresponding code in applaud
:
# All returned apps have 5 related app store version at most
connection.apps().include(
AppListEndpoint.Include.APP_STORE_VERSIONS
).limit(app_store_versions=5).get()
# Raise a ValueError exception, the maxinmu allowed value is 50
connection.apps().include(
AppListEndpoint.Include.APP_STORE_VERSIONS
).limit(app_store_versions=100).get()
By leverage limit()
function with sort()
function, your script can be more responsive.
sort()
You use sort()
function to sort the returned resources by attributes in ascending or descending order. For example:
sort Attributes by which to sort.
[string] Possible values: bundleId, -bundleId, name, -name, sku, -sku
The corresponding code in applaud
:
connection.apps().sort(name=SortOrder.ASC, bundleId=SortOrder.DESC).get()
exists()
exists()
is a special type of filter – filter by existence or non-existence of related resource. For example:
exists[gameCenterEnabledVersions] [string]
The corresponding code in applaud
:
connection.apps().exists(game_center_enabled_versions=True).get()
…Endpoint.create()
The create()
operation initiates a HTTP POST
request on the endpoint's path. For example, the URL of Create an App Store Version service endpoint is:
POST https://api.appstoreconnect.apple.com/v1/appStoreVersions
The corresponding code in applaud
:
request = AppStoreVersionCreateRequest(
data = AppStoreVersionCreateRequest.Data(
relationships = AppStoreVersionCreateRequest.Data.Relationships(
app = AppStoreVersionCreateRequest.Data.Relationships.App(
data = AppStoreVersionCreateRequest.Data.Relationships.App.Data(
id = 'com.exmaple.app1'
)
)
),
attributes = AppStoreVersionCreateRequest.Data.Attributes(
version_string = '1.6',
platform = Platform.IOS,
copyright = f'Copyright © 2021 Codinn Technologies. All rights reserved.',
release_type = AppStoreVersionReleaseType.AFTER_APPROVAL
)
)
)
# Return an AppStoreVersionResponse object
reponse = connection.app_store_versions().create(request)
version = response.data
print(f'{version.version_string}: {version.created_date}, {version.app_store_state}')
…Endpoint.update()
The update()
operation initiates a HTTP PATCH
request on the endpoint's path. For example, the URL of Modify an App Store Version service endpoint is:
PATCH https://api.appstoreconnect.apple.com/v1/appStoreVersions/{id}
The corresponding code in applaud
:
# Get the version id created in previous example
version_id = version.data.id
# Update version's information
request = AppStoreVersionUpdateRequest(
data = AppStoreVersionUpdateRequest.Data(
id = version.data.id,
attributes = AppStoreVersionUpdateRequest.Data.Attributes(
version_string = '1.6.1',
platform = Platform.IOS,
copyright = f'Copyright © 2022 Codinn Technologies. All rights reserved.',
release_type = AppStoreVersionReleaseType.AFTER_APPROVAL
)
)
)
# Return an AppStoreVersionResponse object
reponse = connection.app_store_version(version_id).update(request)
version = response.data
print(f'{version.version_string}: {version.copyright}, {version.app_store_state}')
…Endpoint.delete()
The delete()
operation initiates a HTTP DELETE
request on the endpoint's path. For example, the URL of Delete an App Store Version service endpoint is:
DELETE https://api.appstoreconnect.apple.com/v1/appStoreVersions/{id}
The corresponding code in applaud
:
# Get the version id created in previous example
version_id = version.data.id
connection.app_store_version(version_id).delete()
Exceptions
…Endpoint.get()
, …Endpoint.create()
, …Endpoint.update()
and …Endpoint.delete()
may raise two types of exceptions:
- HTTP request exceptions raised by Python Requests
- Remote service returns an ErrorResponse
For the second case, applaud
raises an EndpointException
exception, and attaches all ErrorResponse.Error
objects in EndpointException.errors
attribute.
Some errors are harmless, for example, App Store Connect has no API for you to tell whether a tester has accepted beta test invitation or not. When you trying to resend invitations to testers, you may encounter an ALREADY_ACCEPTED
error, it's safe to just ignore such error:
try:
# Send / resend beta test invitations
response = connection.beta_tester_invitations().create(…)
except EndpointException as err:
already_accepted_error = False
for e in err.errors:
if e.code == 'STATE_ERROR.TESTER_INVITE.ALREADY_ACCEPTED':
# silent this error
already_accepted_error = True
break
if not already_accepted_error:
raise err
Caveats
- Query parameters functions (
filter()
,include
,fields
…) play a role only when using with…Endpoint.get()
. Though there is no side effects if chain it with…Endpoint.create()
,…Endpoint.update()
and…Endpoint.delete()
operations, it is not adviced.
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
File details
Details for the file applaud-0.9.1.tar.gz
.
File metadata
- Download URL: applaud-0.9.1.tar.gz
- Upload date:
- Size: 87.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.9.9 Darwin/21.2.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3be79130cd7b1782e2854ac9cacff6bdc76d0f472f29ac2fe520199402ab77b |
|
MD5 | 86220240d73caf44a0e6ba80031b8f85 |
|
BLAKE2b-256 | dc69e233a98cd087c3d42bfc56494d86ca56bf05084f4b46a4ce429f2dec7c1d |
File details
Details for the file applaud-0.9.1-py3-none-any.whl
.
File metadata
- Download URL: applaud-0.9.1-py3-none-any.whl
- Upload date:
- Size: 146.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.9.9 Darwin/21.2.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4bb3671f57395f6f0660fb1b868b14c2af86158cc2a0b33adbb8865867c73257 |
|
MD5 | 41ece6f661a32e939a33a59139047e6e |
|
BLAKE2b-256 | c34cdd4b5547192effd13f7b2f51d2899e7770e8927ff987b1cac2288093019a |