Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Simple python library to fetch games directly into Postgres database from Lichess.org using it's API or pgn file containing games.
Simple python library to fetch games directly into Postgres database from Lichess.org using it's API or pgn file containing games.
$ pip install chess2postgres
from chess2postgres import lichess_pgn2db, lichess_api2db
Main goal while creating this library was creating possibility of fetching chess games directly into your Postgres database as chess games db's are getting popular lately.
Lichess API and pgn files may differ a little in some aspects. One of them is termination - while using api to fetch games, end of the game is descirbed more precisely - mate, resign, out of time, variant end (in RacingKings for example). On the other hand, pgn files call them 'abandoned', 'time forfeit' and 'standard'. I decided not to mess with it and leave it how it is. Despite this fact, it is possible to keep both games from pgn files and those fetched directly from Lichess in a same db.
Currently, library supports 2 formats of inserting data into the database. You can do it from pgn file already downloaded and stored on your device or you can use Lichess API to directly fetch games from Lichess.org into the database.
This function works when you have already downloaded pgn file from Lichess.org and want to fetch it into the database. To sucesfully call this function, you have to specify parameters such as:
Predefined parameters:
By default, Lichess pgn files contain '?' in situations where a data is missing. It can happen when the game was abandoned (opening, ECO code, are marked as '?' and the game is just a empty string) or one of the players did not have an account (name, elo, RatingDiff are marked as '?'). In situatuons where the pgn file contains '?', it is added to the database this way. On the other hand, when the data is lacking (for example pgn file does not contain info about openings), they are marked as 'unknown'. Thats why some of the columns are labeled as text, even they could be integer or boolean.
This function is useful when you want to fetch games directly from Lichess to your database without downloading the pgn file. Sucesfull call of this function requires passing parameters such as:
Predefined parameters:
Same as in lichess_pgn2db, this func describes all data that is lacking as 'unknown'. Consider that sometimes opening, ECO etc are not appropiate due to gametype.
sample usage:
lichess_api2db('postgres', 'postgres', 'pass123','localhost', 5432, 'api_token777', 'Player01', 5, tablename='rapid_games', perf_type='rapid', rated='True')
It connects to the db, fetches 'Player01' rapid, ranked games from Lichess to your Postgres databse using specified api token. Done.
FAQs
Simple python library to fetch games directly into Postgres database from Lichess.org using it's API or pgn file containing games.
We found that chess2postgres demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.