Skip to content

sxolar.api.arxiv

Arxiv API wrappers for sxolar, low-level functions for querying the Arxiv API. For more user-friendly functions, see the sxolar.api.query module.

References

[1] API Basics: https://info.arxiv.org/help/api/basics.html [2] Rate Limits: https://info.arxiv.org/help/api/tou.html [3] Search Query Language: https://info.arxiv.org/help/api/user-manual.html #query_details [4] Entry output format: https://info.arxiv.org/help/api/user-manual.html #_entry_metadata [5] ArXiv identifier format: https://info.arxiv.org/help/arxiv_identifier.html

Author dataclass

A dataclass for an author of an Arxiv entry.

Parameters:

Name Type Description Default
name str

str, the name of the author.

required
affiliation str

str, the affiliation of the author.

required
Source code in sxolar/api/arxiv.py
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
@dataclass
class Author:
    """A dataclass for an author of an Arxiv entry.

    Args:
        name:
            str, the name of the author.
        affiliation:
            str, the affiliation of the author.
    """

    name: str
    affiliation: str

    def __str__(self) -> str:
        """Return the author as a string."""
        return self.name

__str__()

Return the author as a string.

Source code in sxolar/api/arxiv.py
113
114
115
def __str__(self) -> str:
    """Return the author as a string."""
    return self.name

Entry dataclass

A dataclass for an entry from the Arxiv API [4]

Parameters:

Name Type Description Default
title str

str, the title of the entry

required
id Identifier

str, the Arxiv ID of the entry

required
published datetime

datetime.datetime, the published date of the entry

required
updated datetime

datetime.datetime, the updated date of the entry

required
summary str

str, the summary of the entry

required
author List[Author]

List[Author], the authors of the entry

required
category List[Category]

List[Category], the categories of the entry

required
Source code in sxolar/api/arxiv.py
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
@dataclass
class Entry:
    """A dataclass for an entry from the Arxiv API [4]

    Args:
        title:
            str, the title of the entry
        id:
            str, the Arxiv ID of the entry
        published:
            datetime.datetime, the published date of the entry
        updated:
            datetime.datetime, the updated date of the entry
        summary:
            str, the summary of the entry
        author:
            List[Author], the authors of the entry
        category:
            List[Category], the categories of the entry
    """

    title: str
    id: Identifier
    published: datetime.datetime
    updated: datetime.datetime
    summary: str
    author: List[Author]
    category: List[Category]

    def link(self) -> str:
        """Formatted arxiv link for the entry"""
        return f"https://arxiv.org/abs/{self.id}"

    def to_dict(self) -> dict:
        """Return the entry as a dictionary."""
        return {
            FIELD_ENTRY_TITLE: self.title,
            FIELD_ENTRY_ID: self.id,
            FIELD_ENTRY_PUBLISHED: self.published,
            FIELD_ENTRY_UPDATED: self.updated,
            FIELD_ENTRY_SUMMARY: self.summary,
            FIELD_ENTRY_AUTHOR: self.author,
            FIELD_ENTRY_CATEGORY: self.category,
        }

    @staticmethod
    def from_dict(data: dict) -> "Entry":
        """Create an entry from a dictionary."""
        return Entry(
            title=data[FIELD_ENTRY_TITLE],
            id=data[FIELD_ENTRY_ID],
            published=data[FIELD_ENTRY_PUBLISHED],
            updated=data[FIELD_ENTRY_UPDATED],
            summary=data[FIELD_ENTRY_SUMMARY],
            author=data[FIELD_ENTRY_AUTHOR],
            category=data[FIELD_ENTRY_CATEGORY],
        )

    def filter_authors(self, authors: List[str]) -> bool:
        """Check if the entry has any of the given authors.

        Args:
            authors:
                List[str], the list of authors to check for.

        Returns:
            bool: True if the entry has any of the authors, False otherwise.
        """
        lower_authors = [author.lower().strip() for author in authors]
        return any(author.name.lower().strip() in lower_authors for author in self.author)

filter_authors(authors)

Check if the entry has any of the given authors.

Parameters:

Name Type Description Default
authors List[str]

List[str], the list of authors to check for.

required

Returns:

Name Type Description
bool bool

True if the entry has any of the authors, False otherwise.

