pypaya-pgn-parser


Namepypaya-pgn-parser JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttps://github.com/PypayaTech/pypaya-pgn-parser
SummaryA lightweight Python package that provides efficient parsing capabilities for Portable Game Notation (PGN) chess files
upload_time2024-09-18 15:49:30
maintainerNone
docs_urlNone
authorPypayaTech
requires_python<4.0,>=3.7
licenseMIT
keywords chess pgn parser
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pypaya-pgn-parser

A lightweight Python package that provides efficient parsing capabilities for Portable Game Notation (PGN) chess files.

## Features

- Fast and memory-efficient PGN parsing
- Robust handling of various PGN formats and edge cases
- Easy-to-use API for integrating into your chess applications
- No external dependencies for core functionality

## Installation

You can install pypaya-pgn-parser using pip:

```bash
pip install pypaya-pgn-parser
```

## Usage

Here's a quick example of how to use pypaya-pgn-parser:

```python
from io import StringIO
from pypaya_pgn_parser.pgn_parser import PGNParser


def process_pgn_file(file_path):
    # Initialize the parser
    parser = PGNParser()

    # Read the entire file into a StringIO object
    with open(file_path, 'r') as file:
        file_content = file.read()
    pgn_stringio = StringIO(file_content)

    game_count = 0

    while True:
        # Parse the next game
        result = parser.parse(pgn_stringio)

        # Check if we've reached the end of the file or encountered an error
        if result is None:
            print(f"Reached end of file or encountered an error after processing {game_count} games.")
            break

        game_info, game_moves = result

        # Process the game
        process_game(game_count, game_info, game_moves)
        game_count += 1

    print(f"Total games processed: {game_count}")


def process_game(game_number, game_info, game_moves):
    print(f"\nGame {game_number + 1} information:")
    for header, value in zip(["Event", "Site", "Date", "Round", "White", "Black", "Result"], game_info):
        print(f"{header}: {value}")

    print("\nMoves:")
    print(game_moves)

    # You can add more processing here, such as analyzing the moves,
    # storing the data, or any other operation you need to perform on each game


# Usage
file_path = "example.pgn"
process_pgn_file(file_path)
```

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/PypayaTech/pypaya-pgn-parser",
    "name": "pypaya-pgn-parser",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.7",
    "maintainer_email": null,
    "keywords": "chess, pgn, parser",
    "author": "PypayaTech",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/e9/75/3d82c32594629d366f27d31be994c700ac923a8ddbeb260b3bfc3b0a7754/pypaya_pgn_parser-0.1.1.tar.gz",
    "platform": null,
    "description": "# pypaya-pgn-parser\n\nA lightweight Python package that provides efficient parsing capabilities for Portable Game Notation (PGN) chess files.\n\n## Features\n\n- Fast and memory-efficient PGN parsing\n- Robust handling of various PGN formats and edge cases\n- Easy-to-use API for integrating into your chess applications\n- No external dependencies for core functionality\n\n## Installation\n\nYou can install pypaya-pgn-parser using pip:\n\n```bash\npip install pypaya-pgn-parser\n```\n\n## Usage\n\nHere's a quick example of how to use pypaya-pgn-parser:\n\n```python\nfrom io import StringIO\nfrom pypaya_pgn_parser.pgn_parser import PGNParser\n\n\ndef process_pgn_file(file_path):\n    # Initialize the parser\n    parser = PGNParser()\n\n    # Read the entire file into a StringIO object\n    with open(file_path, 'r') as file:\n        file_content = file.read()\n    pgn_stringio = StringIO(file_content)\n\n    game_count = 0\n\n    while True:\n        # Parse the next game\n        result = parser.parse(pgn_stringio)\n\n        # Check if we've reached the end of the file or encountered an error\n        if result is None:\n            print(f\"Reached end of file or encountered an error after processing {game_count} games.\")\n            break\n\n        game_info, game_moves = result\n\n        # Process the game\n        process_game(game_count, game_info, game_moves)\n        game_count += 1\n\n    print(f\"Total games processed: {game_count}\")\n\n\ndef process_game(game_number, game_info, game_moves):\n    print(f\"\\nGame {game_number + 1} information:\")\n    for header, value in zip([\"Event\", \"Site\", \"Date\", \"Round\", \"White\", \"Black\", \"Result\"], game_info):\n        print(f\"{header}: {value}\")\n\n    print(\"\\nMoves:\")\n    print(game_moves)\n\n    # You can add more processing here, such as analyzing the moves,\n    # storing the data, or any other operation you need to perform on each game\n\n\n# Usage\nfile_path = \"example.pgn\"\nprocess_pgn_file(file_path)\n```\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A lightweight Python package that provides efficient parsing capabilities for Portable Game Notation (PGN) chess files",
    "version": "0.1.1",
    "project_urls": {
        "Homepage": "https://github.com/PypayaTech/pypaya-pgn-parser",
        "Repository": "https://github.com/PypayaTech/pypaya-pgn-parser"
    },
    "split_keywords": [
        "chess",
        " pgn",
        " parser"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9f05324b38f6933dda1fc2556b55424bb5a5bfe3dffbede70fcdff2cd656c872",
                "md5": "0b4a651a693d2beded9ebb413a0d6c0e",
                "sha256": "d8ae9bb910d30567816452b53976e231ded79fef3ff8b58a7ebe61b3674b8652"
            },
            "downloads": -1,
            "filename": "pypaya_pgn_parser-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0b4a651a693d2beded9ebb413a0d6c0e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.7",
            "size": 6913,
            "upload_time": "2024-09-18T15:49:28",
            "upload_time_iso_8601": "2024-09-18T15:49:28.887991Z",
            "url": "https://files.pythonhosted.org/packages/9f/05/324b38f6933dda1fc2556b55424bb5a5bfe3dffbede70fcdff2cd656c872/pypaya_pgn_parser-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e9753d82c32594629d366f27d31be994c700ac923a8ddbeb260b3bfc3b0a7754",
                "md5": "09e23d4c466a1b8042329c8d51c7b288",
                "sha256": "0b1e436d90ee24e7d8e50c734d0a23939bd23d6b0c9469106107bc202da4c12f"
            },
            "downloads": -1,
            "filename": "pypaya_pgn_parser-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "09e23d4c466a1b8042329c8d51c7b288",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.7",
            "size": 5570,
            "upload_time": "2024-09-18T15:49:30",
            "upload_time_iso_8601": "2024-09-18T15:49:30.478482Z",
            "url": "https://files.pythonhosted.org/packages/e9/75/3d82c32594629d366f27d31be994c700ac923a8ddbeb260b3bfc3b0a7754/pypaya_pgn_parser-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-18 15:49:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "PypayaTech",
    "github_project": "pypaya-pgn-parser",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pypaya-pgn-parser"
}
        
Elapsed time: 0.33203s