{"id":23354,"library":"betfairlightweight","title":"betfairlightweight","description":"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.","status":"active","version":"2.23.2","language":"python","source_language":"en","source_url":"https://github.com/betcode-org/betfair","tags":["betfair","api","betting","exchange","streaming"],"install":[{"cmd":"pip install betfairlightweight","lang":"bash","label":"Latest version"}],"dependencies":[{"reason":"HTTP requests for REST API","package":"requests","optional":false},{"reason":"Streaming API (real-time updates)","package":"socketIO-client-nexus","optional":false},{"reason":"Date/time parsing","package":"python-dateutil","optional":false}],"imports":[{"note":"Common mistake: importing the package without the Betfair class. Use 'from betfairlightweight import Betfair'.","wrong":"import betfairlightweight","symbol":"Betfair","correct":"from betfairlightweight import Betfair"},{"note":"Streaming classes are in the streaming submodule, not top-level.","wrong":"from betfairlightweight import StreamingResources","symbol":"StreamingResources","correct":"from betfairlightweight.streaming import StreamingResources"}],"quickstart":{"code":"import os\nfrom betfairlightweight import Betfair\n\ntrading = Betfair(\n    app_key=os.environ.get('BF_APP_KEY', ''),\n    username=os.environ.get('BF_USERNAME', ''),\n    password=os.environ.get('BF_PASSWORD', ''),\n)\n\n# Login\ntrading.login()\n\n# Get all event types\nevent_types = trading.betting.list_event_types()\nprint(event_types)\n\n# Logout\ntrading.logout()","lang":"python","description":"Initialize Betfair client, login, fetch event types, and logout. Uses environment variables for credentials."},"warnings":[{"fix":"Use 'from betfairlightweight.streaming import StreamingResources' and follow the new streaming pattern.","message":"In version 2.0.0, the streaming API was rewritten. Old code using 'StreamListener' or 'streaming_socket' will not work. Migrate to 'StreamingResources' and 'MarketDataFilter'.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Remove 'endpoint' from Betfair() call. Use credentials as above.","message":"The 'endpoint' parameter was removed from the Betfair constructor. Use environment variables or pass directly via 'app_key', 'username', 'password'.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Cache the client session and call login() only once per session.","message":"Login may have a rate limit. Calling 'login()' rapidly can cause temporary blocks. Use a single login session and reuse the client.","severity":"gotcha","affected_versions":"all"},{"fix":"Replace imports from 'betfairlightweight.endpoints' with 'betfairlightweight.betting' or 'betfairlightweight.account'.","message":"The 'betfairlightweight.endpoints' module is deprecated in favour of 'betfairlightweight.betting' and 'betfairlightweight.account'.","severity":"deprecated","affected_versions":"2.1.0 - 2.23.2"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run 'pip install betfairlightweight' and ensure you're using the correct environment (e.g., virtualenv).","cause":"The package is not installed or the Python environment is wrong.","error":"ModuleNotFoundError: No module named 'betfairlightweight'"},{"fix":"Double-check username/password. Ensure your app key is valid and IP is whitelisted in Betfair's developer portal.","cause":"Wrong credentials or expired app key. Betfair may also require IP whitelisting for app keys.","error":"betfairlightweight.exceptions.LoginError: INVALID_USERNAME_OR_PASSWORD"},{"fix":"Use 'from betfairlightweight import Betfair' instead of 'import betfairlightweight; betfairlightweight.Betfair'.","cause":"Imported incorrectly. The Betfair class is not directly under the module.","error":"AttributeError: module 'betfairlightweight' has no attribute 'Betfair'"},{"fix":"Ensure your app key has streaming permissions enabled. Check firewall/proxy settings. Use 'wss://stream-api.betfair.com' as the streaming URL.","cause":"Streaming API connection failed. Usually because of network issues or incorrect app key permissions.","error":"socketIO_client.exceptions.SocketIOError: Connection refused"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}