Registry / http-networking / betfairlightweight

betfairlightweight

JSON →
library2.23.2pypypi✓ verified 84d ago

Lightweight Python wrapper for the Betfair API-NG. Provides access to Betfair's streaming and REST APIs for betting exchange operations. Current version 2.23.2, requires Python >=3.9. Released under MIT license. Active development with frequent releases.

pip install betfairlightweight
INSTALL
IMPORT
SIG · BETFAIRLIGHTWEIGHT
B
betfairlightweight
http-networkingpythonv2.23.2
Install
2.2s avg
Import
—
Disk
20MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v2.23.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 21.6MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 2.2s · import 0.000s · 22MB
20MB installed
● package 20MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

APIClient
✓ from betfairlightweight import APIClient
✗ from betfairlightweight import Betfair

Initialize Betfair client, login, fetch event types, and logout. Uses environment variables for credentials.

import os from betfairlightweight import Betfair trading = Betfair( app_key=os.environ.get('BF_APP_KEY', ''), username=os.environ.get('BF_USERNAME', ''), password=os.environ.get('BF_PASSWORD', ''), ) # Login trading.login() # Get all event types event_types = trading.betting.list_event_types() print(event_types) # Logout trading.logout()
Debug
Known issues
breakingIn version 2.0.0, the streaming API was rewritten. Old code using 'StreamListener' or 'streaming_socket' will not work. Migrate to 'StreamingResources' and 'MarketDataFilter'.
fix
Use 'from betfairlightweight.streaming import StreamingResources' and follow the new streaming pattern.
affects: >=2.0.0
breakingThe 'endpoint' parameter was removed from the Betfair constructor. Use environment variables or pass directly via 'app_key', 'username', 'password'.
fix
Remove 'endpoint' from Betfair() call. Use credentials as above.
affects: >=2.0.0
gotchaLogin may have a rate limit. Calling 'login()' rapidly can cause temporary blocks. Use a single login session and reuse the client.
fix
Cache the client session and call login() only once per session.
affects: all
deprecatedThe 'betfairlightweight.endpoints' module is deprecated in favour of 'betfairlightweight.betting' and 'betfairlightweight.account'.
fix
Replace imports from 'betfairlightweight.endpoints' with 'betfairlightweight.betting' or 'betfairlightweight.account'.
affects: 2.1.0 - 2.23.2
Upgrade
Version history
2.23.2latest on PyPI · released Mar 16, 2026
Audit
Dependencies
requestsrequiredHTTP requests for REST API
socketIO-client-nexusrequiredStreaming API (real-time updates)
python-dateutilrequiredDate/time parsing
Agent activity
36 hits · last 30 days
node
34
OpenAI (training)
1
Resources
betfairlightweight — pip install betfairlightweight · libregistry