Use Lightweight mode for raw JSON responses
masterEnabling lightweight=True instructs the library to return raw JSON instead of creating complex Python objects. This is significantly faster because it avoids object instantiation overhead, though the data is harder to work with. You can enable it globally during client initialization or per request.
# Global initialization
>>> trading = betfairlightweight.APIClient(
"username",
"password",
app_key="app_key",
certs="/certs",
lightweight=True,
)
>>> trading.login()
{'sessionToken': 'dfgrtegreg===rgrgr', 'loginStatus': 'SUCCESS'}
# Per request
>>> trading.betting.list_event_types(
filter=filters.market_filter(
text_query='Horse Racing'
),
lightweight=True,
)
[{'eventType': {'id': '7', 'name': 'Horse Racing'}, 'marketCount': 328}]