Metadata-Version: 2.1
Name: pypaya-pgn-parser
Version: 0.1.1
Summary: A lightweight Python package that provides efficient parsing capabilities for Portable Game Notation (PGN) chess files
Home-page: https://github.com/PypayaTech/pypaya-pgn-parser
License: MIT
Keywords: chess,pgn,parser
Author: PypayaTech
Requires-Python: >=3.7,<4.0
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Dist: typing-extensions (>=4.0.0,<5.0.0) ; python_version < "3.8"
Project-URL: Repository, https://github.com/PypayaTech/pypaya-pgn-parser
Description-Content-Type: text/markdown

# 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.