Source code in sxolar/api/arxiv.py
237
238
239
240
241
242
243
244
245
246
247
248
def filter_authors(self, authors: List[str]) -> bool:
    """Check if the entry has any of the given authors.

    Args:
        authors:
            List[str], the list of authors to check for.

    Returns:
        bool: True if the entry has any of the authors, False otherwise.
    """
    lower_authors = [author.lower().strip() for author in authors]
    return any(author.name.lower().strip() in lower_authors for author in self.author)

from_dict(data) staticmethod

Create an entry from a dictionary.

Source code in sxolar/api/arxiv.py
224
225
226
227
228
229
230
231
232
233
234
235
@staticmethod
def from_dict(data: dict) -> "Entry":
    """Create an entry from a dictionary."""
    return Entry(
        title=data[FIELD_ENTRY_TITLE],
        id=data[FIELD_ENTRY_ID],
        published=data[FIELD_ENTRY_PUBLISHED],
        updated=data[FIELD_ENTRY_UPDATED],
        summary=data[FIELD_ENTRY_SUMMARY],
        author=data[FIELD_ENTRY_AUTHOR],
        category=data[FIELD_ENTRY_CATEGORY],
    )

Formatted arxiv link for the entry

Source code in sxolar/api/arxiv.py
208
209
210
def link(self) -> str:
    """Formatted arxiv link for the entry"""
    return f"https://arxiv.org/abs/{self.id}"

to_dict()

Return the entry as a dictionary.

Source code in sxolar/api/arxiv.py
212
213
214
215
216
217
218
219
220
221
222
def to_dict(self) -> dict:
    """Return the entry as a dictionary."""
    return {
        FIELD_ENTRY_TITLE: self.title,
        FIELD_ENTRY_ID: self.id,
        FIELD_ENTRY_PUBLISHED: self.published,
        FIELD_ENTRY_UPDATED: self.updated,
        FIELD_ENTRY_SUMMARY: self.summary,
        FIELD_ENTRY_AUTHOR: self.author,
        FIELD_ENTRY_CATEGORY: self.category,
    }

Identifier dataclass

A dataclass for an Arxiv identifier.

Parameters:

Name Type Description Default
number str

str, the number of the identifier.

required
version str

str, the version of the identifier.

required
is_new bool

bool, whether the identifier is in the new format.

required
Source code in sxolar/api/arxiv.py
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
@dataclass
class Identifier:
    """A dataclass for an Arxiv identifier.

    Args:
        number:
            str, the number of the identifier.
        version:
            str, the version of the identifier.
        is_new:
            bool, whether the identifier is in the new format.
    """

    number: str
    version: str
    is_new: bool

    def __str__(self) -> str:
        """Return the identifier as a string."""
        if self.is_new:
            return f"{self.number}v{self.version}" if self.version else self.number
        return self.number

    def link(self) -> str:
        """Formatted arxiv link for the identifier"""
        return f"{ID_PREFIX}{self}"

__str__()

Return the identifier as a string.

Source code in sxolar/api/arxiv.py
135
136
137
138
139
def __str__(self) -> str:
    """Return the identifier as a string."""
    if self.is_new:
        return f"{self.number}v{self.version}" if self.version else self.number
    return self.number

Formatted arxiv link for the identifier

Source code in sxolar/api/arxiv.py
141
142
143
def link(self) -> str:
    """Formatted arxiv link for the identifier"""
    return f"{ID_PREFIX}{self}"

LogicalOperator

Enumeration of logical operators for the Arxiv API [3]

Source code in sxolar/api/arxiv.py
280
281
282
283
284
285
class LogicalOperator:
    """Enumeration of logical operators for the Arxiv API [3]"""

    AND = " AND "
    OR = " OR "
    AND_NOT = " ANDNOT "

SearchField

Enumeration of search fields for the Arxiv API [3]

Source code in sxolar/api/arxiv.py
266
267
268
269
270
271
272
273
274
275
276
277
class SearchField:
    """Enumeration of search fields for the Arxiv API [3]"""

    TITLE = "ti"
    AUTHOR = "au"
    ABSTRACT = "abs"
    COMMENT = "co"
    JOURNAL_REFERENCE = "jr"
    CATEGORY = "cat"
    REPORT_NUMBER = "rn"
    ID = "id"
    ALL = "all"

SortBy

Bases: str, Enum

Enumeration of sort fields for the Arxiv API [3]

Source code in sxolar/api/arxiv.py
251
252
253
254
255
256
class SortBy(str, enum.Enum):
    """Enumeration of sort fields for the Arxiv API [3]"""

    Relevance = "relevance"
    LastUpdatedDate = "lastUpdatedDate"
    SubmittedDate = "submittedDate"

