GrabFood Partner API Python SDK

latest (no versioned releases — install from main branch) · active · verified Sat Feb 28

Official Python SDK for the GrabFood Partner API — enables food delivery merchants and platform partners in Southeast Asia to manage orders, store hours, menus, and campaigns programmatically. Auto-generated from Grab's OpenAPI spec using OpenAPITools PythonClientCodegen. IMPORTANT: This SDK covers GrabFood only (merchant/food delivery). Grab rides/mobility has no official Python SDK. The SDK is not published on PyPI — install via GitHub only.

Warnings

Install

Imports

Quickstart

Authentication is a two-step process: obtain an OAuth token from the auth endpoint, then use it as a Bearer token against the GrabFood partner API. The token must be refreshed manually using the expires_in value from the token response — the SDK does not handle token refresh automatically.

import grabfood
from grabfood.configs.config import STG_ENV, PRD_ENV, STG_AUTH_ENV, PRD_AUTH_ENV
from grabfood.rest import ApiException

# Step 1: Get OAuth token (client credentials flow)
# Credentials obtained from Grab Developer Portal
CLIENT_ID = 'your_client_id'
CLIENT_SECRET = 'your_client_secret'

# Auth configuration — use STG_AUTH_ENV for staging, PRD_AUTH_ENV for production
auth_config = grabfood.Configuration(host=STG_AUTH_ENV)

with grabfood.ApiClient(auth_config) as auth_client:
    auth_api = grabfood.GetOauthGrabApi(auth_client)
    oauth_request = grabfood.GrabOauthRequest(
        client_id=CLIENT_ID,
        client_secret=CLIENT_SECRET,
        grant_type='client_credentials',
        scope='food.partner_api'
    )
    token_response = auth_api.get_oauth_grab('application/json', oauth_request)
    ACCESS_TOKEN = 'Bearer ' + token_response.access_token
    # Store token_response.expires_in to know when to refresh

# Step 2: Use token against GrabFood API
# IMPORTANT: Default host is STG_ENV (sandbox). Switch to PRD_ENV for production.
configuration = grabfood.Configuration(host=PRD_ENV)  # or STG_ENV for testing

MERCHANT_ID = 'your_merchant_id'

with grabfood.ApiClient(configuration) as api_client:
    # Get store hours
    store_api = grabfood.GetStoreHourApi(api_client)
    try:
        response = store_api.get_store_hour(
            authorization=ACCESS_TOKEN,
            merchant_id=MERCHANT_ID
        )
        print(response)
    except ApiException as e:
        print(f'API error: {e}')

    # Accept an order
    order_api = grabfood.AcceptRejectOrderApi(api_client)
    try:
        order_api.accept_reject_order(
            authorization=ACCESS_TOKEN,
            content_type='application/json',
            accept_order_request=grabfood.AcceptOrderRequest()
        )
    except ApiException as e:
        print(f'Order error: {e}')

view raw JSON →