1+ [ ![ PyPI Version] ( https://img.shields.io/pypi/v/sruthi )] ( https://pypi.org/project/sruthi/ )
2+ [ ![ 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 )
3+
14# sruthi
25
36** sru** thi is a client for python to make [ SRU requests (Search/Retrieve via URL)] ( http://www.loc.gov/standards/sru/ ) .
47
5- Currently only SRU 1.2 is supported.
8+ Currently only ** SRU 1.1 and 1.2 ** is supported.
69
710## Table of Contents
811
912* [ Installation] ( #installation )
1013* [ Usage] ( #usage )
1114 * [ ` searchretrieve ` operation] ( #searchretrieve-operation )
1215 * [ ` explain ` operation] ( #explain-operation )
16+ * [ Request for SRU 1.1] ( #request-for-sru-11 )
1317* [ Schemas] ( #schemas )
18+ * [ Development] ( #development )
1419* [ Release] ( #release )
1520
1621## Installation
@@ -28,30 +33,38 @@ See the [`examples` directory](https://github.com/metaodi/sruthi/tree/master/exa
2833### ` searchretrieve ` operation
2934
3035``` python
31- import sruthi
32-
33- records = sruthi.searchretrieve(' https://suche.staatsarchiv.djiktzh.ch/SRU/' , query = ' Zurich' )
34-
35- for record in records:
36- # print fields from schema
37- print (record[' reference' ])
38- print (record[' title' ])
39- print (record[' date' ])
40- print (record[' extra' ][' link' ]) # extra record data is available at the 'extra' key
41- ```
42-
43- ``` python
44- # you can get more information at each step
45- import sruthi
46-
47- # note: records is an iterator
48- records = sruthi.searchretrieve(' https://suche.staatsarchiv.djiktzh.ch/SRU/' , query = ' Human' )
49- print (records.sru_version)
50- print (records.count)
51-
52- for record in records:
53- print (record)
54- print (record[' schema' ])
36+ >> > import sruthi
37+ >> > records = sruthi.searchretrieve(' https://suche.staatsarchiv.djiktzh.ch/SRU/' , query = ' Brettspiel' )
38+ >> > print (records)
39+ SearchRetrieveResponse(sru_version = ' 1.2' ,count = 500 ,next_start_record = 11 )
40+ >> > print (records.count)
41+ 4
42+ >> > print (record[0 ])
43+ {' 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' }}
44+ >> >
45+ >> > for record in records:
46+ ... # print fields from schema
47+ ... print (record[' reference' ])
48+ ... print (record[' title' ])
49+ ... print (record[' date' ])
50+ ... print (record[' extra' ][' link' ]) # extra record data is available at the 'extra' key
51+ PAT 2 , 54 d, Nr. 253492
52+ Schlumberger, Jean, Zürich: Brettspiel
53+ 08.03 .1946
54+ https:// suche.staatsarchiv.djiktzh.ch/ detail.aspx? Id= 1114641
55+ PAT 2 , 54 d, Nr. 246025
56+ Frei, K. H., Weisslingen: Brettspiel
57+ 26.10 .1945
58+ https:// suche.staatsarchiv.djiktzh.ch/ detail.aspx? Id= 1114639
59+ DS 107.2 .37
60+ UZH Magazin
61+ Die Wissenschaftszeitschrift
62+ 2019
63+ https:// suche.staatsarchiv.djiktzh.ch/ detail.aspx? Id= 4612939
64+ G I 1 , Nr. 34
65+ Verordnung der Stadt Zürich betreffend die Erfüllung von Amtspflichten durch die Chorherren des Grossmünsterstifts
66+ 24.09 .1485
67+ https:// suche.staatsarchiv.djiktzh.ch/ detail.aspx? Id= 3796980
5568```
5669
5770The return value of ` searchretrieve ` is iterable, so you can easily loop over it. Or you can use indices to access elements, e.g. ` records[1] ` to get the second elemenet, or ` records[-1] ` to get the last one.
@@ -65,14 +78,48 @@ for records in records[:5]:
6578
6679### ` explain ` operation
6780
81+ The ` explain ` operation returns a dict-like object.
82+ The values can either be accessed as keys ` info['sru_version'] ` or as attributes ` info.sru_version ` .
83+
6884``` python
69- import sruthi
85+ >> > import sruthi
86+ >> > info = sruthi.explain(' https://suche.staatsarchiv.djiktzh.ch/SRU/' )
87+ >> > info
88+ {' 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 }}}
89+ >> > info.server
90+ {' host' : ' https://suche.staatsarchiv.djiktzh.ch/Sru' , ' port' : 80 , ' database' : ' sru' }
91+ >> > info.database
92+ {' title' : ' Staatsarchiv Zürich Online Search' , ' description' : ' Durchsuchen der Bestände des Staatsarchiv Zürichs.' , ' contact' : ' staatsarchivzh@ji.zh.ch' }
93+ >> > info[' index' ]
94+ {' isad' : {' title' : ' Title' , ' reference' : ' Reference Code' , ' date' : ' Date' , ' descriptionlevel' : ' Level' }}
95+ >> > info[' schema' ]
96+ {' isad' : {' identifier' : ' http://www.expertisecentrumdavid.be/xmlschemas/isad.xsd' , ' name' : ' isad' , ' title' : ' ISAD(G)' }}
97+ ```
98+
99+ ### Request for SRU 1.1
100+
101+ 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:
70102
71- info = sruthi.explain(' https://suche.staatsarchiv.djiktzh.ch/SRU/' )
72- print (info.server)
73- print (info.database)
74- print (info.index)
75- print (info.schema)
103+ ``` python
104+ >> > import sruthi
105+ >> > # create a client
106+ >> > client = sruthi.Client(
107+ ... ' https://services.dnb.de/sru/dnb' ,
108+ ... record_schema = ' oai_dc' ,
109+ ... sru_version = ' 1.1'
110+ >> > )
111+ >> > records = client.searchretrieve(query = " Zurich" )
112+ >> > records.count
113+ 8985
114+ >> > # ...or pass the version directly to the call
115+ >> > records = sruthi.searchretrieve(
116+ ... ' https://services.dnb.de/sru/dnb' ,
117+ ... query = " Zurich" ,
118+ ... record_schema = ' oai_dc' ,
119+ ... sru_version = ' 1.1'
120+ >> > )
121+ >> > records.count
122+ 8985
76123```
77124
78125## Schemas
@@ -85,6 +132,13 @@ sruthi has been tested with the following schemas:
85132* [ MARCXML: The MARC 21 XML Schema] ( http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd ) (marcxml)
86133* [ ISAD(G): General International Standard Archival Description, Second edition] ( http://www.expertisecentrumdavid.be/xmlschemas/isad.xsd ) (isad)
87134
135+ ## Development
136+
137+ To contribute to sruthi simply clone this repository and follow the instructions in [ CONTRIBUTING.md] ( /CONTRIBUTING.md ) .
138+
139+ This project ha a Makefile with the most common commands.
140+ Type ` make help ` to get an overview.
141+
88142## Release
89143
90144To create a new release, follow these steps (please respect [ Semantic Versioning] ( http://semver.org/ ) ):
0 commit comments