SortOrder

Bases: str, Enum

Enumeration of sort orders for the Arxiv API [3]

Source code in sxolar/api/arxiv.py
259
260
261
262
263
class SortOrder(str, enum.Enum):
    """Enumeration of sort orders for the Arxiv API [3]"""

    Ascending = "ascending"
    Descending = "descending"

execute(search_query=None, id_list=None, start=0, max_results=10, sort_by=SortBy.Relevance, sort_order=SortOrder.Descending, min_date=None, max_date=None, date_filter_field=FIELD_ENTRY_UPDATED)

Query the Arxiv API with the given parameters.

Parameters:

Name Type Description Default
search_query str

str, optional, The query string to search for. Defaults to None.

None
id_list List[str]

List[str], optional, A list of Arxiv IDs to search for. Defaults to None.

None
start int

int, optional, The index to start the search from. Defaults to 0.

0
max_results int

int, optional, The maximum number of results to return. Defaults to 10.

10
sort_by SortBy

SortBy, optional, The field to sort by. Defaults to SortBy.Relevance.

Relevance
sort_order SortOrder

SortOrder, optional, The order to sort by. Defaults to SortOrder.Descending.

Descending

Returns:

Type Description
List[Entry]

List[Entry]: The list of entries returned by the query.

Source code in sxolar/api/arxiv.py
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
def execute(
    search_query: str = None,
    id_list: List[str] = None,
    start: int = 0,
    max_results: int = 10,
    sort_by: SortBy = SortBy.Relevance,
    sort_order: SortOrder = SortOrder.Descending,
    min_date: datetime.datetime = None,
    max_date: datetime.datetime = None,
    date_filter_field: str = FIELD_ENTRY_UPDATED,

) -> List[Entry]:
    """Query the Arxiv API with the given parameters.

    Args:
        search_query:
            str, optional, The query string to search for. Defaults to None.
        id_list:
            List[str], optional, A list of Arxiv IDs to search for. Defaults to None.
        start:
            int, optional, The index to start the search from. Defaults to 0.
        max_results:
            int, optional, The maximum number of results to return. Defaults to 10.
        sort_by:
            SortBy, optional, The field to sort by. Defaults to SortBy.Relevance.
        sort_order:
            SortOrder, optional, The order to sort by. Defaults to SortOrder.Descending.

    Returns:
        List[Entry]: The list of entries returned by the query.
    """
    # Define the parameters for the query
    params = {
        "search_query": search_query,
        "id_list": id_list,
        "start": start,
        "max_results": max_results,
        "sortBy": sort_by.value,
        "sortOrder": sort_order.value,
    }

    # Filter out the None values
    params = {k: v for k, v in params.items() if v is not None}

    # Get and parse the response
    results = get_and_parse(URL_QUERY, params)

    # Filter for dates if specified
    if date_filter_field not in (FIELD_ENTRY_PUBLISHED, FIELD_ENTRY_UPDATED):
        raise ValueError(
            f"Invalid date filter field: {date_filter_field}, options "
            f"are {FIELD_ENTRY_PUBLISHED} or {FIELD_ENTRY_UPDATED}"
        )
    if min_date is not None:
        results = [r for r in results if getattr(r, date_filter_field) >= min_date]
    if max_date is not None:
        results = [r for r in results if getattr(r, date_filter_field) <= max_date]

    # Return the results
    return results

find(entry, tag, find_all=False)

Find the tag in the entry and return the text.

Parameters:

Name Type Description Default
entry Element

The entry to search.

required
tag str

The tag to search for.

required

Returns:

Name Type Description
str Union[str, List[str]]

The text of the tag.

Source code in sxolar/api/arxiv.py
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
def find(
    entry: ElementTree.Element, tag: str, find_all: bool = False
) -> Union[str, List[str]]:
    """Find the tag in the entry and return the text.

    Args:
        entry (ElementTree.Element): The entry to search.
        tag (str): The tag to search for.

    Returns:
        str: The text of the tag.
    """
    if not tag.startswith(TAG_PREFIX):
        tag = TAG_PREFIX + tag

    if find_all:
        return entry.findall(tag)

    res = entry.find(tag)
    if res is not None:
        return res.text

format_search_query(title=None, author=None, abstract=None, comment=None, journal_reference=None, category=None, report_number=None, id_list=None, all_=None, how=LogicalOperator.AND, how_list=LogicalOperator.OR)

