Skip to main content

Python client for the Betfair API (https://api.developer.betfair.com/)

Project description

https://badge.fury.io/py/betfair.py.png https://travis-ci.org/jmcarp/betfair.py.png?branch=master

betfair.py is a Python wrapper for the Betfair API

Installation

$ pip install betfair.py

Requirements

  • Python >= 2.7 or >= 3.3

Testing

To run tests

$ py.test

Application Keys

You will need an Application Key to log in to the Betfair API. You can find instructions for creating a key at https://api.developer.betfair.com/services/webapps/docs/display/1smk3cen4v3lu3yomq5qye0ni/Application+Keys

SSL Certificates

For non-interactive login, you must generate a self-signed SSL certificate and upload it to your Betfair account. Betfair.py includes tools for simplifying this process. To create a self-signed certificate, run

invoke ssl

This will generate the following files in the certs directory

betfair.crt
betfair.csr
betfair.key
betfair.pem

You can write SSL certificates to another directory by passing the --name parameter

invoke ssl --name=path/to/certs/betfair

Once you have generated the files, you can upload the betfair.crt file to Betfair at https://myaccount.betfair.com/accountdetails/mysecurity?showAPI=1.

Examples

Create a Betfair client and log in

from betfair import Betfair
client = Betfair('app_key', 'certs/betfair.pem')
client.login('username', 'password')

Refresh session token

client.keep_alive()

Log out

client.logout()

List all tennis markets

from betfair.models import MarketFilter
event_types = client.list_event_types(
    MarketFilter(text_query='tennis')
)
print(len(event_types))                 # 2
print(event_types[0].event_type.name)   # 'Tennis'
tennis_event_type = event_types[0]
markets = client.list_market_catalogue(
    MarketFilter(event_type_ids=[tennis_event_type.event_type.id])
)
markets[0].market_name                  # 'Djokovic Tournament Wins'

Author

Joshua Carp (jmcarp)

License

MIT licensed. See the bundled LICENSE file for more details

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

betfair.py-0.2.1.tar.gz (13.4 kB view details)

Uploaded Source

File details

Details for the file betfair.py-0.2.1.tar.gz.

File metadata

  • Download URL: betfair.py-0.2.1.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for betfair.py-0.2.1.tar.gz
Algorithm Hash digest
SHA256 be1c81ca0d73d820b4175679ade2cf5c00547b847e4fa14983b618e88aed049f
MD5 cfe81a03e10dd076d0b17b278d15c077
BLAKE2b-256 c0c6b8d47fecf4143ac19f1a566eac012538fa0e03550f1c08feef297b0c59c2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page