Metadata-Version: 2.4
Name: riftbound-api
Version: 0.6.0
Summary: REST API for Riftbound catalogue, collections, decks, validation, and analysis.
Project-URL: Homepage, https://github.com/baobabgit/riftbound-api
Project-URL: Documentation, https://github.com/baobabgit/riftbound-api/blob/main/docs/README.md
Project-URL: Repository, https://github.com/baobabgit/riftbound-api
Project-URL: Changelog, https://github.com/baobabgit/riftbound-api/blob/main/CHANGELOG.md
Project-URL: Issues, https://github.com/baobabgit/riftbound-api/issues
Author: ANDRIANAIVO Patrick
License: MIT License
        
        Copyright (c) 2026 baobabgit
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: api,fastapi,riftbound,tcg,trading-card-game
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: FastAPI
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Games/Entertainment
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
Requires-Python: >=3.12
Requires-Dist: fastapi<1.0,>=0.115
Requires-Dist: pydantic-settings<3.0,>=2.7
Requires-Dist: riftbound-core<0.2,>=0.1.1
Requires-Dist: riftbound-database<2,>=1.0.0
Requires-Dist: sqlalchemy<3.0,>=2.0
Requires-Dist: uvicorn[standard]<1.0,>=0.34
Provides-Extra: dev
Requires-Dist: bandit<2.0,>=1.8; extra == 'dev'
Requires-Dist: coverage[toml]<8.0,>=7.6; extra == 'dev'
Requires-Dist: httpx<1.0,>=0.28; extra == 'dev'
Requires-Dist: mypy<2.0,>=1.14; extra == 'dev'
Requires-Dist: psycopg[binary]<4.0,>=3.2; extra == 'dev'
Requires-Dist: pytest-asyncio<1.0,>=0.25; extra == 'dev'
Requires-Dist: pytest<9.0,>=8.3; extra == 'dev'
Requires-Dist: ruff<1.0,>=0.9; extra == 'dev'
Provides-Extra: postgres
Requires-Dist: psycopg[binary]<4.0,>=3.2; extra == 'postgres'
Description-Content-Type: text/markdown

# riftbound-api

API REST FastAPI pour consulter les données Riftbound, gérer des collections et
des decks, puis orchestrer la validation et l'analyse via [`riftbound-core`](https://pypi.org/project/riftbound-core/)
et [`riftbound-database`](https://pypi.org/project/riftbound-database/).

Version actuelle : **0.6.0** (pré-1.0, persistance PostgreSQL collection/decks).

## Installation

Prérequis : Python 3.12 ou 3.13.

```bash
python -m pip install riftbound-api
```

Avec le driver PostgreSQL recommandé en production :

```bash
python -m pip install "riftbound-api[postgres]"
```

Développement local :

```bash
python -m pip install -e ".[dev]"
```

## Démarrage rapide

```bash
export RIFTBOUND_DATABASE_URL="postgresql+psycopg://user:password@localhost:5432/riftbound"
uvicorn riftbound_api.main:app --host 0.0.0.0 --port 8000
```

Sans base configurée, les routes catalogue, collection et decks renvoient
`503 DATABASE_UNAVAILABLE`.

Documentation interactive : `GET /docs` et `GET /openapi.json`.

## Configuration

| Variable | Obligatoire | Défaut | Rôle |
|---|---|---|---|
| `RIFTBOUND_DATABASE_URL` | Oui (prod) | — | URL PostgreSQL (`postgresql+psycopg://…`) |
| `RIFTBOUND_API_ENV` | Non | `development` | Environnement |
| `RIFTBOUND_API_LOG_LEVEL` | Non | `INFO` | Niveau de log JSON |
| `RIFTBOUND_API_CORS_ORIGINS` | Non | vide | Origines CORS autorisées |
| `RIFTBOUND_API_AUTH_MODE` | Non | `disabled` | `disabled`, `api_key` ou `oidc` (réservé) |
| `RIFTBOUND_API_DEV_USER_ID` | Non | `dev-user` | Utilisateur injecté en mode `disabled` |
| `RIFTBOUND_API_API_KEYS` | Non | vide | Clés API `key:user_id` ou JSON |

Les secrets ne sont jamais loggés. Chaque réponse d'erreur inclut un `request_id`
(`X-Request-Id`).

## Endpoints principaux

| Domaine | Exemples |
|---|---|
| Système | `GET /health`, `GET /version` |
| Catalogue | `GET /cards`, `GET /cards/{card_id}` |
| Références | `GET /sets`, `GET /rules/current`, `GET /keywords`, `GET /formats` |
| Collection | `GET /collections/me`, `POST /collections/me/cards` |
| Decks | `GET /decks`, `POST /decks`, `POST /decks/{id}/validate`, `POST /decks/{id}/analyze` |
| Import/export | `POST /decks/import`, `POST /decks/{id}/export` |
| Validation inline | `POST /deck-validation` |

Spécification complète : [`docs/`](docs/README.md).

## Migrations base de données

Les migrations sont fournies par `riftbound-database` :

```bash
python -m pip install riftbound-database
riftbound-db upgrade
```

## Tests d'intégration PostgreSQL

Prérequis locaux : Docker.

Les tests marqués `postgresql` démarrent automatiquement un conteneur éphémère
(`docker compose`, projet `riftbound-api-pytest`) puis l'arrêtent et le suppriment
à la fin de la session pytest.

```bash
python -m pytest -m postgresql -q
```

Pour réutiliser une base déjà disponible (CI ou instance locale) :

```bash
export RIFTBOUND_TEST_POSTGRESQL_URL="postgresql+psycopg://postgres:postgres@localhost:5432/riftbound_test"
python -m pytest -m postgresql -q
```

Pour un PostgreSQL manuel persistant (hors pytest) :

```bash
docker compose up -d
```

## Limitations connues (0.6.0)

- **Authentification OIDC** : `RIFTBOUND_API_AUTH_MODE=oidc` est réservé et rejeté au démarrage.
- **Snapshots de validation API** : repository mémoire process (non persistés PostgreSQL).
- **Snapshots d'analyse deck** : non implémentés côté API.

## Frontière de persistance

`riftbound-api` dépend de `riftbound-database` pour le provider, les sessions,
les repositories catalogue, les transactions et les migrations. `baobab-database`
reste encapsulé et n'est jamais utilisé directement par l'API.

SQLAlchemy est déclaré uniquement pour classifier ses exceptions publiques lors
du mapping HTTP. L'API ne définit aucun modèle, repository, moteur ou migration
SQLAlchemy propre.

## Qualité

```bash
python -m ruff check .
python -m mypy src tests
python -m coverage run -m pytest -m "not integration and not postgresql" -q
python -m coverage report --fail-under=85
```

## Licence

MIT — voir [LICENSE](LICENSE).
