mijnbib
Python API for bibliotheek.be (formerly mijn.bibliotheek.be)
With this Python library you can retrieve your borrowed items, reservations and account information if you have an account on https://bibliotheek.be, the Flemish & Brussels public library network. You can also extend loans.
This API allows you to show and extend your loans (or loans from multiple accounts in your family) in your own coding projects, such as a small desktop or web application.
A list of supported libraries can be found in libraries.md.
Installation
Install via:
pip install mijnbib
Or, to force an upgrade:
pip install --upgrade mijnbib
Usage
For example, retrieving your borrowed items can be done as follows (after installation):
from mijnbib import MijnBibliotheek
username = "johndoe"
password = "12345678"
account_id = "123" # see the number in the URL, or via mb.get_accounts()
mb = MijnBibliotheek(username, password)
loans = mb.get_loans(account_id)
print(loans)
For a more readable version, use pprint():
import pprint
pprint.pprint([l for l in loans])
# outputs:
[
Loan(
title="Erebus",
loan_from=datetime.date(2023, 11, 25),
loan_till=datetime.date(2023, 12, 23),
author="Palin, Michael",
type="Boek",
extendable=True,
extend_url="https://gent.bibliotheek.be/mijn-bibliotheek/lidmaatschappen/123/uitleningen/verlengen?loan-ids=789",
extend_id="789",
branchname="Gent Hoofdbibliotheek",
id="456789",
url="https://gent.bibliotheek.be/resolver.ashx?extid=%7Cwise-oostvlaanderen%7C456789",
cover_url="https://webservices.bibliotheek.be/index.php?func=cover&ISBN=9789000359325&VLACCnr=10157217&CDR=&EAN=&ISMN=&EBS=&coversize=medium",
account_id="123",
)
]
Below is a code snippet showing the main functionality:
accounts = mb.get_accounts()
acc_id = accounts[0].id
loans = mb.get_loans(acc_id)
reservations = mb.get_reservations(acc_id)
all_info = mb.get_all_info(acc_id)
For more examples (including extending loans), see the code in the examples folder.
It also uses asdict for conversion to a dictionary.
Command-line interface
Warning: the cli is experimental and may change without warning. Do not base any automation on it; use the Python API instead.
You can call the module from the command-line as follows:
python -m mijnbib loans
python -m mijnbib --version
Or, directly via the CLI command:
mijnbib loans
The --help option shows all available options
$ mijnbib --help
usage: mijnbib [-h] [-V] [-v] {all,accounts,loans,reservations,login} ...
Interact with bibliotheek.be website, e.g. to retrieve loans, reservations
or accounts.
Specify the required authentication parameters (username, password, ...)
as a parameter of the subcommando. See the help of a subcommando for all
parameters, e.g. `mijnbib --help all`
More convenient is creating a `mijnbib.ini` file containing the parameters:
[DEFAULT]
username = john
password = 123456
accountid = 456
positional arguments:
{all,accounts,loans,reservations,login}
all retrieve all information for all accounts
accounts retrieve accounts
loans retrieve loans for account id
reservations retrieve reservations for account id
login just log in, and report if success or not
options:
-h, --help show this help message and exit
-V, --version show program's version number and exit
-v, --verbose show debug logging
Notes
-
Data models - Check models.py for details on each of the available objects. Note that
Loanobjects do not have a unique loan identifier; they can be identified - across extensions - by the combination of the library item (theidproperty), the start date of the loan (loan_fromproperty), and the account (account_id). -
Error handling - Depending on the application, it may be advisable to provide error handling. The
errors.pyfile contains the list of Mijnbib-specific exceptions. The docstrings of the public methods contain the errors that can occur. For example:from mijnbib import AuthenticationError, MijnbibError, MijnBibliotheek mb = MijnBibliotheek(username, password) try: accounts = mb.get_accounts() except AuthenticationError as e: print(e) # wrong credentials except MijnbibError as e: print(e) # any other custom mijnbib error
-
Compatibility with bibliotheek.be - This Python API retrieves its data via web scraping of the bibliotheek.be website. Therefore it depends on the structure of the website. When the structure of the website changes, it is very likely that all or certain functionality will suddenly stop working.
In that case, you have to wait until this Python library is updated to deal with the new structure.
Provide a try/except wrapper, where you either catchMijnbibError, or the more specificIncompatibleSourceError.
Alternatives
The Home Assistant plugin https://github.com/myTselectionPublic/bibliotheek_be scrapes the bibliotheek.be website in a similar way.
Development
This project uses the following tools:
uv(install viacurl -LsSf https://astral.sh/uv/install.sh | sh)make(for Windows, see e.g. https://stackoverflow.com/a/32127632/50899)
To install all dependencies for development:
make init
If all is good, the following should print mijnbib <version>:
uv run mijnbib --version
Note: This works because mijnbib is installed as a cli script via the
project.scripts entry in pyproject.toml, with uv run taking care of
activating the virtual environment before running the command.
Running the tests, applying linting and code formatting can be done via:
make dev # markdown linting, fast tests, linting, formatting
make all # the above + more (see Makefile)
Publishing:
-
Update
changelog.md(do not commit) -
Do:
make all uvx uv-ship next patch # (updates pyproject.toml and uv.lock, # creates tag and pushes to remote) make publish # always cleans + rebuilds dist/ first, # so it can't upload stale/wrong-version artifacts
-
Create release in github, starting from tag
Metadata
Release files for mijnbib 0.12.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mijnbib-0.12.0.tar.gz | 21.1 kB | Without provenance | Details for mijnbib-0.12.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mijnbib-0.12.0-py3-none-any.whl | Python 3 | none | any | Details for mijnbib-0.12.0-py3-none-any.whl |
Total release size: 45.6 kB
Release files / mijnbib-0.12.0.tar.gz
| Download URL | mijnbib-0.12.0.tar.gz |
|---|---|
| Size | 21.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b6845386e2628e52e2e04c01c76fa3995e45c16e9079ea9253e7dd572e233f8b
|
|
BLAKE2b-256 checksum How to use checksums |
5da8f255427cf1560993c497e6018b1154e262d21e4b9d1fd507863961e4b7cb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.8.13
|
Release files / mijnbib-0.12.0-py3-none-any.whl
| Download URL | mijnbib-0.12.0-py3-none-any.whl |
|---|---|
| Size | 24.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a072c5c79a0f45f1968d0a73e5101e66ae41ae19bcc3a7cecef385753b3ba873
|
|
BLAKE2b-256 checksum How to use checksums |
99354a3d4f9f1526f049fc02f6a6c926777ff9b0f1fbe9cefdd88443fb069033
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.8.13
|
Security for mijnbib 0.12.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.