A lightweight Python library for The Fantrax API.
Project description
Welcome to Fantrax Documentation!
Overview
Unofficial Python bindings for the Fantrax API. The goal is to make interaction with the API as easy as possible while emulating the endpoints as much as possible
Installation & Documentation
pip install fantraxapi
Documentation can be found at Read the Docs.
Using the API
Getting a FantraxAPI Instance
To connect to the Fantrax API you use the FantraxAPI object.
from fantraxapi import FantraxAPI
league_id = "96igs4677sgjk7ol"
api = FantraxAPI(league_id)
import fantraxapi
api = fantraxapi.FantraxAPI()
Usage Examples
Example: Get the Scores for the Season.
from fantraxapi import FantraxAPI
league_id = "96igs4677sgjk7ol"
api = FantraxAPI(league_id)
for _, scoring_period in api.scoring_periods().items():
print("")
print(scoring_period)
Connecting with a private League
I was unable to decipher the api login method so in order to connect to a private league or specific pages in a public
league that are not public you need to use a cookie. The code below uses Google Chrome and the selenium
and
webdriver-manager
packages to open a chrome instance where you can login and after 30 seconds a cookie file with
that login will be save to fantraxloggedin.cookie
.
First install the two packages:
pip install selenium
pip install webdriver-manager
Second run the code below and login when the chrome window loads the Fantrax login page:
import pickle
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
service = Service(ChromeDriverManager().install())
options = Options()
options.add_argument("--window-size=1920,1600")
options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36")
with webdriver.Chrome(service=service, options=options) as driver:
driver.get("https://www.fantrax.com/login")
time.sleep(30)
pickle.dump(driver.get_cookies(), open("fantraxloggedin.cookie", "wb"))
Third use the saved cookie file with the wrapper:
import pickle
from fantraxapi import FantraxAPI
from requests import Session
session = Session()
with open("fantraxloggedin.cookie", "rb") as f:
for cookie in pickle.load(f):
session.cookies.set(cookie["name"], cookie["value"])
league_id = "96igs4677sgjk7ol"
api = FantraxAPI(league_id, session=session)
print(api.trade_block()) # The Trade Block Page is always private
Usage & Contributions
Source is available on the Github Project Page.
Contributors to FantraxAPI own their own contributions and may distribute that code under the MIT license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file fantraxapi-0.2.9.tar.gz
.
File metadata
- Download URL: fantraxapi-0.2.9.tar.gz
- Upload date:
- Size: 12.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8b01676079e17308cfda396d0854ddf833ce64645966fb9d32fdb2e9d380770 |
|
MD5 | bc3eeff57e64955e98c486bbefe70551 |
|
BLAKE2b-256 | 03bf0df34a9af4e5ecc5bd13df8bd9eaafcf40c59ebdef1cb1b09d5fe5258588 |
File details
Details for the file fantraxapi-0.2.9-py3-none-any.whl
.
File metadata
- Download URL: fantraxapi-0.2.9-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e14cd899ca4f13d146361cd85ec83d89f983e98b9dacdfb56cd8c84c175a8c33 |
|
MD5 | 80c317f02720925bb3943393462c92b2 |
|
BLAKE2b-256 | 0fbdc1d57fa8066e36d167c3f7642601c31d6c7e38474444170a6c930129af19 |