Metadata-Version: 2.1
Name: thestorygraph-client
Version: 0.1.1
Summary: A Simple Python Client for TheStoryGraph
Home-page: https://github.com/altvod/thestorygraph-client
Author: Grigory Statsenko
Author-email: grisha100@gmail.com
License: UNKNOWN
Project-URL: Bug Tracker, https://github.com/altvod/thestorygraph-client/issues
Keywords: thestorygraph,books,client
Platform: UNKNOWN
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: aiohttp
Requires-Dist: attrs
Requires-Dist: beautifulsoup4
Requires-Dist: requests
Requires-Dist: yarl
Provides-Extra: build
Requires-Dist: build ; extra == 'build'
Requires-Dist: twine ; extra == 'build'
Provides-Extra: testing
Requires-Dist: mypy ; extra == 'testing'
Requires-Dist: pytest ; extra == 'testing'
Requires-Dist: types-requests ; extra == 'testing'

# thestorygraph-client

A Simple Python Client for TheStoryGraph.com

Sync and async clients as well as a model abstraction layer for the website.

Since no public API is available, this library parses HTML via `BeautifulSoup4`
and loads the data into model objects.


## Installation

```bash
pip install thestorygraph-client
```

## Examples

### Search for books (sync)

Find and print books related to `'SPQR'`:

```python
from tsg.client import SyncTSGClient

def print_search_result(search_text: str) -> None:
    client = SyncTSGClient()
    book_list = client.search(text=search_text)
    for book in book_list:
        print(f'{book.authors[0].name} - {book.title}')

print_search_result('SPQR')
```

### Search for books (async)

Same as above, but using the asynchronous client:

```python
import asyncio
from tsg.client import AsyncTSGClient

async def print_search_result(search_text: str) -> None:
    client = AsyncTSGClient()
    book_list = await client.get_browse(text=search_text)
    for book in book_list:
        print(f'{", ".join(book.author_names)} - {book.title}')

asyncio.run(print_search_result('SPQR'))
```

The two clients have identical APIs (beside the fact that the latter is async).

### Get a book by ID

```python
import asyncio
from tsg.client import AsyncTSGClient

async def print_book_by_id(book_id: str) -> None:
    client = AsyncTSGClient()
    book = await client.get_book(id=book_id)
    print(f'{book.title} by {", ".join(book.author_names)}')

asyncio.run(print_book_by_id('79b894b0-df12-4bb6-89d7-40288f28acc1'))
```

## Development and Testing

### Configuring the test environment

Install

```bash
pip install -Ue .[testing]
```

### Testing

Run the tests:

```bash
pytest tests
```

And always validate typing:

```bash
mypy src/tsg
```

Or simply

```bash
make test
```

(it will run all test commands)

## Links

Homepage on GitHub: https://github.com/altvod/thestorygraph-client

Project's page on PyPi: https://pypi.org/project/thestorygraph-client/

TheStoryGraph: https://thestorygraph.com/


