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.8.tar.gz
.
File metadata
- Download URL: fantraxapi-0.2.8.tar.gz
- Upload date:
- Size: 12.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e01425446629e2d36fb6b740a9dd5c8cb526a95bd54b2325285154820a747d1a |
|
MD5 | 03e0e8dd8b19d9604b1f0aa1c29041ba |
|
BLAKE2b-256 | de376916d5df742cbea104f2f0948357723198b042565e55df258de2647c0fb9 |
File details
Details for the file fantraxapi-0.2.8-py3-none-any.whl
.
File metadata
- Download URL: fantraxapi-0.2.8-py3-none-any.whl
- Upload date:
- Size: 10.9 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 | 7f089035bd7b2566c08bc1507f071ce48b81ff9e75f6d755925dcb5578b2c494 |
|
MD5 | d027f1a291d53326f4108fc9bc8200a8 |
|
BLAKE2b-256 | 3ededd6f0ebc34c5aa7dfe0805f1b0d39b5e3c0bab60f1c5da3271bfbe1902cd |