Format the search query for the Arxiv API.

Parameters:

Name Type Description Default
title Union[str, List[str]]

Union[str, List[str]], optional, The title to search for. Defaults to None.

None
author Union[str, List[str]]

Union[str, List[str]], optional, The author to search for. Defaults to None.

None
abstract Union[str, List[str]]

Union[str, List[str]], optional, The abstract to search for. Defaults to None.

None
comment Union[str, List[str]]

Union[str, List[str]], optional, The comment to search for. Defaults to None.

None
journal_reference Union[str, List[str]]

Union[str, List[str]], optional, The journal reference to search for. Defaults to None.

None
category Union[str, List[str]]

Union[str, List[str]], optional, The category to search for. Defaults to None.

None
report_number Union[str, List[str]]

Union[str, List[str]], optional, The report number to search for. Defaults to None.

None
id_list List[str]

List[str], optional, The list of Arxiv IDs to search for. Defaults to None.

None
all_ Union[str, List[str]]

Union[str, List[str]], optional, The all field to search for. Defaults to None.

None
how LogicalOperator

LogicalOperator, optional, The logical operator to use when adding the field. Defaults to LogicalOperator.AND.

AND
how_list LogicalOperator

LogicalOperator, optional, The logical operator to use when adding a list of values. Defaults to LogicalOperator.OR.

OR

Returns:

Type Description
Union[str, None]

str or None: The formatted query string, or None if no fields are provided.

Source code in sxolar/api/arxiv.py
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
def format_search_query(
    title: Union[str, List[str]] = None,
    author: Union[str, List[str]] = None,
    abstract: Union[str, List[str]] = None,
    comment: Union[str, List[str]] = None,
    journal_reference: Union[str, List[str]] = None,
    category: Union[str, List[str]] = None,
    report_number: Union[str, List[str]] = None,
    id_list: List[str] = None,
    all_: Union[str, List[str]] = None,
    how: LogicalOperator = LogicalOperator.AND,
    how_list: LogicalOperator = LogicalOperator.OR,
) -> Union[str, None]:
    """Format the search query for the Arxiv API.

    Args:
        title:
            Union[str, List[str]], optional, The title to search for. Defaults to None.
        author:
            Union[str, List[str]], optional, The author to search for. Defaults to None.
        abstract:
            Union[str, List[str]], optional, The abstract to search for. Defaults to
            None.
        comment:
            Union[str, List[str]], optional, The comment to search for. Defaults to
            None.
        journal_reference:
            Union[str, List[str]], optional, The journal reference to search for.
            Defaults to None.
        category:
            Union[str, List[str]], optional, The category to search for. Defaults to
            None.
        report_number:
            Union[str, List[str]], optional, The report number to search for.
            Defaults to None.
        id_list:
            List[str], optional, The list of Arxiv IDs to search for. Defaults to None.
        all_:
            Union[str, List[str]], optional, The all field to search for. Defaults to
            None.
        how:
            LogicalOperator, optional, The logical operator to use when adding the
            field. Defaults to LogicalOperator.AND.
        how_list:
            LogicalOperator, optional, The logical operator to use when adding a list
            of values. Defaults to LogicalOperator.OR.

    Returns:
        str or None: The formatted query string, or None if no fields are provided.
    """
    # Short-circuit if no fields are provided
    if all(
        v is None
        for v in (
            title,
            author,
            abstract,
            comment,
            journal_reference,
            category,
            report_number,
            id_list,
            all_,
        )
    ):
        return None

    query = ""

    for field, value in zip(
        (
            SearchField.TITLE,
            SearchField.AUTHOR,
            SearchField.ABSTRACT,
            SearchField.COMMENT,
            SearchField.JOURNAL_REFERENCE,
            SearchField.CATEGORY,
            SearchField.REPORT_NUMBER,
            SearchField.ID,
            SearchField.ALL,
        ),
        (
            title,
            author,
            abstract,
            comment,
            journal_reference,
            category,
            report_number,
            id_list,
            all_,
        ),
    ):
        if value is not None:
            query = _extend_query(query, field, value, how=how, how_list=how_list)

    return parse.quote(query, safe="/:&=")

get_and_parse(url, params)

Get and parse the response from the Arxiv API, the payloads are encoded using the Atom 1 XML format.

Parameters:

Name Type Description Default
url str

The endpoint to query

required
params dict

