This is a Python module for using the Soccermetrics REST API.
The Soccermetrics API Python client library depends on the Requests and easydict libraries. You can install the client library within a virtual environment on your computer, or install it system-wide.
Python 2.6+ is required. The module might work with Python 3, but we haven't tested it and give no guarantees.
It's not required, but autoenv is very nice to have.
We recommend installing soccermetrics-client-py
within a virtual environment
using virtualenv
. That way you can run different versions of Python
installations and libraries without dealing with conflicting dependencies.
Here is a link to a nice tutorial on Virtualenv.
To install virtualenv
on MacOS or Linux, create a folder and run one of these
two commands as sudo
:
$ sudo easy_install virtualenv
or
$ sudo pip install virtualenv
If you are on Windows, this link
will show you how to install pip
and distribute
, which you will use to
install virtualenv
.
Download [the current zipped version of the source code] (https://github.com/soccermetrics/soccermetrics-client-py/archive/master.zip) from GitHub, unzip the folder and run:
$ make install
If you want to install soccermetrics-client-py
system-wide -- not recommended
because of possible library conflicts -- download
[the current zipped version of the source code]
(https://github.com/soccermetrics/soccermetrics-client-py/archive/master.zip)
from GitHub, unzip the folder and run:
$ make install
To start using the Soccermetrics API, create a SoccermetricsRestClient
.
You'll need your Soccermetrics API credentials to use the SoccermetricsRestClient
.
These get passed to the constructor directly or via environment variables.
from soccermetrics.rest import SoccermetricsRestClient
appID = "f53baabb"
appKey = "demo1234567890demo1234567890"
client = SoccermetricsRestClient(account=appID,api_key=appKey)
If you call SoccermetricsRestClient
without any parameters, the constructor
will look for SOCCERMETRICS_APP_ID
and SOCCERMETRICS_APP_KEY
variables
inside the current environment.
We recommend that you keep your credentials in environment variables. That way you won't have to worry about accidentally posting your credentials in a public place.
from soccermetrics.rest import SoccermetricsRestClient
client = SoccermetricsRestClient()
from soccermetrics.rest import SoccermetricsRestClient
appID = "f53baabb"
appKey = "demo1234567890demo1234567890"
client = SoccermetricsRestClient()
match = client.match.information.get(home_team_name="Everton",
away_team_name="Liverpool").data[0]
print match.matchday, match.match_date, match.kickoff_time
lineup_data = client.link.get(match.link.lineups, is_starting=True).all()
for datum in lineup_data:
print datum.player_name, datum.player_team_name
from soccermetrics.rest import SoccermetricsRestClient
appID = "f53baabb"
appKey = "demo1234567890demo1234567890"
client = SoccermetricsRestClient()
player = client.players.get(full_name=u'Robin van Persie').data[0]
goals = client.link.get(player.link.events.goals)
penalties = client.link.get(player.link.events.penalties,outcome_type="Goal")
from soccermetrics.rest import SoccermetricsRestClient
client = SoccermetricsRestClient()
match = client.match.information.get(home_team_name='Manchester United', away_team_name='Stoke City').data[0]
match_state_46 = client.link.get(match.link.analytics.state,time_mins=46)
match_state_75 = client.link.get(match.link.analytics.state,time_mins=75)
match_state_final = client.link.get(match.link.analytics.state)
match_segments = client.link.get(match.link.analytics.segment)