Metadata-Version: 2.1
Name: sdamgia
Version: 0.2.0
Summary: Unofficial API for SdamGIA educational portal for exam preparation written in Python.
License: LGPL-3.0-or-later
Keywords: sdamgia,api,asyncio
Author: Динаzavr
Author-email: dinaprk@cumallover.me
Requires-Python: >=3.10,<4.0
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Framework :: AsyncIO
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Provides-Extra: pix2tex
Requires-Dist: aiohttp (>=3.9.5,<4.0.0)
Requires-Dist: cairosvg (>=2.7.0,<3.0.0)
Requires-Dist: pillow (>=10.2.0,<11.0.0)
Requires-Dist: pix2tex[cli] (>=0.1.2,<0.2.0) ; extra == "pix2tex"
Requires-Dist: selectolax (>=0.3.21,<0.4.0)
Project-URL: Documentation, https://dinaprk.github.io/sdamgia-python
Project-URL: Issue Tracker, https://github.com/dinaprk/sdamgia-python/issues
Project-URL: Repository, https://github.com/dinaprk/sdamgia-python
Description-Content-Type: text/markdown

# 📚 SdamGIA API

[![License](https://img.shields.io/pypi/l/sdamgia?color=green&style=flat-square)](https://github.com/dinaprk/sdamgia-python/blob/master/LICENSE)
[![Version](https://img.shields.io/pypi/v/sdamgia?style=flat-square)](https://pypi.org/project/sdamgia)
[![Python Version](https://img.shields.io/pypi/pyversions/sdamgia?style=flat-square)](https://pypi.org/project/sdamgia)
[![Status](https://img.shields.io/pypi/status/sdamgia?style=flat-square)](https://pypi.org/project/sdamgia)
[![Documentation](https://img.shields.io/github/actions/workflow/status/dinaprk/sdamgia-python/docs.yml?label=docs&style=flat-square)](https://dinaprk.github.io/sdamgia-python)

Unofficial API for SdamGIA educational portal for exam preparation written in Python.

### ⚠️ Important Note

This library retrieves data by parsing HTML because sdamgia uses server-side rendering, which
is not very reliable, but the only method available at the moment. We strive to keep the API
up to date to work as expected. However, if you encounter any issues,
please [report them](https://github.com/dinaprk/sdamgia-python/issues).

Use of this library is at your own risk. Sdamgia explicitly restricts parsing, and we do not
take responsibility for any legal issues that arise from using this library.

## 📦 Installing

**Python 3.10 or above is required.**

### pip

Installing the library with `pip` is quite simple:

```shell
pip install -U sdamgia
```

For full problem text recognition support `pix2tex` extra is required,
which can be installed like so:

```shell
pip install -U "sdamgia[pix2tex]"
```

### poetry

You can add the library as a dependency like so:

```shell
poetry add sdamgia
```

With full text recognition support:

```shell
poetry add sdamgia --extras pix2tex
```

## 🗂️ Problems database structure

To make it easier to understand how the SdamGIA problems database is structured, I suggest using
the following scheme:

```
SdamGIA
└── GIA type, Subject
    ├── Problem catalog
    │   └── Topic
    │       └── Category
    │           └── Problem
    └── Test
        └── Problem
```

Each problem, test, theme or category has its own *unique* integer ID.

## 📃 Documentation

You can find the documentation [here](https://dinaprk.github.io/sdamgia-python).

## 🚀 Basic usage

Because SdamgiaAPI client is asynchronous, it needs to be initialized in asynchronous context:

```python
import asyncio
import dataclasses
import json

from sdamgia import SdamgiaAPI
from sdamgia.types import Problem
from sdamgia.enums import GiaType, Subject


def problem_to_json(problem: Problem) -> str:
    return json.dumps(dataclasses.asdict(problem), indent=4, ensure_ascii=False)


async def main() -> None:
    async with SdamgiaAPI(gia_type=GiaType.EGE, subject=Subject.MATH) as sdamgia:
        problem_id = 26596
        problem = await sdamgia.get_problem(problem_id, subject=Subject.MATH)
        print(problem_to_json(problem))
        print(problem.url)  # https://math-ege.sdamgia.ru/problem?id=26596


if __name__ == "__main__":
    asyncio.run(main())
```

Or without context manager:

```python
from sdamgia import SdamgiaAPI
from sdamgia.enums import GiaType, Subject


async def main() -> None:
    sdamgia = SdamgiaAPI(gia_type=GiaType.EGE, subject=Subject.MATH)
    # ... do something with client
    await sdamgia.close()  # this line is mandatory
```

## 📜 License

This project is licensed under the LGPLv3+ license - see the
[license file](https://github.com/dinaprk/sdamgia-python/blob/master/LICENSE) for details.

