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:
pip install pypaya-pgn-parser
Usage
Here's a quick example of how to use pypaya-pgn-parser:
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 file for details.
Metadata
Release files for pypaya-pgn-parser 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pypaya_pgn_parser-0.1.1.tar.gz | 5.6 kB | Without provenance | Details for pypaya_pgn_parser-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pypaya_pgn_parser-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for pypaya_pgn_parser-0.1.1-py3-none-any.whl |
Total release size: 12.5 kB
Release files / pypaya_pgn_parser-0.1.1.tar.gz
| Download URL | pypaya_pgn_parser-0.1.1.tar.gz |
|---|---|
| Size | 5.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0b1e436d90ee24e7d8e50c734d0a23939bd23d6b0c9469106107bc202da4c12f
|
|
BLAKE2b-256 checksum How to use checksums |
e9753d82c32594629d366f27d31be994c700ac923a8ddbeb260b3bfc3b0a7754
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.9
|
Release files / pypaya_pgn_parser-0.1.1-py3-none-any.whl
| Download URL | pypaya_pgn_parser-0.1.1-py3-none-any.whl |
|---|---|
| Size | 6.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d8ae9bb910d30567816452b53976e231ded79fef3ff8b58a7ebe61b3674b8652
|
|
BLAKE2b-256 checksum How to use checksums |
9f05324b38f6933dda1fc2556b55424bb5a5bfe3dffbede70fcdff2cd656c872
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.9
|
Security for pypaya-pgn-parser 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.