The purpose of the zbMATH Links API is to show the interconnections between zbMATH (the target
of the API) and external platforms (called here partners
and constituting the source
of the API) which store links linking to objects in the target, i.e., documents indexed at zbMATH.
The prototypical partner is the Digital Library of Mathematical Functions (DLMF), which contains more than 6.000 links linking to publications indexed at zbMATH.
Other partners can be integrated as well.
Dummy database. To run the zbMATH Links API with a dummy database (only for illustrative purposes) please follow these steps:
-
Install the requirements and set the environment variables. On a first install:
python3 -m venv env source env/bin/activate pip install -e .
This will install the package,
zbmath-links-api
in the virtual environment, and set the environment variable for flask to discover the application. -
Create the database. Define and export an environment variable
SQLALCHEMY_DATABASE_URI
to set the database connection URI, e.g.,export SQLALCHEMY_DATABASE_URI="postgresql:///my_database"
. Define and export the environment variableFLASK_APP="zb_links.db.init_tables.init_db_app.py"
. With initialization a migration folder will be automatically created.flask db init flask schema_add flask db migrate flask db upgrade flask extra_tables_add flask view_add
-
Populate the (dummy) database. The following command adds just a single illustrative entry in all tables as a starting example dataset.
flask seed_all
-
Run the zbMATH Links API:
export FLASK_APP=zb_links.app flask run
-
View the API at http://127.0.0.1:5000/links_api/
Remark. See settings for configuring writing access. One can use dotenv to store your settings.
DLMF database. To run the zbMATH Links API with DLMF data an auxiliary package is needed, update-zblinks-api
(available here), to be installed separately.
This will allow the user to populate the database with real data coming from DLMF and execute an update when needed.
Please follow these steps (only the third step is different from above):
-
As above.
-
As above.
-
To populate the database, please install the separate package
update-zblinks-api
and follow the instructions for that package. -
As above.
-
As above.
Remark. See settings for configuring writing access. One can use dotenv to store your settings.
Remark. For a proper operation of the API with real DLMF data at least one table (more precisely, a subset of it) of the real database of zbMATH is needed, i.e., math_documents
.
Indeed, the needed table must contain at least those documents indexed at zbMATH that are referenced in the links obtained by the update-zblinks-api
package. For the same reason, a view of the zbMATH table math_authors_ids
is needed.
a) In what follows links are objects belonging to the source
(within a given partner) and zbMATH objects are objects belonging to the target
zbMATH.
b) The zbMATH Links API offers 12 endpoints.
-
GET /link. It retrieves links for given zbMATH objects.
-
DELETE /link/item. It deletes a link from the database.
-
POST /link/item. It creates a new link related to a zbMATH object.
-
GET /link/item. It checks relations between a given link and a given zbMATH object.
-
PATCH /link/item. It edits and existing link.
-
GET /link/item/{doc_id}. It retrieves links for a given zbMATH object.
-
GET /partner. It retrieves data of a given zbMATH partner.
-
PUT /partner. It edits data of a given zbMATH partner.
-
POST /partner. It creates a new partner related to zbMATH.
-
GET /source. It produces a list of all links of a given zbMATH partner.
-
GET /statistics/msc. It shows the occurrence of primary MSC codes (2-digit level) of zbMATH objects in the set of links of a given partner.
-
GET /statistics/year. It shows the occurrence of years of publication of zbMATH objects in the set of links of a given partner.
c) The X-Field is an optional parameter that can be used when one is running a query that can pull back a lot of metadata, but only a few fields in the output are of interest. Example: in the GET/link one is interested only in retrieving the id identifier of sources where the name of the author is Abramowitz. Then, Author: Abramowitz, X-Field: {Source{Identifier{ID}}}.
run
COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker-compose up -d
visit http://127.0.0.1:5001/links_api/
To use the write feature in some endpoints it is required to set the environment variable
ZBMATH_API_KEY
.
This is unfortunately a bit complicated.
See
https://docs.docker.com/compose/environment-variables/
for details.
One alternative is use a docker-compose override file.
The following example file docker-compose.override.yml
version: '3.4'
services:
db:
ports:
- 5432:5432
rest:
environment:
ZBMATH_API_KEY: secretKey
Sets the key to secretKey
and maps the internal database to port 5432 on your host system.
This can be practical for development.
All settings are listed at in the method zb_links.app.configure_app.
Install https://github.com/nektos/act and run
act