$ show pybliometrics-dev/pybliometrics
Pybliometrics is a Python library that provides programmatic access to Elsevier's bibliographic databases (Scopus, ScienceDirect, and SciVal). It acts as a wrapper around the respective APIs, handling authentication, request throttling, caching, and response parsing. The library is designed for researchers and developers who need to extract bibliometric data for analysis, literature reviews, or academic workflows. The architecture follows a modular design with separate subpackages for each service (Scopus, ScienceDirect, SciVal) and a set of superclasses that encapsulate common functionality such as caching and HTTP request handling. Utility modules provide cross-cutting concerns like configuration management, parameter validation, and safe data extraction from JSON responses. This separation of concerns allows for maintainability and extension. Key features include automatic caching of API responses to reduce redundant requests, support for multiple API views (e.g., FULL, STANDARD) to control the level of detail returned, and the conversion of raw JSON data into structured Python objects (like namedtuples) for ease of use. The library also implements rate limiting and error handling specific to the Elsevier APIs.
The LLM identified 3 files worth highlighting for reuse:
The `Base` class provides a robust caching mechanism that checks for existing cached data, validates its freshness, and stores new API responses. It is inherited by both `Retrieval` and `Search` classes, making it a reusable pattern for any API client that benefits from file-based JSON caching. The implementation includes cache directory organization per API endpoint and automatic cache file management.
The `chained_get` function allows safe traversal of nested dictionaries using a key path, returning a default value if any key is missing. This eliminates the need for repetitive try-except blocks or nested conditionals when parsing JSON responses, promoting cleaner and more readable code across the library. It is a self-contained utility with no external dependencies beyond the standard library.
This module contains validation functions (e.g., `check_parameter_value`) that ensure parameters conform to expected values (like specific string literals or numeric ranges). Used throughout the library to validate inputs to API calls, it centralizes validation logic and provides clear error messages. The functions are lightweight, easy to test, and can be reused in other projects requiring similar input validation.