Quickstart

Quickstart: call the Credicorp public API from Python

With the requests library you can call the Credicorp public API in about ten lines of Python. This quickstart lists the live products from GET /public/v1/products, unwraps the data envelope and turns the documented error shape into a Python exception you can catch.

2 min read

requestsOr httpx for async
raiseTurn error envelope into an exception
dataUnwrap the list envelope

List products

The whole call, including error handling, fits on a screen:

import requests

BASE = 'https://api.credicorp.co.uk/public/v1'

def list_products():
    r = requests.get(f'{BASE}/products',
                     headers={'Accept': 'application/json'},
                     timeout=10)
    body = r.json()
    if r.status_code >= 400:
        err = body.get('error', {})
        raise RuntimeError(f"{r.status_code} {err.get('code')}: {err.get('message')}")
    return body['data']

for product in list_products():
    print(f"{product['name']} \u2014 up to \u00a3{product['max_amount']:,}")

Async with httpx

If your service is async, httpx uses the same interface:

import httpx

async def list_products():
    async with httpx.AsyncClient(base_url=BASE, timeout=10) as client:
        r = await client.get('/products',
                             headers={'Accept': 'application/json'})
        r.raise_for_status()
        return r.json()['data']

Configuration

Read the base host from the environment so the same code runs against sandbox and production:

import os
BASE = os.environ.get('CREDICORP_BASE',
                      'https://sandbox.credicorp.co.uk/public/v1')

Frequently asked questions

requests or httpx?

Use requests for simple synchronous scripts. Reach for httpx when you need async, HTTP/2 or a shared connection pool inside a FastAPI or asyncio service.

How do I retry safely?

Wrap the call in a retry with exponential back-off that only retries on 429 and 5xx. The rate-limit recipe shows the exact pattern.

Does the response include pagination?

List endpoints that can return many rows include a next_cursor. See paging through list results.

Funding for UK limited companies

Credicorp lends to your company, not to you personally — short-term working capital with no personal guarantee. See what your business could access.