Answers.Body: <p>chess.com has a public API: <a href="https://www.chess.com/news/view/published-data-api#pubapi-endpoint-player-stats" rel="noreferrer">https://www.chess.com/news/view/published-data-api#pubapi-endpoint-player-stats</a></p>
  <p>URL pattern: <a href="https://api.chess.com/pub/player/%7Busername%7D/stats" rel="noreferrer">https://api.chess.com/pub/player/{username}/stats</a></p>
  <p>Example output:</p>
  <pre><code>$ curl -s 'https://api.chess.com/pub/player/hikaru/stats' | jq 
  {
    &quot;chess_daily&quot;: {
      &quot;last&quot;: {
        &quot;rating&quot;: 2239,
        &quot;date&quot;: 1694547202,
        &quot;rd&quot;: 103
      },
      &quot;best&quot;: {
        &quot;rating&quot;: 2464,
        &quot;date&quot;: 1397136740,
        &quot;game&quot;: &quot;https://www.chess.com/game/daily/84604826&quot;
      },
      &quot;record&quot;: {
        &quot;win&quot;: 73,
        &quot;loss&quot;: 11,
        &quot;draw&quot;: 4,
        &quot;time_per_move&quot;: 32755,
        &quot;timeout_percent&quot;: 0
      }
    },
    &quot;chess960_daily&quot;: {
      &quot;last&quot;: {
        &quot;rating&quot;: 1231,
        &quot;date&quot;: 1444458214,
        &quot;rd&quot;: 230
      },
      &quot;best&quot;: {
        &quot;rating&quot;: 1489,
        &quot;date&quot;: 1397073007,
        &quot;game&quot;: &quot;https://www.chess.com/game/daily/87191830&quot;
      },
      &quot;record&quot;: {
        &quot;win&quot;: 1,
        &quot;loss&quot;: 2,
        &quot;draw&quot;: 0,
        &quot;time_per_move&quot;: 32755,
        &quot;timeout_percent&quot;: 0
      }
    },
    &quot;chess_rapid&quot;: {
      &quot;last&quot;: {
        &quot;rating&quot;: 2762,
        &quot;date&quot;: 1715460607,
        &quot;rd&quot;: 49
      },
      &quot;best&quot;: {
        &quot;rating&quot;: 2927,
        &quot;date&quot;: 1645902514,
        &quot;game&quot;: &quot;https://www.chess.com/game/live/61144117987&quot;
      },
      &quot;record&quot;: {
        &quot;win&quot;: 170,
        &quot;loss&quot;: 48,
        &quot;draw&quot;: 172
      }
    },
    &quot;chess_bullet&quot;: {
      &quot;last&quot;: {
        &quot;rating&quot;: 3317,
        &quot;date&quot;: 1716659796,
        &quot;rd&quot;: 37
      },
      &quot;best&quot;: {
        &quot;rating&quot;: 3570,
        &quot;date&quot;: 1605136047,
        &quot;game&quot;: &quot;https://www.chess.com/game/live/5710095242&quot;
      },
      &quot;record&quot;: {
        &quot;win&quot;: 13030,
        &quot;loss&quot;: 1782,
        &quot;draw&quot;: 805
      }
    },
    &quot;chess_blitz&quot;: {
      &quot;last&quot;: {
        &quot;rating&quot;: 3175,
        &quot;date&quot;: 1717623525,
        &quot;rd&quot;: 32
      },
      &quot;best&quot;: {
        &quot;rating&quot;: 3405,
        &quot;date&quot;: 1707519571,
        &quot;game&quot;: &quot;https://www.chess.com/game/live/59245152619&quot;
      },
      &quot;record&quot;: {
        &quot;win&quot;: 27992,
        &quot;loss&quot;: 4681,
        &quot;draw&quot;: 3671
      }
    },
    &quot;fide&quot;: 2814,
    &quot;tactics&quot;: {
      &quot;highest&quot;: {
        &quot;rating&quot;: 3902,
        &quot;date&quot;: 1710574172
      },
      &quot;lowest&quot;: {
        &quot;rating&quot;: 695,
        &quot;date&quot;: 1389043648
      }
    },
    &quot;puzzle_rush&quot;: {
      &quot;best&quot;: {
        &quot;total_attempts&quot;: 126,
        &quot;score&quot;: 123
      }
    }
  }
  
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-06-06T15:03:25.290Z
Answers.Text: Thanks for sharing for chess.com too. Can't have 2 accepted answers or this one would be included
Answers.UserDisplayName: Al Martins
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-06-06T04:19:57.953Z
Answers.LastActivityDate: 2024-06-06T04:19:57.953Z
Answers.UserDisplayName: qwr
Answers.Body: <p>A sample python script for Lichess, chess.com and FIDE.</p>
  <h1>1. Lichess</h1>
  <pre><code>&quot;&quot;&quot;Gets Lichess user ratings given username.
  
  API: https://lichess.org/api
  &quot;&quot;&quot;
  
  import json
  from urllib.request import urlopen
  
  username = input('Input your Lichess username? ')
  user_json = urlopen(&quot;http://en.lichess.org/api/user/&quot; + username).read()
  user_perfs = json.loads(user_json)['perfs']
  
  print(f'username: {username}')
  for k in user_perfs:
      rating = user_perfs[k].get('rating')
      if rating:
          print(f'{k}: {rating}')
  </code></pre>
  <h2>Sample run</h2>
  <pre><code>Input your Lichess username? zhigalko_sergei
  username: zhigalko_sergei
  ultraBullet: 2472
  bullet: 3250
  blitz: 2828
  rapid: 2948
  classical: 1500
  correspondence: 1500
  chess960: 2777
  kingOfTheHill: 2630
  threeCheck: 2576
  racingKings: 1698
  crazyhouse: 2547
  puzzle: 2822
  </code></pre>
  <h1>2. chess.com</h1>
  <pre><code>&quot;&quot;&quot;Gets user ratings from chess.com given username
  
  API: https://www.chess.com/news/view/published-data-api
  &quot;&quot;&quot;
  
  import urllib.request
  import json
  
  username = input('Input your chess.com username? ')
  url = f&quot;https://api.chess.com/pub/player/{username}/stats&quot;
  
  with urllib.request.urlopen(url) as response:
      data = response.read().decode()
      player_stats = json.loads(data)
  
      print(f'username: {username}')
      for k in player_stats:
          try:
              rating = player_stats[k]['last'].get('rating')
          except KeyError:
              pass
          except Exception as exc:
              pass
          else:
              if rating:
                  print(f'{k}: {rating}')
  </code></pre>
  <h2>Sample run</h2>
  <pre><code>Input your chess.com username? hikaru
  username: hikaru
  chess_daily: 2239
  chess960_daily: 1231
  chess_rapid: 2762
  chess_bullet: 3257
  chess_blitz: 3286
  </code></pre>
  <h1>3. FIDE</h1>
  <pre><code>&quot;&quot;&quot;Gets FIDE rating given FIDE Id.
  
  Reference: https://github.com/cassiofb-dev/fide-api
  &quot;&quot;&quot;
  
  import urllib.request
  import json
  
  def get_fide_rating(fide_id):
      url = f&quot;https://fide-api.vercel.app/player_info/?fide_id={fide_id}&amp;history=true&quot;
      try:
          with urllib.request.urlopen(url) as response:
              if response.status == 200:
                  data = json.loads(response.read().decode())
                  name = data.get('name')
                  title = data.get('fide_title')
  
                  pinfo = data['history'][0]
                  period = pinfo.get('period')
                  classical_rating = pinfo.get('classical_rating')
                  rapid_rating = pinfo.get('rapid_rating')
                  blitz_rating = pinfo.get('blitz_rating')
  
                  print(f'fide id: {fide_id}')
                  print(f'name: {name}')
                  print(f'title: {title}')
                  print(f'period: {period}')
                  print(f'classical rating: {classical_rating}')
                  print(f'rapid rating: {rapid_rating}')
                  print(f'blitz rating: {blitz_rating}')
              else:
                  print(f&quot;Failed to retrieve data for player ID {fide_id}. HTTP Status Code: {response.status}&quot;)
      except urllib.error.URLError as e:
          print(f&quot;Error retrieving data: {e}&quot;)
  
  fide_id = input('Input player FIDE ID? ')
  get_fide_rating(fide_id)
  </code></pre>
  <h2>Sample run</h2>
  <pre><code>Input player FIDE ID? 46616543
  fide id: 46616543
  name: Gukesh D        
  title: Grandmaster    
  period: 2024-Jun      
  classical rating: 2763
  rapid rating: 2647    
  blitz rating: 2627    
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-07-01T00:48:07.750Z
Answers.Text: Yes you could do this, but it's also one line with curl and jq.
Answers.UserDisplayName: qwr
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-06-12T22:43:39.213Z
Answers.LastActivityDate: 2024-06-16T11:43:33.980Z
Answers.LastEditDate: 2024-06-16T11:43:33.980Z
Answers.UserDisplayName: ferdy
Answers.Body: <p>You can get user current rating from Lichess using <a href="https://lichess.org/api#tag/Users/operation/apiUser" rel="noreferrer">/api/user/{username}</a>, which returns JSON with key <code>&quot;perfs&quot;</code>, in which are current ratings by time control category.</p>
  <p>For rating history you can use <a href="https://lichess.org/api#tag/Users/operation/apiUserRatingHistory" rel="noreferrer">/api/user/{username}/rating-history</a>.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-06-05T09:58:50.810Z
Answers.LastActivityDate: 2024-06-05T09:58:50.810Z
Answers.UserDisplayName: Matija Sirk
Body: <p>We use a chess club and class management system that gets up to date ratings from ECF (English Chess Federation). Is it possible to do the same for Chess.com and Lichess and how?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-06-05T11:07:39.417Z
Comments.Text: In addition to the answer while not a duplicate the answer to [Downloading Games From Lichess](https://chess.stackexchange.com/questions/32761/downloading-games-from-lichess) might be helpful, at least for Lichess
Comments.UserDisplayName: Ian Bush
Tags: <rating><lichess><chess.com>
Title: How to pull ratings from Chess.com and Lichess automatically?
ThreadText: # How to pull ratings from Chess.com and Lichess automatically?
  
  (Asked by: username_0 on 2024-06-05)
  
  We use a chess club and class management system that gets up to date ratings from ECF (English Chess Federation). Is it possible to do the same for Chess.com and Lichess and how?
  
  **Tags:** rating, lichess, chess.com
  
  > **Comments:**
  > **username_1**: In addition to the answer while not a duplicate the answer to [Downloading Games From Lichess](https://chess.stackexchange.com/questions/32761/downloading-games-from-lichess) might be helpful, at least for Lichess  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_4 on 2024-06-05. Score: 10 | Accepted answer
  
  You can get user current rating from Lichess using [/api/user/{username}](https://lichess.org/api#tag/Users/operation/apiUser), which returns JSON with key `"perfs"`, in which are current ratings by time control category.
  
  For rating history you can use [/api/user/{username}/rating-history](https://lichess.org/api#tag/Users/operation/apiUserRatingHistory).
  
  
  ---
  
  ### Answer by username_2 on 2024-06-06. Score: 8
  
  chess.com has a public API: <https://www.chess.com/news/view/published-data-api#pubapi-endpoint-player-stats>
  
  URL pattern: [https://api.chess.com/pub/player/{username}/stats](https://api.chess.com/pub/player/%7Busername%7D/stats)
  
  Example output:
  
  ```
  $ curl -s 'https://api.chess.com/pub/player/hikaru/stats' | jq 
  {
    "chess_daily": {
      "last": {
        "rating": 2239,
        "date": 1694547202,
        "rd": 103
      },
      "best": {
        "rating": 2464,
        "date": 1397136740,
        "game": "https://www.chess.com/game/daily/84604826"
      },
      "record": {
        "win": 73,
        "loss": 11,
        "draw": 4,
        "time_per_move": 32755,
        "timeout_percent": 0
      }
    },
    "chess960_daily": {
      "last": {
        "rating": 1231,
        "date": 1444458214,
        "rd": 230
      },
      "best": {
        "rating": 1489,
        "date": 1397073007,
        "game": "https://www.chess.com/game/daily/87191830"
      },
      "record": {
        "win": 1,
        "loss": 2,
        "draw": 0,
        "time_per_move": 32755,
        "timeout_percent": 0
      }
    },
    "chess_rapid": {
      "last": {
        "rating": 2762,
        "date": 1715460607,
        "rd": 49
      },
      "best": {
        "rating": 2927,
        "date": 1645902514,
        "game": "https://www.chess.com/game/live/61144117987"
      },
      "record": {
        "win": 170,
        "loss": 48,
        "draw": 172
      }
    },
    "chess_bullet": {
      "last": {
        "rating": 3317,
        "date": 1716659796,
        "rd": 37
      },
      "best": {
        "rating": 3570,
        "date": 1605136047,
        "game": "https://www.chess.com/game/live/5710095242"
      },
      "record": {
        "win": 13030,
        "loss": 1782,
        "draw": 805
      }
    },
    "chess_blitz": {
      "last": {
        "rating": 3175,
        "date": 1717623525,
        "rd": 32
      },
      "best": {
        "rating": 3405,
        "date": 1707519571,
        "game": "https://www.chess.com/game/live/59245152619"
      },
      "record": {
        "win": 27992,
        "loss": 4681,
        "draw": 3671
      }
    },
    "fide": 2814,
    "tactics": {
      "highest": {
        "rating": 3902,
        "date": 1710574172
      },
      "lowest": {
        "rating": 695,
        "date": 1389043648
      }
    },
    "puzzle_rush": {
      "best": {
        "total_attempts": 126,
        "score": 123
      }
    }
  }
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks for sharing for chess.com too. Can't have 2 accepted answers or this one would be included  
  
  ---
  
  ### Answer by username_3 on 2024-06-12. Score: 2
  
  A sample python script for Lichess, chess.com and FIDE.
  
  # 1. Lichess
  
  ```
  """Gets Lichess user ratings given username.
  
  API: https://lichess.org/api
  """
  
  import json
  from urllib.request import urlopen
  
  username = input('Input your Lichess username? ')
  user_json = urlopen("http://en.lichess.org/api/user/" + username).read()
  user_perfs = json.loads(user_json)['perfs']
  
  print(f'username: {username}')
  for k in user_perfs:
      rating = user_perfs[k].get('rating')
      if rating:
          print(f'{k}: {rating}')
  
  ```
  
  ## Sample run
  
  ```
  Input your Lichess username? zhigalko_sergei
  username: zhigalko_sergei
  ultraBullet: 2472
  bullet: 3250
  blitz: 2828
  rapid: 2948
  classical: 1500
  correspondence: 1500
  chess960: 2777
  kingOfTheHill: 2630
  threeCheck: 2576
  racingKings: 1698
  crazyhouse: 2547
  puzzle: 2822
  
  ```
  
  # 2. chess.com
  
  ```
  """Gets user ratings from chess.com given username
  
  API: https://www.chess.com/news/view/published-data-api
  """
  
  import urllib.request
  import json
  
  username = input('Input your chess.com username? ')
  url = f"https://api.chess.com/pub/player/{username}/stats"
  
  with urllib.request.urlopen(url) as response:
      data = response.read().decode()
      player_stats = json.loads(data)
  
      print(f'username: {username}')
      for k in player_stats:
          try:
              rating = player_stats[k]['last'].get('rating')
          except KeyError:
              pass
          except Exception as exc:
              pass
          else:
              if rating:
                  print(f'{k}: {rating}')
  
  ```
  
  ## Sample run
  
  ```
  Input your chess.com username? hikaru
  username: hikaru
  chess_daily: 2239
  chess960_daily: 1231
  chess_rapid: 2762
  chess_bullet: 3257
  chess_blitz: 3286
  
  ```
  
  # 3. FIDE
  
  ```
  """Gets FIDE rating given FIDE Id.
  
  Reference: https://github.com/cassiofb-dev/fide-api
  """
  
  import urllib.request
  import json
  
  def get_fide_rating(fide_id):
      url = f"https://fide-api.vercel.app/player_info/?fide_id={fide_id}&history=true"
      try:
          with urllib.request.urlopen(url) as response:
              if response.status == 200:
                  data = json.loads(response.read().decode())
                  name = data.get('name')
                  title = data.get('fide_title')
  
                  pinfo = data['history'][0]
                  period = pinfo.get('period')
                  classical_rating = pinfo.get('classical_rating')
                  rapid_rating = pinfo.get('rapid_rating')
                  blitz_rating = pinfo.get('blitz_rating')
  
                  print(f'fide id: {fide_id}')
                  print(f'name: {name}')
                  print(f'title: {title}')
                  print(f'period: {period}')
                  print(f'classical rating: {classical_rating}')
                  print(f'rapid rating: {rapid_rating}')
                  print(f'blitz rating: {blitz_rating}')
              else:
                  print(f"Failed to retrieve data for player ID {fide_id}. HTTP Status Code: {response.status}")
      except urllib.error.URLError as e:
          print(f"Error retrieving data: {e}")
  
  fide_id = input('Input player FIDE ID? ')
  get_fide_rating(fide_id)
  
  ```
  
  ## Sample run
  
  ```
  Input player FIDE ID? 46616543
  fide id: 46616543
  name: Gukesh D        
  title: Grandmaster    
  period: 2024-Jun      
  classical rating: 2763
  rapid rating: 2647    
  blitz rating: 2627    
  
  ```
  
  > **Comments:**
  > **username_2**: Yes you could do this, but it's also one line with curl and jq.  
  
  ---
  
  