Lightweight Python wrapper for Gallica (BnF) SRU & IIIF.
Project description
pyGallica
pyGallica est un wrapper Python léger pour l’API SRU et IIIF de Gallica (BnF). Il fournit :
- un client HTTP (basé sur
httpx) avec retries, - des helpers CQL pour construire des requêtes,
- un itérateur de recherche paginée,
- un parseur XML → objets Python / JSON / DataFrame,
- et quelques utilitaires IIIF (manifest, vignettes, pages).
⚠️ Respectez les CGU de Gallica (quotas, réutilisation, attribution). Ce projet n’est ni affilié ni supporté par la BnF.
Installation
# depuis la racine du repo
pip install -e ".[pandas]"
# ou sans pandas
pip install -e .
Python 3.10+ recommandé.
Exemples d’usage
Recherche SRU simple (paginée)
from pyGallica import GallicaClient, build_cql, search_iter
cli = GallicaClient(user_agent="pyGallica/0.1")
# Exemple : cartes/images sur "Paris" vers 1900
q = build_cql(title="Paris", doc_type="image", date="1900")
records = list(search_iter(cli, free_cql=q, page_size=50, limit=150))
print(f"Fetched {len(records)} records")
print(records[0].ark, records[0].title)
Conversion en JSON / DataFrame
from pyGallica import records_to_json, records_to_dataframe
js = records_to_json(records)
print(js[0])
# DataFrame (si pandas installé)
df = records_to_dataframe(records)
print(df.head())
IIIF : manifest & vignettes
from pyGallica import GallicaClient
cli = GallicaClient()
ark = "ark:/12148/btv1b1234567z"
manifest = cli.get_manifest(ark)
pages = cli.list_pages_from_manifest(manifest)
print(f"{len(pages)} pages")
thumb = cli.get_thumbnail(ark, page=1, max_width=300)
with open("thumb.jpg", "wb") as f:
f.write(thumb)
Concepts clés
SRU : recherche via CQL (dc.title, dc.creator, dc.date, dc.type, dc.language, dc.subject, …).
Helpers fournis : cql_all, cql_any, cql_and, cql_or, build_cql.
Pagination : basée sur startRecord, maximumRecords et nextRecordPosition.
Utilisez search_iter() pour streamer les résultats.
IIIF : récupération de manifest.json, listing des pages et tuiles images.
API de haut niveau (sélection)
from pyGallica import (
GallicaClient, validate_ark,
build_cql, cql_all, cql_any, cql_and, cql_or,
search_iter, search_all,
parse_sru_xml, records_to_json, records_to_dataframe,
SRURecord, SRUResult,
GallicaError, GallicaHTTPError, GallicaAPIError, GallicaParseError,
)
Développement
Installer les dépendances
python -m pip install -U pip setuptools wheel
pip install -e ".[pandas]" pytest ruff black
Lancer les tests
pytest -q
Lint & format
ruff check .
black --check .
# ou formatage
black .
Compatibilité & limites
L’API SRU de Gallica est hétérogène : certains enregistrements utilisent <oai_dc:dc>, d’autres un conteneur <dc> simple. Le parseur est tolérant et lit les dc:* depuis recordData.
dc:identifier peut contenir un ARK ou une URL complète : pyGallica tente d’extraire l’ARK (ark:/...) quand c’est pertinent.
Licence
MIT – voir LICENSE
.
Pensez à créditer Gallica / BnF et à respecter leurs conditions d’utilisation.
---
### `LICENSE` (MIT)
```text
MIT License
Copyright (c) 2025 Your Name
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pygallica-0.1.0.tar.gz.
File metadata
- Download URL: pygallica-0.1.0.tar.gz
- Upload date:
- Size: 12.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
870d4bd07cf85902bcc42514a469ba4fb1591aee66b8bfe49f0d7b5e0bc7e488
|
|
| MD5 |
b201d0c1a42dfcafade96b447ff49466
|
|
| BLAKE2b-256 |
efc6739a70354b71cf26e8887f295bb394f2d588b49ff375e19a7b72f78fcb19
|
Provenance
The following attestation bundles were made for pygallica-0.1.0.tar.gz:
Publisher:
publish.yml on maxcasado/pyGallica
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pygallica-0.1.0.tar.gz -
Subject digest:
870d4bd07cf85902bcc42514a469ba4fb1591aee66b8bfe49f0d7b5e0bc7e488 - Sigstore transparency entry: 603143654
- Sigstore integration time:
-
Permalink:
maxcasado/pyGallica@c02db11f88588f8d7c11dc6837ac5ec2b01ea2f0 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/maxcasado
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c02db11f88588f8d7c11dc6837ac5ec2b01ea2f0 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pygallica-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pygallica-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f7d5a97e56d2ec92678c610a18bf74dd517828cc899e8aa4de80eae4bbb0bf06
|
|
| MD5 |
dc481af2b94a262a710fa404d4f91419
|
|
| BLAKE2b-256 |
39eafcc9a7c7d1c63807070441aabe0f2772861b0d76b4500cca1019bd0d9c77
|
Provenance
The following attestation bundles were made for pygallica-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on maxcasado/pyGallica
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pygallica-0.1.0-py3-none-any.whl -
Subject digest:
f7d5a97e56d2ec92678c610a18bf74dd517828cc899e8aa4de80eae4bbb0bf06 - Sigstore transparency entry: 603143701
- Sigstore integration time:
-
Permalink:
maxcasado/pyGallica@c02db11f88588f8d7c11dc6837ac5ec2b01ea2f0 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/maxcasado
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c02db11f88588f8d7c11dc6837ac5ec2b01ea2f0 -
Trigger Event:
push
-
Statement type: