Skip to main content

A Python wrapper for multi-threaded retrieval from Gallica API endpoints

Project description

gallicaGetter

This tool wraps a few endpoints from the Gallica API.

Current endpoints are:

  • 'content' : context for term occurrence and page numbers
  • 'sru' : for a term, all the volumes the term appears in
  • 'text' : full text for a volume on Gallica
  • 'papers' : paper titles and publishing range data
  • 'issues' : years published for a paper (used internally in papers)

I developed this tool into a graphing app similar to Google's n-gram viewer for books.

For an exact number of occurrences over a period, use Pyllicagram.

Installation

pip install gallicaGetter

Content example

This wrapper pairs best with an SRU fetch since the ark code for an issue is in the SRU response.

Build the content wrapper using connect(), fetch using get():

import gallicaGetter

contentWrapper = gallicaGetter.connect('content')

data = contentWrapper.get(
    ark='bpt6k270178t',
    term='guerre',
)

for contentRecord in data:
    print(contentRecord.num_results)
    print(contentRecord.get_pages())

SRU examples

Build the wrapper object using the connect() factory:

import gallicaGetter

sruWrapper = gallicaGetter.connect('sru')

Then, retrieve records or counts using get().

get(terms, generate=False, **kwargs)

PARAMETERS:

  • terms: a string, or list of strings, to search for.
  • startDate: lower year boundary for the search.
  • endDate: upper year boundary for the search.
  • codes: string paper codes to restrict the search. Can be found in the URL of a Gallica periodical's page.
  • grouping: 'year', 'month', or 'all'
  • generate: if True, returns a generator object. Otherwise, returns a list of results.
  • linkTerm: a string that restricts the search to occurrences within its proximity.
  • linkDistance: proximity distance in words.

Retrieve the number of volumes with >= 1 mention of "Victor Hugo" across the Gallica archive from 1800 to 1900, by year, running 30 requests in parallel.

import gallicaGetter

sruWrapper = gallicaGetter.connect('sru', numWorkers=30)

records = sruWrapper.get(
    terms="Victor Hugo",
    startDate="1800",
    endDate="1900",
    grouping="year"
)

for record in records:
    print(record.getRow())

Retrieve 15 issues that mention "Brazza" from 1890 to 1900.

import gallicaGetter

sruWrapper = gallicaGetter.connect('sru')

records = sruWrapper.get(
    terms="Brazza",
    startDate="1890",
    endDate="1900",
    grouping="all",
    numRecords=15
)

for record in records:
    print(record.getRow())

Retrieve all occurrences of "Brazza" within 10 words of "Congo" in the paper "Le Temps" from 1890 to 1900.

import gallicaGetter

sruWrapper = gallicaGetter.connect('sru')

records = sruWrapper.get(
    terms="Brazza",
    startDate="1890",
    endDate="1900",
    linkTerm="Congo",
    linkDistance=10,
    grouping="all",
    codes="cb34431794k"
)

for record in records:
    print(record.getRow())

Retrieve all issues mentioning "Paris" in the papers "Le Temps" and "Le Figaro" from 1890 to 1900.

import gallicaGetter

sruWrapper = gallicaGetter.connect('sru')

recordGenerator = sruWrapper.get(
    terms="Paris",
    startDate="1890",
    endDate="1900",
    grouping="all",
    codes=["cb34431794k", "cb34355551z"]
)

for record in recordGenerator:
    print(record.getRow())

Full text example

Retrieve a volume's text from its ark code. Pass a list of codes to retrieve multiple sets of text.

import gallicaGetter

textWrapper = gallicaGetter.connect('text')

data = textWrapper.get('bpt6k270178t')

for textRecord in data:
    print(textRecord.get_ocr_quality())
    print(textRecord.get_text())

Papers example

Retrieve metadata from a Gallica periodical's code. Example for "Le Temps":

import gallicaGetter

papersWrapper = gallicaGetter.connect('papers')

metadata = papersWrapper.get('cb34431794k')

for record in metadata:
    print(record.getRow())
    print(record.isContinuous())

Issues example

The papers wrapper calls this internally, but it might be useful. For a paper code, retrieve all years with at least one issue archived on Gallica.

import gallicaGetter

issuesWrapper = gallicaGetter.connect('issues')

years = issuesWrapper.get('cb34431794k')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gallicagetter-0.0.8.tar.gz (31.1 kB view details)

Uploaded Source

Built Distribution

gallicagetter-0.0.8-py3-none-any.whl (42.6 kB view details)

Uploaded Python 3

File details

Details for the file gallicagetter-0.0.8.tar.gz.

File metadata

  • Download URL: gallicagetter-0.0.8.tar.gz
  • Upload date:
  • Size: 31.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for gallicagetter-0.0.8.tar.gz
Algorithm Hash digest
SHA256 d4264576c853f18ce3d3dfd747fea3848404a8cc701596d66b4cbbad5b585f85
MD5 dfe944ec4ef79a5561bfc59f8883aba8
BLAKE2b-256 3d916be7a0b38e49c56d31c8d87581f36951ecbdbdf1d2bfbde8d0f4c46e95d7

See more details on using hashes here.

File details

Details for the file gallicagetter-0.0.8-py3-none-any.whl.

File metadata

File hashes

Hashes for gallicagetter-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 c7390ae04f2dfe9ed849e0148d1ddf3ba46b0e533b7069f97cca12187619b0db
MD5 c2a69f4c29a0052e5c55b331b02c217e
BLAKE2b-256 cf357271d9dc24813d18ef36a4452f211eaac7274330594c4670bd1006020c36

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page