The parameters to pass to the query

required

Returns:

Name Type Description
dict List[Entry]

The parsed response

Source code in sxolar/api/arxiv.py
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
def get_and_parse(url: str, params: dict) -> List[Entry]:
    """Get and parse the response from the Arxiv API, the payloads
    are encoded using the Atom 1 XML format.

    Args:
        url (str): The endpoint to query
        params (dict): The parameters to pass to the query

    Returns:
        dict: The parsed response
    """
    # Get the response
    response = SESSION.get(url, params=params)

    # Check for failures
    if not response.ok:
        response.raise_for_status()

    # Parse the response securely into ElementTree
    root = SecureElementTree.fromstring(response.text)

    # TODO finish parsing response into a list of named tuples if no errors,
    #  otherwise raise the error
    if len(root) == 1 and root[0].tag == "error":
        raise ValueError(f"No results found. Error: {root[0].text}")

    entries = [parse_entry(entry) for entry in find(root, TAG_ENTRY, find_all=True)]

    # Return the parsed response
    return entries

parse_entry(entry)

Parse an entry from the Arxiv API response.

Parameters:

Name Type Description Default
entry Element

The entry to parse.

required

Returns:

Name Type Description
Entry Entry

The parsed entry.

Source code in sxolar/api/arxiv.py
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
def parse_entry(entry: ElementTree.Element) -> Entry:
    """Parse an entry from the Arxiv API response.

    Args:
        entry (ElementTree.Element): The entry to parse.

    Returns:
        Entry: The parsed entry.
    """
    # Parse the authors
    authors = [
        Author(name=find(author, TAG_NAME), affiliation=find(author, TAG_AFFILIATION))
        for author in find(entry, TAG_AUTHOR, find_all=True)
    ]

    # Parse the categories
    categories = [
        Category(term=category.attrib[TAG_TERM], scheme=category.attrib[TAG_SCHEME])
        for category in find(entry, TAG_CATEGORY, find_all=True)
    ]

    # Parse date-type fields
    published = find(entry, TAG_PUBLISHED)
    updated = find(entry, TAG_UPDATED)
    if published is not None:
        published = datetime.datetime.fromisoformat(published)
    if updated is not None:
        updated = datetime.datetime.fromisoformat(updated)

    # Parse components of the identifier
    raw_id = find(entry, TAG_ID)
    id_ = parse_identifier(raw_id)

    # Return the parsed entry
    return Entry(
        title=find(entry, TAG_TITLE),
        id=id_,
        published=published,
        updated=updated,
        summary=find(entry, TAG_SUMMARY),
        author=authors,
        category=categories,
    )

parse_identifier(id_text)

Parse an Arxiv identifier into its components.

Parameters:

Name Type Description Default
id_text str

str, the Arxiv identifier to parse.

required
Source code in sxolar/api/arxiv.py
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
def parse_identifier(id_text: str) -> Identifier:
    """Parse an Arxiv identifier into its components.

    Args:
        id_text:
            str, the Arxiv identifier to parse.
    """
    # Check if the identifier starts with the url prefix, if so remove
    if id_text.startswith(ID_PREFIX):
        id_text = id_text[len(ID_PREFIX) :]

    # Check if the identifier is in the new format
    match = re.match(ID_PATTERN_NEW, id_text)
    if match:
        return Identifier(
            number=match.group("number"),
            version=match.group("version"),
            is_new=True,
        )

    # Check if the identifier is in the old format
    match = re.match(ID_PATTERN_OLD, id_text)
    if match:
        return Identifier(
            number=match.group("number"),
            version=None,
            is_new=False,
        )

    # If the identifier does not match either pattern, raise an error
    raise ValueError(f"Invalid Arxiv identifier: {id_text}")

query(title=None, author=None, abstract=None, comment=None, journal_reference=None, category=None, report_number=None, id_list=None, all_=None, how=LogicalOperator.AND, how_list=LogicalOperator.OR, start=0, max_results=10, sort_by=SortBy.Relevance, sort_order=SortOrder.Descending, min_date=None, max_date=None, date_filter_field=FIELD_ENTRY_UPDATED)

Query the Arxiv API with the given parameters.

Parameters:

Name Type Description Default
title Union[str, List[str]]

Union[str, List[str]], optional, The title to search for. Defaults to None.

None
author Union[str, List[str]]

Union[str, List[str]], optional, The author to search for. Defaults to None.

None
abstract Union[str, List[str]]

