A Python package to interact with the CLARIN SPF API to retrieve the 'logged in' cookies necessary to potentially interact with APIs of services that require the authentication.
Project description
CLARIN SPF
Utility package to login to CLARIN's SPF and then collect the required session cookies for the login. These cookies can then be used to call the APIs of services that require authorization. Note that the pop-up login occurs in an isolated browser environment so no personal information or cookies are ever collected or used or even read.
The cookies are stored in locally in a file (by default in ~/.cache/clarin/cookies.json
) and can be re-used for future requests. If they expire, the login window will automatically pop up again.
Installation
You can install the package from PyPI but you will also have to install the necessary browser utilities via playwright.
pip install clarin-spf
playwright install chromium --with-deps
For development:
git clone https://github.com/BramVanroy/clarin-spf
cd clarin-spf
pip install -e .[dev]
playwright install chromium --with-deps
Usage
Once you have logged in by initializing the ClarinRequester
class, you can use the get
, post
, put
, and delete
methods to make requests to the CLARIN services. The cookies will be automatically added to the request headers. The request methods are identical to the requests
package.
from clarin_spf import ClarinRequester
base_url = "https://portal.clarin.ivdnt.org/galahad"
clarin = ClarinRequester(trigger_url=base_url)
response = clarin.get(f"{base_url}/api/user").json()
print(f"Found user: {response['id']}")
See example usages in examples/.
To do
- Investigate feasibility of using a headless browser
- Investigate feasibility of running in notebooks
- Investigate feasibility of running in CI/CD
- Full MyPy compatible type hints
- Add more tests where applicable
- Improve handling of cookies: when they expire, the
requests.get
call will fail and just return HTML for the CLARIN discovery login. Incorporate common operations such asget
,post
,put
,delete
in theClarinCredentials
class, and when a json parse occurs, trigger a re-login request?
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file clarin_spf-0.2.0.tar.gz
.
File metadata
- Download URL: clarin_spf-0.2.0.tar.gz
- Upload date:
- Size: 19.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ccb786873d7760b72b6818da348bb3d5b1bc23e48ef1899097615ed10295e29 |
|
MD5 | 780fd42a5f6bedbd88980fb2af9bba7e |
|
BLAKE2b-256 | c2ded01a84ee6047b863c0f82bf7c880424422dc9f22ffb2b6023c859612961c |
File details
Details for the file clarin_spf-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: clarin_spf-0.2.0-py3-none-any.whl
- Upload date:
- Size: 15.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2e780c85ce62b776d117cce89fd806c5fdd9f603027b1cf544c6ff8411c42bb |
|
MD5 | 00058291f22aa93da29f9d91ed035f29 |
|
BLAKE2b-256 | d0bf91013c141e3aff94a171c4689df32f68651817811646ca3e626df5d58dde |