sruthi


Namesruthi JSON
Version 2.0.0 PyPI version JSON
download
home_pagehttps://github.com/metaodi/sruthi
SummarySRU client for Python
upload_time2023-07-05 23:27:52
maintainerStefan Oderbolz
docs_urlNone
authorStefan Oderbolz
requires_python>=3.7
licenseMIT
keywords sru search retrieve archive library
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![PyPI Version](https://img.shields.io/pypi/v/sruthi)](https://pypi.org/project/sruthi/)
[![Tests + Linting Python](https://github.com/metaodi/sruthi/actions/workflows/lint_python.yml/badge.svg)](https://github.com/metaodi/sruthi/actions/workflows/lint_python.yml)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

# sruthi

**sru**thi is a client for python to make [SRU requests (Search/Retrieve via URL)](http://www.loc.gov/standards/sru/).

Currently only **SRU 1.1 and 1.2** is supported.

## Table of Contents

* [Installation](#installation)
* [Usage](#usage)
    * [`searchretrieve` operation](#searchretrieve-operation)
    * [`explain` operation](#explain-operation)
    * [Request for SRU 1.1](#request-for-sru-11)
* [Schemas](#schemas)
* [Development](#development)
* [Release](#release)

## Installation

[sruthi is available on PyPI](https://pypi.org/project/sruthi/), so to install it simply use:

```
$ pip install sruthi
```

## Usage

See the [`examples` directory](https://github.com/metaodi/sruthi/tree/master/examples) for more scripts.

### `searchretrieve` operation

```python
>>> import sruthi
>>> records = sruthi.searchretrieve('https://suche.staatsarchiv.djiktzh.ch/SRU/', query='Brettspiel')
>>> print(records)
SearchRetrieveResponse(sru_version='1.2',count=500,next_start_record=11)
>>> print(records.count)
4
>>> print(record[0])
{'schema': 'isad', 'reference': 'PAT 2, 54 d, Nr. 253492', 'title': 'Schlumberger, Jean, Zürich: Brettspiel', 'date': '08.03.1946', 'descriptionlevel': 'Dossier', 'extent': None, 'creator': None, 'extra': {'score': '0.4', 'link': 'https://suche.staatsarchiv.djiktzh.ch/detail.aspx?Id=1114641', 'beginDateISO': '1946-03-08', 'beginApprox': '0', 'endDateISO': '1946-03-08', 'endApprox': '0', 'hasDigitizedItems': '0'}}
>>>
>>> for record in records:
...    # print fields from schema
...    print(record['reference'])
...    print(record['title'])
...    print(record['date'])
...    print(record['extra']['link']) # extra record data is available at the 'extra' key
PAT 2, 54 d, Nr. 253492
Schlumberger, Jean, Zürich: Brettspiel
08.03.1946
https://suche.staatsarchiv.djiktzh.ch/detail.aspx?Id=1114641
PAT 2, 54 d, Nr. 246025
Frei, K. H., Weisslingen: Brettspiel
26.10.1945
https://suche.staatsarchiv.djiktzh.ch/detail.aspx?Id=1114639
DS 107.2.37
UZH Magazin
Die Wissenschaftszeitschrift
2019
https://suche.staatsarchiv.djiktzh.ch/detail.aspx?Id=4612939
G I 1, Nr. 34
Verordnung der Stadt Zürich betreffend die Erfüllung von Amtspflichten durch die Chorherren des Grossmünsterstifts
24.09.1485
https://suche.staatsarchiv.djiktzh.ch/detail.aspx?Id=3796980
```

The return value of `searchretrieve` is iterable, so you can easily loop over it.
Or you can use indices to access records, e.g. `records[1]` to get the second record, or `records[-1]` to get the last one.

Even [slicing](https://python-reference.readthedocs.io/en/latest/docs/brackets/slicing.html) is supported, so you can do things like only iterate over the first 5 elements using

```python
for records in records[:5]:
   print(record)
```

### `explain` operation

The `explain` operation returns a dict-like object.
The values can either be accessed as keys `info['sru_version']` or as attributes `info.sru_version`.

```python
>>> import sruthi
>>> info = sruthi.explain('https://suche.staatsarchiv.djiktzh.ch/SRU/')
>>> info
{'sru_version': '1.2', 'server': {'host': 'https://suche.staatsarchiv.djiktzh.ch/Sru', 'port': 80, 'database': 'sru'}, 'database': {'title': 'Staatsarchiv Zürich Online Search', 'description': 'Durchsuchen der Bestände des Staatsarchiv Zürichs.', 'contact': 'staatsarchivzh@ji.zh.ch'}, 'index': {'isad': {'title': 'Title', 'reference': 'Reference Code', 'date': 'Date', 'descriptionlevel': 'Level'}}, 'schema': {'isad': {'identifier': 'http://www.expertisecentrumdavid.be/xmlschemas/isad.xsd', 'name': 'isad', 'title': 'ISAD(G)'}}, 'config': {'maximumRecords': 99, 'defaults': {'numberOfRecords': 99}}}
>>> info.server
{'host': 'https://suche.staatsarchiv.djiktzh.ch/Sru', 'port': 80, 'database': 'sru'}
>>> info.database
{'title': 'Staatsarchiv Zürich Online Search', 'description': 'Durchsuchen der Bestände des Staatsarchiv Zürichs.', 'contact': 'staatsarchivzh@ji.zh.ch'}
>>> info['index']
{'isad': {'title': 'Title', 'reference': 'Reference Code', 'date': 'Date', 'descriptionlevel': 'Level'}}
>>> info['schema']
{'isad': {'identifier': 'http://www.expertisecentrumdavid.be/xmlschemas/isad.xsd', 'name': 'isad', 'title': 'ISAD(G)'}}
```

### Request for SRU 1.1

By default sruthi uses SRU 1.2 to make requests, but you can specify the SRU version for each call or when you create a new client instance:

```python
>>> import sruthi
>>> # create a client
>>> client = sruthi.Client(
...     'https://services.dnb.de/sru/dnb',
...     record_schema='oai_dc',
...     sru_version='1.1'
>>> )
>>> records = client.searchretrieve(query="Zurich")
>>> records.count
8985
>>> # ...or pass the version directly to the call
>>> records = sruthi.searchretrieve(
...     'https://services.dnb.de/sru/dnb',
...     query="Zurich",
...     record_schema='oai_dc',
...     sru_version='1.1'
>>> )
>>> records.count
8985
```

### Custom parameters and settings

If an SRU endpoint needs additional (custom) parameters, you can create your own session object and pass it to the client.
This is useful for adding authentication (username, password), custom headers or parameters, SSL verification settings etc.

```python
>>> import sruthi
>>> import requests
>>> # customize session
>>> session = requests.Session()
>>> session.params = {"x-collection": "GGC"}
>>> # pass the customized session to sruthi
>>> records = sruthi.searchretrieve("https://jsru.kb.nl/sru", query="gruninger", session=session)
>>> records.count
4
```

## Schemas

sruthi does not make any assumptions about the record data schema.
The data is provided as-is (as a flattend dict).
sruthi has been tested with the following schemas:

* [Dublin Core Record Schema](http://www.loc.gov/standards/sru/recordSchemas/dc-schema.html) (dc)
* [MARCXML: The MARC 21 XML Schema](http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd) (marcxml)
* [ISAD(G): General International Standard Archival Description, Second edition](http://www.expertisecentrumdavid.be/xmlschemas/isad.xsd) (isad)

## Development

To contribute to sruthi simply clone this repository and follow the instructions in [CONTRIBUTING.md](/CONTRIBUTING.md).

This project has a `Makefile` with the most common commands.
Type `make help` to get an overview.

## Release

To create a new release, follow these steps (please respect [Semantic Versioning](http://semver.org/)):

1. Adapt the version number in `sruthi/__init__.py`
1. Update the CHANGELOG with the version
1. Create a pull request to merge `develop` into `master` (make sure the tests pass!)
1. Create a [new release/tag on GitHub](https://github.com/metaodi/sruthi/releases) (on the master branch)
1. The [publication on PyPI](https://pypi.python.org/pypi/sruthi) happens via [GitHub Actions](https://github.com/metaodi/sruthi/actions?query=workflow%3A%22Upload+Python+Package%22) on every tagged commit



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/metaodi/sruthi",
    "name": "sruthi",
    "maintainer": "Stefan Oderbolz",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "odi@metaodi.ch",
    "keywords": "sru,search,retrieve,archive,library",
    "author": "Stefan Oderbolz",
    "author_email": "odi@metaodi.ch",
    "download_url": "https://files.pythonhosted.org/packages/66/25/96324a7413692ab1aa4cb1648af6a4fa1ae4d2db406a25cd04830d6cb6f0/sruthi-2.0.0.tar.gz",
    "platform": null,
    "description": "[![PyPI Version](https://img.shields.io/pypi/v/sruthi)](https://pypi.org/project/sruthi/)\n[![Tests + Linting Python](https://github.com/metaodi/sruthi/actions/workflows/lint_python.yml/badge.svg)](https://github.com/metaodi/sruthi/actions/workflows/lint_python.yml)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n\n# sruthi\n\n**sru**thi is a client for python to make [SRU requests (Search/Retrieve via URL)](http://www.loc.gov/standards/sru/).\n\nCurrently only **SRU 1.1 and 1.2** is supported.\n\n## Table of Contents\n\n* [Installation](#installation)\n* [Usage](#usage)\n    * [`searchretrieve` operation](#searchretrieve-operation)\n    * [`explain` operation](#explain-operation)\n    * [Request for SRU 1.1](#request-for-sru-11)\n* [Schemas](#schemas)\n* [Development](#development)\n* [Release](#release)\n\n## Installation\n\n[sruthi is available on PyPI](https://pypi.org/project/sruthi/), so to install it simply use:\n\n```\n$ pip install sruthi\n```\n\n## Usage\n\nSee the [`examples` directory](https://github.com/metaodi/sruthi/tree/master/examples) for more scripts.\n\n### `searchretrieve` operation\n\n```python\n>>> import sruthi\n>>> records = sruthi.searchretrieve('https://suche.staatsarchiv.djiktzh.ch/SRU/', query='Brettspiel')\n>>> print(records)\nSearchRetrieveResponse(sru_version='1.2',count=500,next_start_record=11)\n>>> print(records.count)\n4\n>>> print(record[0])\n{'schema': 'isad', 'reference': 'PAT 2, 54 d, Nr. 253492', 'title': 'Schlumberger, Jean, Z\u00fcrich: Brettspiel', 'date': '08.03.1946', 'descriptionlevel': 'Dossier', 'extent': None, 'creator': None, 'extra': {'score': '0.4', 'link': 'https://suche.staatsarchiv.djiktzh.ch/detail.aspx?Id=1114641', 'beginDateISO': '1946-03-08', 'beginApprox': '0', 'endDateISO': '1946-03-08', 'endApprox': '0', 'hasDigitizedItems': '0'}}\n>>>\n>>> for record in records:\n...    # print fields from schema\n...    print(record['reference'])\n...    print(record['title'])\n...    print(record['date'])\n...    print(record['extra']['link']) # extra record data is available at the 'extra' key\nPAT 2, 54 d, Nr. 253492\nSchlumberger, Jean, Z\u00fcrich: Brettspiel\n08.03.1946\nhttps://suche.staatsarchiv.djiktzh.ch/detail.aspx?Id=1114641\nPAT 2, 54 d, Nr. 246025\nFrei, K. H., Weisslingen: Brettspiel\n26.10.1945\nhttps://suche.staatsarchiv.djiktzh.ch/detail.aspx?Id=1114639\nDS 107.2.37\nUZH Magazin\nDie Wissenschaftszeitschrift\n2019\nhttps://suche.staatsarchiv.djiktzh.ch/detail.aspx?Id=4612939\nG I 1, Nr. 34\nVerordnung der Stadt Z\u00fcrich betreffend die Erf\u00fcllung von Amtspflichten durch die Chorherren des Grossm\u00fcnsterstifts\n24.09.1485\nhttps://suche.staatsarchiv.djiktzh.ch/detail.aspx?Id=3796980\n```\n\nThe return value of `searchretrieve` is iterable, so you can easily loop over it.\nOr you can use indices to access records, e.g. `records[1]` to get the second record, or `records[-1]` to get the last one.\n\nEven [slicing](https://python-reference.readthedocs.io/en/latest/docs/brackets/slicing.html) is supported, so you can do things like only iterate over the first 5 elements using\n\n```python\nfor records in records[:5]:\n   print(record)\n```\n\n### `explain` operation\n\nThe `explain` operation returns a dict-like object.\nThe values can either be accessed as keys `info['sru_version']` or as attributes `info.sru_version`.\n\n```python\n>>> import sruthi\n>>> info = sruthi.explain('https://suche.staatsarchiv.djiktzh.ch/SRU/')\n>>> info\n{'sru_version': '1.2', 'server': {'host': 'https://suche.staatsarchiv.djiktzh.ch/Sru', 'port': 80, 'database': 'sru'}, 'database': {'title': 'Staatsarchiv Z\u00fcrich Online Search', 'description': 'Durchsuchen der Best\u00e4nde des Staatsarchiv Z\u00fcrichs.', 'contact': 'staatsarchivzh@ji.zh.ch'}, 'index': {'isad': {'title': 'Title', 'reference': 'Reference Code', 'date': 'Date', 'descriptionlevel': 'Level'}}, 'schema': {'isad': {'identifier': 'http://www.expertisecentrumdavid.be/xmlschemas/isad.xsd', 'name': 'isad', 'title': 'ISAD(G)'}}, 'config': {'maximumRecords': 99, 'defaults': {'numberOfRecords': 99}}}\n>>> info.server\n{'host': 'https://suche.staatsarchiv.djiktzh.ch/Sru', 'port': 80, 'database': 'sru'}\n>>> info.database\n{'title': 'Staatsarchiv Z\u00fcrich Online Search', 'description': 'Durchsuchen der Best\u00e4nde des Staatsarchiv Z\u00fcrichs.', 'contact': 'staatsarchivzh@ji.zh.ch'}\n>>> info['index']\n{'isad': {'title': 'Title', 'reference': 'Reference Code', 'date': 'Date', 'descriptionlevel': 'Level'}}\n>>> info['schema']\n{'isad': {'identifier': 'http://www.expertisecentrumdavid.be/xmlschemas/isad.xsd', 'name': 'isad', 'title': 'ISAD(G)'}}\n```\n\n### Request for SRU 1.1\n\nBy default sruthi uses SRU 1.2 to make requests, but you can specify the SRU version for each call or when you create a new client instance:\n\n```python\n>>> import sruthi\n>>> # create a client\n>>> client = sruthi.Client(\n...     'https://services.dnb.de/sru/dnb',\n...     record_schema='oai_dc',\n...     sru_version='1.1'\n>>> )\n>>> records = client.searchretrieve(query=\"Zurich\")\n>>> records.count\n8985\n>>> # ...or pass the version directly to the call\n>>> records = sruthi.searchretrieve(\n...     'https://services.dnb.de/sru/dnb',\n...     query=\"Zurich\",\n...     record_schema='oai_dc',\n...     sru_version='1.1'\n>>> )\n>>> records.count\n8985\n```\n\n### Custom parameters and settings\n\nIf an SRU endpoint needs additional (custom) parameters, you can create your own session object and pass it to the client.\nThis is useful for adding authentication (username, password), custom headers or parameters, SSL verification settings etc.\n\n```python\n>>> import sruthi\n>>> import requests\n>>> # customize session\n>>> session = requests.Session()\n>>> session.params = {\"x-collection\": \"GGC\"}\n>>> # pass the customized session to sruthi\n>>> records = sruthi.searchretrieve(\"https://jsru.kb.nl/sru\", query=\"gruninger\", session=session)\n>>> records.count\n4\n```\n\n## Schemas\n\nsruthi does not make any assumptions about the record data schema.\nThe data is provided as-is (as a flattend dict).\nsruthi has been tested with the following schemas:\n\n* [Dublin Core Record Schema](http://www.loc.gov/standards/sru/recordSchemas/dc-schema.html) (dc)\n* [MARCXML: The MARC 21 XML Schema](http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd) (marcxml)\n* [ISAD(G): General International Standard Archival Description, Second edition](http://www.expertisecentrumdavid.be/xmlschemas/isad.xsd) (isad)\n\n## Development\n\nTo contribute to sruthi simply clone this repository and follow the instructions in [CONTRIBUTING.md](/CONTRIBUTING.md).\n\nThis project has a `Makefile` with the most common commands.\nType `make help` to get an overview.\n\n## Release\n\nTo create a new release, follow these steps (please respect [Semantic Versioning](http://semver.org/)):\n\n1. Adapt the version number in `sruthi/__init__.py`\n1. Update the CHANGELOG with the version\n1. Create a pull request to merge `develop` into `master` (make sure the tests pass!)\n1. Create a [new release/tag on GitHub](https://github.com/metaodi/sruthi/releases) (on the master branch)\n1. The [publication on PyPI](https://pypi.python.org/pypi/sruthi) happens via [GitHub Actions](https://github.com/metaodi/sruthi/actions?query=workflow%3A%22Upload+Python+Package%22) on every tagged commit\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "SRU client for Python",
    "version": "2.0.0",
    "project_urls": {
        "Download": "https://github.com/metaodi/sruthi/archive/v2.0.0.zip",
        "Homepage": "https://github.com/metaodi/sruthi"
    },
    "split_keywords": [
        "sru",
        "search",
        "retrieve",
        "archive",
        "library"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b3b525a403ad11f8c132e7c2042db62e576d9b8fbe8641a77259a2654e1fae65",
                "md5": "449d24f27bb104df77f00ce36db628c9",
                "sha256": "262b8b8a5a7f607ce31aa758e05ffd670f58c15855493d2528fcf8f77b32a05f"
            },
            "downloads": -1,
            "filename": "sruthi-2.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "449d24f27bb104df77f00ce36db628c9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 10753,
            "upload_time": "2023-07-05T23:27:50",
            "upload_time_iso_8601": "2023-07-05T23:27:50.474406Z",
            "url": "https://files.pythonhosted.org/packages/b3/b5/25a403ad11f8c132e7c2042db62e576d9b8fbe8641a77259a2654e1fae65/sruthi-2.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "662596324a7413692ab1aa4cb1648af6a4fa1ae4d2db406a25cd04830d6cb6f0",
                "md5": "fd154b0dc5259ad375943aae7e16c7ae",
                "sha256": "415639dc06e074041e35107940d89dad10534e327d1366fb17d3f4e3dda45906"
            },
            "downloads": -1,
            "filename": "sruthi-2.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "fd154b0dc5259ad375943aae7e16c7ae",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 13132,
            "upload_time": "2023-07-05T23:27:52",
            "upload_time_iso_8601": "2023-07-05T23:27:52.019362Z",
            "url": "https://files.pythonhosted.org/packages/66/25/96324a7413692ab1aa4cb1648af6a4fa1ae4d2db406a25cd04830d6cb6f0/sruthi-2.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-05 23:27:52",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "metaodi",
    "github_project": "sruthi",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "sruthi"
}
        
Elapsed time: 0.41616s