Union[str, List[str]], optional, The abstract to search for. Defaults to None.

None
comment Union[str, List[str]]

Union[str, List[str]], optional, The comment to search for. Defaults to None.

None
journal_reference Union[str, List[str]]

Union[str, List[str]], optional, The journal reference to search for. Defaults to None.

None
category Union[str, List[str]]

Union[str, List[str]], optional, The category to search for. Defaults to None.

None
report_number Union[str, List[str]]

Union[str, List[str]], optional, The report number to search for. Defaults to None.

None
id_list List[str]

List[str], optional, The list of Arxiv IDs to search for. Defaults to None.

None
all_ Union[str, List[str]]

Union[str, List[str]], optional, The all field to search for. Defaults to None.

None
how LogicalOperator

LogicalOperator, optional, The logical operator to use when adding the field. Defaults to LogicalOperator.AND.

AND
how_list LogicalOperator

LogicalOperator, optional, The logical operator to use when adding a list of values. Defaults to LogicalOperator.OR.

OR
start int

int, optional, The index to start the search from. Defaults to 0.

0
max_results int

int, optional, The maximum number of results to return. Defaults to 10.

10
sort_by SortBy

SortBy, optional, The field to sort by. Defaults to SortBy.Relevance.

Relevance
sort_order SortOrder

SortOrder, optional, The order to sort by. Defaults to SortOrder.Descending.

Descending
Source code in sxolar/api/arxiv.py
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
def query(
    title: Union[str, List[str]] = None,
    author: Union[str, List[str]] = None,
    abstract: Union[str, List[str]] = None,
    comment: Union[str, List[str]] = None,
    journal_reference: Union[str, List[str]] = None,
    category: Union[str, List[str]] = None,
    report_number: Union[str, List[str]] = None,
    id_list: List[str] = None,
    all_: Union[str, List[str]] = None,
    how: LogicalOperator = LogicalOperator.AND,
    how_list: LogicalOperator = LogicalOperator.OR,
    start: int = 0,
    max_results: int = 10,
    sort_by: SortBy = SortBy.Relevance,
    sort_order: SortOrder = SortOrder.Descending,
    min_date: datetime.datetime = None,
    max_date: datetime.datetime = None,
    date_filter_field: str = FIELD_ENTRY_UPDATED,
) -> List[Entry]:
    """Query the Arxiv API with the given parameters.

    Args:
        title:
            Union[str, List[str]], optional, The title to search for. Defaults to None.
        author:
            Union[str, List[str]], optional, The author to search for. Defaults to None.
        abstract:
            Union[str, List[str]], optional, The abstract to search for. Defaults to
            None.
        comment:
            Union[str, List[str]], optional, The comment to search for. Defaults to
            None.
        journal_reference:
            Union[str, List[str]], optional, The journal reference to search for.
            Defaults to None.
        category:
            Union[str, List[str]], optional, The category to search for. Defaults to
            None.
        report_number:
            Union[str, List[str]], optional, The report number to search for.
            Defaults to None.
        id_list:
            List[str], optional, The list of Arxiv IDs to search for. Defaults to None.
        all_:
            Union[str, List[str]], optional, The all field to search for. Defaults to
            None.
        how:
            LogicalOperator, optional, The logical operator to use when adding the
            field. Defaults to LogicalOperator.AND.
        how_list:
            LogicalOperator, optional, The logical operator to use when adding a list
            of values. Defaults to LogicalOperator.OR.
        start:
            int, optional, The index to start the search from. Defaults to 0.
        max_results:
            int, optional, The maximum number of results to return. Defaults to 10.
        sort_by:
            SortBy, optional, The field to sort by. Defaults to SortBy.Relevance.
        sort_order:
            SortOrder, optional, The order to sort by. Defaults to SortOrder.Descending.
    """
    # Format the search query
    search_query = format_search_query(
        title,
        author,
        abstract,
        comment,
        journal_reference,
        category,
        report_number,
        id_list,
        all_,
        how,
        how_list,
    )

    # Short-circuit if no search query is provided
    if search_query is None and id_list is None:
        raise ValueError("No search query provided; cannot query the entire Arxiv.")

    # Query the API
    return execute(
        search_query=search_query,
        id_list=id_list,
        start=start,
        max_results=max_results,
        sort_by=sort_by,
        sort_order=sort_order,
        min_date=min_date,
        max_date=max_date,
        date_filter_field=date_filter_field,
    )