Integrate your Python code with the Marqeta Core API using the Marqeta Software Developer Kit (SDK) for Python.
Hidden
Note
This feature is currently in beta and subject to change. To learn more about the Beta program for this feature, contact your Marqeta representative.
The Marqeta Software Developer Kit (SDK) for Python provides easy access to the Marqeta Core API from your Python application. The Python SDK is built on top of the Core API, providing wrappers for the REST API endpoints.
This section describes the basics of how to use the SDK, including configuration and basic operations. For a list of objects, see Resources. For usage specifics for each object, see Using the Python SDK.
Create an account on marqeta.com to retrieve your application token and access token for your public sandbox environment. Note that the base_url in the example below is for the public sandbox. For production or a private sandbox environment, you will need to update the base_url.To configure your client object:
Depending on your use case, there are several ways to retrieve collections of objects. The Python library handles pagination for you, unless you request a specific page of data. To retrieve every object in a collection, call list(limit=None) on the resource:
Python
users = client.users.list(limit=None)
If a value is specified for limit, objects up to that number are returned. For most cases the default value of limit is None; however, for client.users.list() and client.card_products.list() the default values are 1000 and 25 respectively.The stream() method returns a generator that efficiently downloads subsequent pages as needed, rather than download all objects into memory at once:
Python
for user in client.users.stream(): pass
To retrieve a single page, call the page() method and specify values for start_index and count:
Most methods support additional query parameters as a params dictionary. The keys and values are the same as those described for each endpoint in the Core API Reference:
The following sections show the basic method usage for each of the Python objects. For details on the REST API, including input and return values, see the Core API Reference.
Use the account_holder_groups object to manage groups of multiple account holders. For details on account holder groups, including available parameters, see /accountholdergroups in the Core API Reference. The following code examples show basic usage of the account_holder_groups methods.
Python
# Create an account holder groupaccount_holder_group = client.account_holder_groups.create({...})# Retrieve a specific account holder groupaccount_holder_group = client.account_holder_groups.find(token)# Update an account holder groupaccount_holder_group = client.account_holder_groups.save(token, {...})# List all account holder groupsaccount_holder_groups = client.account_holder_groups.list()for account_holder_group in client.account_holder_groups.stream(): passaccount_holder_groups_page = client.account_holder_groups.page(start_index=0)
Use the auth_controls object to manage authorization controls, which are spend controls that limit where users can transact. For details, including available parameters, see /authcontrols in the Core API Reference. The following code examples show basic usage of the auth_controls methods.
Python
# Create an auth controlauth_control = client.auth_controls.create({...})# Retrieve a specific auth controlauth_control = client.auth_controls.find(token)# Update an auth controlauth_control = client.auth_controls.save(token, {...})# List all auth controlsauth_controls = client.auth_controls.list()for auth_control in client.auth_controls.stream(): passauth_controls_page = client.auth_controls.page(start_index=0)
Use the auth_controls.exempt_mids object to manage exemptions of Merchant Identifier numbers (MIDs) from authorization controls. Transactions originating from an exempt MID ignore otherwise applicable authorization controls. For details, including input parameters, see the /authcontrols/exemptmids endpoint in the Core API Reference. The following code examples show basic usage of the auth_controls.exempt_mids methods.
Python
# Create an exempt MIDexempt_mid = client.auth_controls.exempt_mids.create({...})# Retrieve a specific exempt MIDexempt_mid = client.auth_controls.exempt_mids.find(token)# Update an exempt MIDexempt_mid = client.auth_controls.exempt_mids.save(token, {...})# List all exempt MIDsexempt_mi_ds = client.auth_controls.exempt_mids.list()for exempt_mid in client.auth_controls.exempt_mids.stream(): passexempt_mi_ds_page = client.auth_controls.exempt_mids.page(start_index=0)
Use the auto_reloads object to automatically load a specified amount of funding into a GPA account when the balance falls below a defined threshold. Transactions originating from an exempt MID ignore otherwise applicable authorization controls. For details, including input parameters, see the /autoreloads endpoint in the Core API Reference. The following code examples show basic usage of the auto_reloads methods.
Python
# Create an autoreloadautoreload = client.auto_reloads.create({...})# Retrieve a specific autoreloadautoreload = client.auto_reloads.find(token)# Update an autoreloadautoreload = client.auto_reloads.save(token, {...})# List all autoreloadsautoreloads = client.auto_reloads.list()for autoreload in client.auto_reloads.stream(): passautoreloads_page = client.auto_reloads.page(start_index=0)
Use the balances object to retrieve a specifc balance. For details, including available parameters, see the /balances endpoint in the Core API Reference. The following code examples show basic usage of the balances methods.
Python
# Retrieve a specific balancebalance = client.balances.find_for_user_or_business(token)
Use the bulk_issuances object to manage bulk card orders. For details, including input parameters, see the /bulkissuances endpoint in the Core API Reference. The following code examples show basic usage of the bulk_issuances methods.
Python
# Create a bulk issuancebulk_issuance = client.bulk_issuances.create({...})# Retrieve a specific bulk issuancebulk_issuance = client.bulk_issuances.find(token)# List all bulk issuancesbulk_issuances = client.bulk_issuances.list()for bulk_issuance in client.bulk_issuances.stream(): passbulk_issuances_page = client.bulk_issuances.page(start_index=0)
Use the businesses object to manage businesses on the Marqeta platform. For details, including input parameters, see the /businesses endpoint in the Core API Reference. The following code examples show basic usage of the businesses methods.
Python
# Create a businessbusiness = client.businesses.create({...})# Retrieve a specific businessbusiness = client.businesses.find(token)# Update a businessbusiness = client.businesses.save(token, {...})# List all businessesbusinesses = client.businesses.list()for business in client.businesses.stream(): passbusinesses_page = client.businesses.page(start_index=0)# Retrieve a specific business SSNssn = client.businesses(token).ssn()# Retrieve a specific business Full SSNssn = client.businesses(token).ssn(full_ssn = True)# List all children of parent businesschild_cardholders = client.businesses(token).children.list()for child_cardholder in client.businesses(token).children.stream(): passchild_cardholders_page = client.businesses(token).children.page(start_index=0)# Search for businessesbusinesses = client.businesses.look_up({...})
Use the businesses(business_token).transitions object to manage business transitions. For details, including input parameters, see the /businesstransitions endpoint in the Core API Reference. The following code examples show basic usage of the businesses(business_token).transitions methods.
Python
# Create a business transitiontransition = client.businesses(business_token).transitions.create(...)# Retrieve a specific business transitiontransition = client.businesses(business_token).transitions.find(token)# List transitions for a specific businesstransitions = client.businesses(business_token).transitions.list()for transition in client.businesses(business_token).transitions.stream(): passtransitions_page = client.businesses(business_token).transitions.page(start_index=0)
Use the /card_products object to manage the behavior and functionality of one or more physical or virtual cards. For details, including input parameter, see /cardproducts in the Core API Reference. The following code examples show basic usage of the card_products methods.
Python
# Create a card productcard_product = client.card_products.create({...})# Retrieve a specific card productcard_product = client.card_products.find(token)# Update a card productcard_product = client.card_products.save(token, {...})# List all card products. Default limit is 25.card_products = client.card_products.list()for card_product in client.card_products.stream(): passcard_products_page = client.card_products.page(start_index=0)
Use the /cards object to manage the behavior and functionality of one or more physical or virtual cards. For details, including input descriptions, see /cards in the Core API Reference. The following code examples show basic usage of the cards methods.
Python
# Create a carddata = {...}card = client.cards.create(data)# Create a merchant onboarding carddata = {...}card = client.cards.create_for_merchant(token, data)# Return a specific cardcard = client.cards.find(token)# Return a specific card - PAN visiblecard = client.cards.find_show_pan(token)# Retrieve a card by its barcodecard = client.cards.find_by_barcode(barcode)# Return the user and card tokens for a specified PANtokens = client.cards.tokens_for_pan(pan)# Return a merchant onboarding cardcard = client.cards.find_for_merchant(token)# Return a specific card - PAN visiblecard = client.cards.find_for_merchant_show_pan(token)# Update a carddata = {...}card = client.cards.save(data)# List cards by last 4cards = client.cards.list(last_four='6789')for card in client.cards.stream(): passcards_page = client.cards.page()# List all cards for one usercards = client.cards.list_for_user(token)for card in client.cards.stream_for_user(token): pass
Use the cards(token).transitions object to manage card transitions. For details, including input parameters, see the /cardtransitions endpoint in the Core API Reference. The following code examples show basic usage of the cards(token).transitions methods.
Python
# Create a card transitiontransition = client.cards(token).transitions.create(...)# Retrieve a specific card transitiontransition = client.cards(token).transitions.find(token)# List transitions for a specific cardtransitions = client.cards(token).transitions.list()for transition in client.cards(token).transitions.stream(): passtransitions_page = client.cards(token).transitions.page(start_index=0)
Use the commando_modes object to manage the Commando Modes fallback measure that ensures Gateway JIT-funded cards continue to function in the event your system fails. For details, including input parameters, see the /commandomodes endpoint in the Core API Reference. The following code examples show basic usage of the commando_modes methods.
Python
# Retrieve a specific Commando Modecommando_mode = client.commando_modes.find(token)# List all Commando Modescommando_modes = client.commando_modes.list()for commando_mode in client.commando_modes.stream(): passcommando_modes_page = client.commando_modes.page(start_index=0)
Use the commando_modes(token) object to manage Commando Mode transitions. For details, including input parameters, see the Commando Mode documentation in the Core API Reference. The following code examples show basic usage of the commando_modes(token) methods.
Python
# Retrieve a specific Commando Mode transitiontransition = client.commando_modes(token).transitions.find(token)# List transitions for a specific Commando Modetransitions = client.commando_modes(token).transitions.list()for transition in client.commando_modes(token).transitions.stream(): passtransitions_page = client.commando_modes(token).transitions.page(start_index=0)
Use the digital_wallet_tokens object to manage digital wallet tokens. For details, including input parameters, see the /digitalwallettokens/ endpoint in the Core API Reference. The following code examples show basic usage of the digital_wallet_tokens methods.
Python
# Retrieve a specific digital wallet tokendigital_wallet_token = client.digital_wallet_tokens.find(token)# Retrieve a specific digital wallet token with PANdigital_wallet_token = client.digital_wallet_tokens.find_show_pan(token)# List all digital wallet tokensdigital_wallet_tokens = client.digital_wallet_tokens.list()for digital_wallet_token in client.digital_wallet_tokens.stream(): passdigital_wallet_tokens_page = client.digital_wallet_tokens.page(start_index=0)
Use the digital_wallet_tokens(token).transitions object to manage digital wallet token transitions. For details, including input parameters, see the /digitalwallettokentransitions endpoint in the Core API Reference. The following code examples show basic usage of the digital_wallet_tokens(token).transitions methods.
Python
# Create a digital wallet token transitiontransition = client.digital_wallet_tokens(token).transitions.create(...)# Retrieve a specific digital wallet token transitiontransition = client.digital_wallet_tokens(token).transitions.find(token)# List transitions for a specific digital wallet tokentransitions = client.digital_wallet_tokens(token).transitions.list()for transition in client.digital_wallet_tokens(token).transitions.stream(): passtransitions_page = client.digital_wallet_tokens(token).transitions.page(start_index=0)
Use the direct_deposits object to manage direct deposits. For details, including input parameters, see the /directdeposits endpoint in the Core API Reference. The following code examples show basic usage of the direct_deposits methods.
Python
# Retrieve a specific direct depositdirect_deposit = client.direct_deposits.find(token)# List all direct depositsdirect_deposits = client.direct_deposits.list()for direct_deposit in client.direct_deposits.stream(): passdirect_deposits_page = client.direct_deposits.page(start_index=0)
Use the direct_deposits(token).transitions object to manage direct deposit transitions. For details, including input parameters, see the /directdeposits/transitions endpoint in the Core API Reference. The following code examples show basic usage of the direct_deposits(token).transitions methods.
Python
# Create a direct deposit transitiontransition = client.direct_deposits(token).transitions.create(...)# Retrieve a specific direct deposit transitiontransition = client.direct_deposits(token).transitions.find(token)# List transitions for a specific direct deposittransitions = client.direct_deposits(token).transitions.list()for transition in client.direct_deposits(token).transitions.stream(): passtransitions_page = client.direct_deposits(token).transitions.page(start_index=0)
Use the funding_sources.addresses object to manage funding source addresses. For details, including input parameters, see the /fundingsources/addresses endpoint in the Core API Reference. The following code examples show basic usage of the funding_sources.addresses methods.
Python
# Create a funding source addressfunding_source_address = client.funding_sources.addresses.create({...})# Retrieve a specific funding source addressfunding_source_address = client.funding_sources.addresses.find(token)# Update a funding source addressfunding_source_address = client.funding_sources.addresses.save(token, {...})# list funding source addresses for a specific useraddresses = client.funding_sources.addresses.list_for_user(user_token)for address in client.funding_sources.addresses.stream_for_user(user_token) pass# list funding source addresses for a specific businessaddresses = client.funding_sources.addresses.list_for_business(business_token)for address in client.funding_sources.addresses.stream_for_business(business_token) pass
Use the funding_sources.ach object to manage funding source addresses. For details, including input parameters, see the /fundingsources/ach endpoint in the Core API Reference. The following code examples show basic usage of the funding_sources.ach methods.
Python
# Create an ACH funding sourceach_funding_source = client.funding_sources.ach.create({...})# Retrieve a specific ACH funding sourceach_funding_source = client.funding_sources.ach.find(token)# Retrieve the dollar amounts used to verify an ACH funding sourceclient.funding_sources.addresses(token).verification_amounts()# Update an ACH funding sourceach_funding_source = client.funding_sources.ach.save(token, {...})
Use the funding_sources.payment_card object to manage funding sources for payment cards. For details, including input parameters, see the /fundingsources/paymentcard endpoint in the Core API Reference. The following code examples show basic usage of the funding_sources.payment_card methods.
Python
# Create a payment card funding sourcepayment_card_funding_source = client.funding_sources.payment_card.create({...})# Retrieve a specific payment card funding sourcepayment_card_funding_source = client.funding_sources.payment_card.find(token)# Update a payment card funding sourcepayment_card_funding_source = client.funding_sources.payment_card.save(token, {...})
Use the funding_sources.program_gateway object to manage program gateway funding sources. For details, including input parameters, see the /fundingsources/programgateway endpoint in the Core API Reference. The following code examples show basic usage of the funding_sources.program_gateway methods.
Python
# Create a program gateway funding sourceprogram_gateway_funding_source = client.funding_sources.program_gateway.create({...})# Retrieve a specific program gateway funding sourceprogram_gateway_funding_source = client.funding_sources.program_gateway.find(token)# Update a program gateway funding sourceprogram_gateway_funding_source = client.funding_sources.program_gateway.save(token, {...})
Use the funding_sources.program object to manage program funding sources. For details, including input parameters, see the /fundingsources/program endpoint in the Core API Reference. The following code examples show basic usage of the funding_sources.program methods.
Python
# Create a program funding sourceprogram_funding_source = client.funding_sources.program.create({...})# Retrieve a specific program funding sourceprogram_funding_source = client.funding_sources.program.find(token)# Update a program funding sourceprogram_funding_source = client.funding_sources.program.save(token, {...})
Use the gpa_orders object to manage GPA orders. For details, including input parameters, see the /gpaorders endpoint in the Core API Reference. The following code examples show basic usage of the gpa_orders methods.
Python
# Create a GPA ordergpa_order = client.gpa_orders.create({...})# Retrieve a specific GPA ordergpa_order = client.gpa_orders.find(token)
Use the gpa_orders.unloads object to manage GPA orders. For details, including input parameters, see the /gpaorders/unloads endpoint in the Core API Reference. The following code examples show basic usage of the gpa_orders.unloads methods.
Python
# Create a GPA returngpa_return = client.gpa_orders.unloads.create({...})# Retrieve a specific GPA returngpa_return = client.gpa_orders.unloads.find(token)# List all GPA returnsgpa_returns = client.gpa_orders.unloads.list()for gpa_return in client.gpa_orders.unloads.stream(): passgpa_returns_page = client.gpa_orders.unloads.page(start_index=0)
Use the kyc object to manage KYC. For details, including input parameters, see the /kyc endpoint in the Core API Reference. The following code examples show basic usage of the kyc methods.
Python
# Retrieve a specific KYC resultkyc = client.kyc.find(token)# Update KYC answersclient.kyc.save(token, {...})# Perform a KYC operationclient.kyc.create({...})# List KYC results for a specific userkyc_results = client.kyc.list_for_user(user_token)for kyc_result in client.kyc.stream_for_user(user_token): pass# List KYC results for a specific businesskyc_results = client.kyc.list_for_business(business_token)for kyc_result in client.kyc.stream_for_business(business_token): pass
Use the mcc_groups object to manage MCC groups. For details, including input parameters, see the /mccgroups endpoint in the Core API Reference. The following code examples show basic usage of the mcc_groups methods.
Python
# Create an MCC groupmcc_group = client.mcc_groups.create({...})# Retrieve a specific MCC groupmcc_group = client.mcc_groups.find(token)# Update an MCC groupmcc_group = client.mcc_groups.save(token, {...})# List all MCC groupsmcc_groups = client.mcc_groups.list()for mcc_group in client.mcc_groups.stream(): passmcc_groups_page = client.mcc_groups.page(start_index=0)
Use the program_transfers objects to manage program transfers. For details, including input parameters, see the /programtransfers endpoint in the Core API Reference. The following code examples show basic usage of the program_transfers methods.
Python
# Create a program transferprogram_transfer = client.program_transfers.create({...})# Retrieve a specific program transferprogram_transfer = client.program_transfers.find(token)# List all program transfersprogram_transfers = client.program_transfers.list()for program_transfer in client.program_transfers.stream(): passprogram_transfers_page = client.program_transfers.page(start_index=0)
Use the program_transfers.types object to manage program transfer types. For details, including input parameters, see the /programtransfers/types endpoint in the Core API Reference. The following code examples show basic usage of the program_transfers.types methods.
Python
# Create a program transfer typeprogram_transfer_type = client.program_transfers.types.create({...})# Retrieve a specific program transfer typeprogram_transfer_type = client.program_transfers.types.find(token)# Update a program transfer typeprogram_transfer_type = client.program_transfers.types.save(token, {...})# List all program transfer typesprogram_transfer_types = client.program_transfers.types.list()for program_transfer_type in client.program_transfers.types.stream(): passprogram_transfer_types_page = client.program_transfers.types.page(start_index=0)
Use the push_to_cards object to manage Push-to-Card payment cards. For details, including input parameters, see the /pushtocards endpoint in the Core API Reference. The following code examples show basic usage of the push_to_cards methods.
Python
# Create a push-to-cardpush_to_card = client.push_to_cards.create({...})# Retrieve a specific push-to-cardpush_to_card = client.push_to_cards.find(token)# Update a push-to-cardpush_to_card = client.push_to_cards.save(token, {...})# List all push-to-cardspush_to_cards = client.push_to_cards.list()for push_to_card in client.push_to_cards.stream(): passpush_to_cards_page = client.push_to_cards.page(start_index=0)
Use the push_to_cards.disburse object to manage Push-to-Card disbursements. For details, including input parameters, see the /pushtocards/disburse endpoint in the Core API Reference. The following code examples show basic usage of the push_to_cards.disburse methods.
Python
# Create a push-to-card disbursementpush_to_card_disbursement = client.push_to_cards.disburse.create({...})# Retrieve a specific push-to-card disbursementpush_to_card_disbursement = client.push_to_cards.disburse.find(token)# List all push-to-card disbursementspush_to_card_disbursements = client.push_to_cards.disburse.list()for push_to_card_disbursement in client.push_to_cards.disburse.stream(): passpush_to_card_disbursements_page = client.push_to_cards.disburse.page(start_index=0)
Use the push_to_cards.payment_card object to manage Push-to-Card disbursements. For details, including input parameters, see the /pushtocards/paymentcard endpoint in the Core API Reference. The following code examples show basic usage of the push_to_cards.payment_card methods.
Python
# Create a push-to-card payment cardpush_to_card_payment_card = client.push_to_cards.payment_card.create({...})# Retrieve a specific push-to-card payment cardpush_to_card_payment_card = client.push_to_cards.payment_card.find(token)# List all push-to-card payment cardspush_to_card_payment_cards = client.push_to_cards.payment_card.list()for push_to_card_payment_card in client.push_to_cards.payment_card.stream(): passpush_to_card_payment_cards_page = client.push_to_cards.payment_card.page(start_index=0)
Use the transactions object to manage transactions. For details, including input parameters, see the /transactions endpoint in the Core API Reference. The following code examples show basic usage of the transactions methods.
Python
# Retrieve a specific transactiontransaction = client.transactions.find(token)# List all transactionstransactions = client.transactions.list()for transaction in client.transactions.stream(): passtransactions_page = client.transactions.page(start_index=0)# List all transactions for a specific funding sourcetransactions = client.transactions.list_for_funding_source(funding_source_token)for transaction in client.transactions.stream_for_funding_source(funding_source_token): pass
Use the transactions(token).related object to manage related transactions. For details, including input parameters, see the /transactions//related endpoint in the Core API Reference. The following code examples show basic usage of the transactions(token).related methods.
Python
# List all related transactionsrelated_transactions = client.transactions(token).related.list()for related_transaction in client.transactions(token).related.stream(): passrelated_transactions_page = client.transactions(token).related.page(start_index=0)
Use the users object to manage users. For details, including input parameters, see the /users endpoint in the Core API Reference. The following code examples show basic usage of the users methods.
Python
# Create a useruser = client.users.create({...})# Retrieve a specific useruser = client.users.find(token)# Update a useruser = client.users.save(token, {...})# Retrieve a specific user SSNssn = client.users(token).ssn()# Retrieve a specific user Full SSNssn = client.users(token).ssn(full_ssn = True)# List all users. Default limit is 1000.users = client.users.list()for user in client.users.stream(): passusers_page = client.users.page(start_index=0)# List all children of parent userchild_cardholders = client.users(token).children.list()for child_cardholder in client.users(token).children.stream(): passchild_cardholders_page = client.users(token).children.page(start_index=0)# Search for users, if look_up data is not specified by default lists 1000 usersusers = client.users.look_up({...})
Use the users(token).transitions object to manage user transitions. For details, including input parameters, see the /usertransitions endpoint in the Core API Reference. The following code examples show basic usage of the users(token).transitions methods.
Python
# Create a user transitiontransition = client.users(token).transitions.create(...)# Retrieve a specific user transitiontransition = client.users(token).transitions.find(token)# List transitions for a specific usertransitions = client.users(token).transitions.list()for transition in client.users(token).transitions.stream(): passtransitions_page = client.users(token).transitions.page(start_index=0)
Use the velocity_controls object to manage velocity controls. For details, including input parameters, see the /velocitycontrols endpoint in the Core API Reference. The following code examples show basic usage of the velocity_controls methods.
Python
# Create a velocity controlvelocity_control = client.velocity_controls.create({...})# Retrieve a specific velocity controlvelocity_control = client.velocity_controls.find(token)# Update a velocity controlvelocity_control = client.velocity_controls.save(token, {...})# List all velocity controlsvelocity_controls = client.velocity_controls.list()for velocity_control in client.velocity_controls.stream(): passvelocity_controls_page = client.velocity_controls.page(start_index=0)# List velocity controls available for a specific uservelocity_controls = list_available_for_user(user_token)for velocity_control in stream_available_for_user(user_token): pass
Use the webhooks object to manage webhooks. For details, including input parameters, see the /webhooks endpoint in the Core API Reference. The following code examples show basic usage of the webhooks methods.
Python
# Create a webhookwebhook = client.webhooks.create({...})# Retrieve a specific webhookwebhook = client.webhooks.find(token)# Update a webhookwebhook = client.webhooks.save(token, {...})# Ping a webhookclient.webhooks(token).ping()# Resend a webhookclient.webhooks(token).resent(event_type, event_token)# List all webhookswebhooks = client.webhooks.list()for webhook in client.webhooks.stream(): passwebhooks_page = client.webhooks.page(start_index=0)