{"id":38681658,"url":"https://github.com/zq99/pgn2data","last_synced_at":"2026-01-17T10:15:35.090Z","repository":{"id":39699561,"uuid":"326748597","full_name":"zq99/pgn2data","owner":"zq99","description":"A library that converts a chess pgn file into a tabulated CSV data set.","archived":false,"fork":false,"pushed_at":"2024-01-24T14:02:48.000Z","size":11505,"stargazers_count":17,"open_issues_count":3,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-18T09:04:38.647Z","etag":null,"topics":["chess","chess-analysis","csv","data","dataset","fen","library","pgn"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zq99.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-01-04T16:49:52.000Z","updated_at":"2025-05-16T15:28:37.000Z","dependencies_parsed_at":"2023-01-19T19:32:20.963Z","dependency_job_id":null,"html_url":"https://github.com/zq99/pgn2data","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/zq99/pgn2data","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zq99%2Fpgn2data","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zq99%2Fpgn2data/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zq99%2Fpgn2data/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zq99%2Fpgn2data/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zq99","download_url":"https://codeload.github.com/zq99/pgn2data/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zq99%2Fpgn2data/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28505973,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T06:57:29.758Z","status":"ssl_error","status_checked_at":"2026-01-17T06:56:03.931Z","response_time":85,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chess","chess-analysis","csv","data","dataset","fen","library","pgn"],"created_at":"2026-01-17T10:15:34.905Z","updated_at":"2026-01-17T10:15:35.081Z","avatar_url":"https://github.com/zq99.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pgn2data\n\n[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)\n![GitHub stars](https://img.shields.io/github/stars/zq99/pgn2data?style=social)\n![GitHub forks](https://img.shields.io/github/forks/zq99/pgn2data?style=social)\n\n\nThis library converts chess pgn files into CSV tabulated data sets.\n\nA pgn file can contain one or multiple chess games. The library parses the pgn file and creates two csv files:\n\n- Games file: contains high level information (e.g. date, site, event, score, players etc...)\n\n- Moves file: contains the moves for each game  (e.g. notation, squares, fen position, is in check etc...)\n\nThe two files can be mapped together using a GUID which the process inserts into both files.\n\n\n## Installation\n\nThe library requires Python 3.7 or later.  \n \nTo install, type the following command on the python terminal:\n\n    pip install pgn2data\n    \n  \n## Implementation\n\nHere is a basic example of how to convert a PGN file:\n\n    from converter.pgn_data import PGNData\n    \n    pgn_data = PGNData(\"tal_bronstein_1982.pgn\")\n    pgn_data.export()\n\nThe following is an example of grouping multiple files into the same output file (\"output.csv\").\n\n    pgn_data = PGNData([\"file1.pgn\",\"file2.pgn\"],\"output\")\n    pgn_data.export()\n    \nThe export function has a return object which allows you to quickly check the size and location of the files created:\n\n    pgn_data = PGNData(\"tal_bronstein_1982.pgn\")\n    result = pgn_data.export()\n    result.print_summary()\n\nIf you want to check if the files have been created before doing further processing you can do the following:\n\n    pgn_data = PGNData(\"tal_bronstein_1982.pgn\")\n    result = pgn_data.export()\n    if result.is_complete:\n        print(\"Files created!\")\n    else:\n        print(\"Files not created!\")\n\n\n### Pandas\n\nThe result object also provides methods to import the created files into pandas dataframes:\n\n    pgn_data = PGNData(\"tal_bronstein_1982.pgn\")\n    result = pgn_data.export()\n    if result.is_complete:\n        \n        # read the games file\n        games_df = result.get_games_df()\n        print(games_df.head())\n        \n        # read the moves file\n        moves_df = result.get_moves_df()\n        print(moves_df.head())\n        \n        # read both files joined together\n        combined_df = result.get_combined_df()\n        print(combined_df.head())\n\n\n### Optimization\n\nTo output the game information only, you can do the following:\n    \n    from converter.pgn_data import PGNData\n    \n    pgn_data = PGNData(\"tal_bronstein_1982.pgn\")\n    pgn_data.export(moves_required=False)\n\n\n## Examples\n\nThe folder 'samples' in this repository, has some examples of the output from the library.\n\nYou can also go [here](https://www.kaggle.com/datasets/zq1200/magnus-carlsen-lichess-games-dataset) to see a Kaggle project that converted all of Magnus Carlsen's online Bullet games\ninto CSV format. \n\n\n## Columns\n\nThis is a full list of the columns in each output file:\n\n### Games File\n\n| Field                 | Description                        |\n|-----------------------|------------------------------------|\n| game_id               | ID of game generated by process    |\n| game_order            | Order of game in PGN file          |\n| event                 | Event                              |\n| site                  | Site                               |\n| date_played           | Date played                        |\n| round                 | Round                              |\n| white                 | White player                       |\n| black                 | Black player                       |\n| result                | Result                             |\n| white_elo             | White player rating                |\n| white_rating_diff     | White rating difference from Black |\n| black_elo             | Black player rating                |\n| black_rating_diff     | Black rating difference from White |\n| white_title           | Player title                       |\n| black_title           | Player title                       |\n| winner                | Player name                        |\n| winner_elo            | Player rating                      |\n| loser                 | Losing player                      |\n| loser_elo             | Player rating                      |\n| winner_loser_elo_diff | Diff in rating                     |\n| eco                   | Opening                            |\n| termination           | How game ended                     |\n| time_control          | Time control                       |\n| utc_date              | Date played                        |\n| utc_time              | Time played                        |\n| variant               | Game type                          |\n| ply_count             | Ply Count                          |\n| date_created          | Extract date                       |\n| file_name             | PGN source file                    |\n\n\n### Moves File\n\n| Field                          | Description                                                             |\n|--------------------------------|-------------------------------------------------------------------------|\n| game_id                        | ID of game that maps to games file                                      |\n| move_no                        | Order of moves                                                          |\n| move_no_pair                   | Chess move number                                                       |\n| player                         | Player name                                                             |\n| notation                       | Standard notation of move                                               |\n| move                           | Before and after piece location                                         |\n| from_square                    | Piece location before                                                   |\n| to_square                      | Piece location after                                                    |\n| piece                          | Initial of piece name                                                   |\n| color                          | Piece color                                                             |\n| fen                            | Fen position                                                            |\n| is_check                       | Is check on board                                                       |\n| is_check_mate                  | Is checkmate on board                                                   |\n| is_fifty_moves                 | Is 50 move complete                                                     |\n| is_fivefold_repetition         | Is 5 fold repetition on board                                           |\n| is_game_over                   | Is game over                                                            |\n| is_insufficient_material       | Is game over from lack of mating material                               |\n| white_count                    | Count of white pieces                                                   |\n| black_count                    | Count of black pieces                                                   |\n| white_{piece}_count            | Count of white specified piece                                          |\n| black_{piece}_count            | Count of black specified piece                                          |\n| captured_score_for_white       | Total of black pieces captured                                          |\n| captured_score_for_black       | Total of white pieces captured                                          |\n| fen_row{number}_{colour)_count | Number of pieces for the specified colour on this row of the board      |\n| fen_row{number}_{colour}_value | Total value of pieces for the specified colour on this row of the board |\n| move_sequence                  | Sequence of moves up to current position                                |\n\n\n## Contributions\n\nContributions are welcome, all modifications should come with appropriate tests demonstrating\nan issue has been resolved, or new functionality is working as intended. Pull Requests without tests\nwill not be merged.\n\nThe library can be tested by doing the following:\n\n    from testing.tests import run_all_tests\n    run_all_tests()\n\nNew tests should be added to the above method.\n\n\n## Acknowledgements\n\nThis project makes use of the [python-chess](https://github.com/niklasf/python-chess) library.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzq99%2Fpgn2data","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzq99%2Fpgn2data","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzq99%2Fpgn2data/lists"}