Skip to main content

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.

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

For development:

git clone https://github.com/BramVanroy/clarin-spf
cd clarin-spf
pip install -e .[dev]

playwright install chromium --with-deps

Usage

from clarin_spf import ClarinCredentials
import requests

base_url = "https://portal.clarin.ivdnt.org/galahad"

# Will trigger a browser pop-up to login and will store cookies (by default in ~/.cache/clarin/cookies.json)
cookies = ClarinCredentials(service_url=base_url, overwrite=True).cookies

# Get API response
user_resp = requests.get(f"{base_url}/api/user", cookies=cookies).json()
print(user_resp)

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
  • 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 as get, post, put, delete in the ClarinCredentials class, and when a json parse occurs, trigger a re-login request?

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

clarin_spf-0.1.1.tar.gz (18.1 kB view details)

Uploaded Source

Built Distribution

clarin_spf-0.1.1-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file clarin_spf-0.1.1.tar.gz.

File metadata

  • Download URL: clarin_spf-0.1.1.tar.gz
  • Upload date:
  • Size: 18.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.7

File hashes

Hashes for clarin_spf-0.1.1.tar.gz
Algorithm Hash digest
SHA256 fc53bf15fb47103fd851b6defa4decf614671932df253b4a8a72fb2910b2c51c
MD5 a5a20dafef6bdc650b4889b2db7d3c0f
BLAKE2b-256 54c79dace0bac6d6c2b7ccd05d6d4256fa6fabef3aa88caf0d4762b5c6bda3e4

See more details on using hashes here.

File details

Details for the file clarin_spf-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: clarin_spf-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 14.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.7

File hashes

Hashes for clarin_spf-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 10086f5f7f28ea2cd5946ee16a37fd0f9f103250869ab0e25192cadd4c765187
MD5 e023d991ff9fd21981492e44ee91ed16
BLAKE2b-256 065586eb6e0361e7fc6f069cf7a0c175989cee5716931e10c26de5eba68c2646

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page