The list of assets that an account is opted in is provided by the /v2/account/{address}
endpoint.
With the Python SDK, it is given by the account_information
function of the V2 client.
Here is an example using the Algoexplorer TestNet API on the account GD7CZ4NH4PBZ75BSGBNXC76CYGEGEYVXYNGVNNWOYY33S64NV7VEISFGKE
that is opted in asset ID 10458941 but not in asset ID 10 (at least when the post was written):
import algosdk.v2client
algod_address = "https://node.testnet.algoexplorerapi.io"
algod_token = ""
client = algosdk.v2client.algod.AlgodClient(algod_token, algod_address)
account = client.account_info("GD7CZ4NH4PBZ75BSGBNXC76CYGEGEYVXYNGVNNWOYY33S64NV7VEISFGKE")
def is_account_opted_in(account: dict, asset_id: int):
return any(asset["asset-id"] == asset_id for asset in account["assets"])
print(is_account_opted_in(account, 10458941))
print(is_account_opted_in(account, 10))