Metadata-Version: 2.4
Name: adminconsole
Version: 0.1.0
Summary: Python wrapper for Adobe's User Management API
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests>=2.28
Provides-Extra: dev
Requires-Dist: pytest>=7; extra == "dev"
Requires-Dist: ruff>=0.11; extra == "dev"
Requires-Dist: build>=1; extra == "dev"
Dynamic: license-file

# adminconsole

A lightweight Adobe User Management API (UMAPI v2) wrapper using the same
configuration, connector, and camelCase method conventions as `aanalytics2` and
`launchpy`. Only `requests` is required at runtime; neither companion package is needed.
Requires Python 3.10+.

## Documentation

The [documentation index](docs/README.md) includes:

- [Getting started](docs/get-started.md): installation, Adobe credentials, and a first safe request.
- [AdminConsole reference](docs/adminconsole.md): every method, parameter, return value, and example.
- [Configuration](docs/configuration.md): credential files, environment variables, multiple organizations, and proxies.
- [Connector reference](docs/connector.md): authentication, connection reuse, retries, and low-level requests.
- [Workflows](docs/workflows.md): provisioning, membership changes, and exporting users.
- [Troubleshooting](docs/troubleshooting.md): errors, partial batches, permissions, and API limitations.
- [Release notes](docs/releases.md).

## Installation and connection

```powershell
python -m pip install -e .
```

Create an OAuth server-to-server credential with the **User Management API** in
Adobe Developer Console. A system administrator must set up this integration.
JWT authentication is deprecated and is not supported.

```python
import adminconsole as ac

ac.createConfigFile()  # Creates config_adminconsole.json; fill in your credentials.
ac.importConfigFile("config_adminconsole.json")
admin = ac.AdminConsole()

# Alternatively, configure directly (use environment variables for secrets):
# ac.configure(org_id=org_id, client_id=client_id, secret=secret,
#              scopes="openid,AdobeID,user_management_sdk")
```

Use the scopes shown in your Developer Console credential if they differ from the
default. Keep credential files private and out of version control.

`createConfigFile(multi_org=True)` creates a list template. Each entry must have
an `org_name`; select one with `AdminConsole(org_name="production")`. Without
`org_name`, the first configured organization is used, as in `launchpy`.
Both `configure` and `importConfigFile` accept a `proxy` URL for OAuth and API calls.

## Users and groups

```python
users = admin.getUsers()  # Automatically retrieves every page.
user = admin.getUser("person@example.com", domain="example.com")
groups = admin.getGroups()  # Includes product profiles and administrative groups.
group = admin.getGroup("Marketing")
members = admin.getGroupUsers("Marketing")

# Optional refresh and membership filters:
fresh_users = admin.getUsers(refresh=True)
all_memberships = admin.getUsers(directOnly=False)
active_users = admin.getGroupUsers("Product profile", status="active")

admin.updateUser("person@example.com", {"firstname": "Jane", "lastname": "Doe"})
admin.updateGroup("Marketing", name="Marketing Team", description="Updated description")

admin.addUsersToGroup("Marketing Team", ["person@example.com", "other@example.com"])
admin.addGroupsToUser("person@example.com", ["Marketing Team", "Product profile"])
admin.removeUsersFromGroup("Marketing Team", "other@example.com")
admin.removeGroupsFromUser("person@example.com", "Product profile")
admin.addProductProfilesToGroup("Marketing Team", ["Product profile"])
admin.removeProductProfilesFromGroup("Marketing Team", "Product profile")
```

List methods return lists of dictionaries; `getUser` and `getGroup` return a single
dictionary. `getGroup` searches the group listing because UMAPI has no single-group
metadata endpoint; a missing group raises `LookupError`. Group names, usernames,
and organization IDs are URL-encoded.

`getUsers()` and `getGroups()` fetch every page starting from zero and cache the
complete listing on the instance. User caches are separate for each `domain` and
`directOnly` combination. Pass `refresh=True` to either method after external
changes. Non-test writes through `AdminConsole` clear both caches before sending
commands; `testOnly=True` leaves them intact.

`addUsersToGroup` / `removeUsersFromGroup` use user-group commands and accept
emails for a **USER_GROUP**. For product profiles or admin roles, use
`addGroupsToUser` / `removeGroupsFromUser`. Those per-user methods and `updateUser`
accept `domain` and `useAdobeID` to disambiguate identities. Group/profile membership
controls product access; UMAPI cannot grant or remove the system administrator role.

## Creation, removal, and raw actions

```python
admin.createGroup("New team", description="A user group")
admin.createUser(
    "person@example.com",
    {"email": "person@example.com", "firstname": "Jane", "lastname": "Doe", "country": "US"},
    identity_type="federatedID",  # Also: adobeID (default), enterpriseID.
)
# Equivalent identity-specific convenience methods:
admin.createFederatedID(
    "jane",
    {"email": "jane@example.com", "firstname": "Jane", "lastname": "Doe", "country": "US"},
    domain="example.com",
)
admin.createAdobeID("person@example.com", {"email": "person@example.com"})
admin.createEnterpriseID(
    "employee@example.com",
    {"email": "employee@example.com", "firstname": "Jane", "lastname": "Doe"},
)
admin.removeUser("person@example.com")  # Removes org membership, not the account.
admin.deleteGroup("New team")

# Every write method supports testOnly=True for Adobe's validation-only mode:
admin.addGroupsToUser("person@example.com", "Marketing Team", testOnly=True)
responses = admin.executeCommands([
    {"user": "person@example.com", "do": [{"add": {"group": ["Marketing Team"]}}]}
], testOnly=True)
```

Updates, creates, and deletes return Adobe's response dictionary. Membership
helpers and `executeCommands` always return a list of response dictionaries,
one per request. Membership lists and raw command lists are automatically split
at UMAPI's ten-item limit. Raw commands must themselves obey Adobe's per-command
membership limits; use the membership helpers for automatic splitting.

**Failures are explicit:** HTTP failures raise `requests.HTTPError`; API-level
errors and partial action failures raise `UMAPIError`, with the complete Adobe
payload in `exception.response`. Failed batches stop processing; earlier batches
may already have applied changes and are not rolled back. Do not blindly replay a
failed sequence. `testOnly` is Adobe's limited validation mode, not a transaction
or a guarantee that a real write will succeed.

**Restrictions:** Only Enterprise/Federated user information can be updated;
country is immutable. Only user groups can be created, renamed, or deleted,
not product profiles. `removeUser(deleteAccount=True)` may **permanently delete**
organization-owned accounts and assets; it is deliberately disabled by default.

## Connector

`AdobeConnector` is the equivalent of the companion wrappers' `AdobeRequest`
(also exported as an alias). It owns OAuth token acquisition/refresh, JSON
headers, a reusable HTTP session, timeouts, and bounded rate-limit retries.
It honors `Retry-After` seconds or HTTP dates, with exponential backoff/jitter
otherwise. GETs also retry transient server failures; writes are not retried on
server errors or timeouts to avoid duplicate mutations.

```python
with ac.AdminConsole(retry=3, timeout=60) as admin:
    users = admin.getUsers()

# Reuse an existing connection:
connector = ac.AdobeConnector(org_name="production")
admin = ac.AdminConsole(_connector=connector)
# Caller owns injected connectors:
connector.close()
```

The retry budget is per request (three additional attempts by default).
UMAPI quotas are low, especially group queries (five requests/minute), so large
listings may wait on rate limits or exhaust the retry budget. Requests run
sequentially rather than using concurrent pagination.

## Development

```powershell
python -m pip install -e ".[dev]"
python -m pytest
python -m ruff check .
python -m ruff format --check .
python -m build
```

Tests use mocked HTTP/connector responses and never modify an Adobe organization.

[API documentation](https://adobe-apiplatform.github.io/umapi-documentation/en/API_introduction.html)
