Skip to main content

Librus (polish school e-register) unofficial API client written in Python.

Project description

PyLibrus

Stand With Ukraine License MIT

Librus (polish school e-register) unofficial API client written in Python.

Installation

pip3 install pylibrus

Usage

(Replace every field containing 'your' with your data)

Authorization

  • Authorize using existing token (load existing tokens pair)
    or
  • Generate new OAuth token
    • using user credentials:
      import pylibrus
      access_token, refresh_token = pylibrus.auth.user_credentials(
          username="yourusername",
          password="yourpassword",
          long_lived=True # optional, if set to True (default) token will be valid for 24h, if set to False token will be valid for 3h
      )
      print(
          access_token, # used to access resources
          refresh_token # used to regenerate access token without user credentials
      )
      
    • using previousely generated refresh token:
      import pylibrus
      access_token, refresh_token = pylibrus.auth.refresh_token(
          refresh_token="yourrefreshtoken",
          long_lived=True # default True (if not specified)
      )
      print(access_token, refresh_token)
      

Accessing resources

Access resources using previousely generated access token (see Authorization):

import pylibrus
lib = pylibrus.Librus("youraccesstoken") # previousely generated/cached access token
json_res = lib.getResource("YourResourceName")
print(json_res) # Raw API response (decoded JSON as dict)

List of available resources here.

Examples

Get user name using login/password authorization:

import pylibrus
lib = pylibrus.Librus(pylibrus.auth.user_credentials(
    username="yourusername",
    password="yourpassword",
)[0])
names = lib.getResource("Me")["Me"]["User"]
print(f"Hello {names['FirstName']} {names['LastName']}")

Get number of user's grades using new access token generated using previousely cached refresh token:

import pylibrus
lib = pylibrus.Librus(pylibrus.auth.refresh_token(
    refresh_token="yourrefreshtoken"
)[0])
grades = lib.getResource("Grades")["Grades"]
print(len(grades))

Contribute

Any pull requests are welcome. You can set up a development environment like this:

git clone https://github.com/YOU/YOUR_FORK.git .
python3 -m venv venv
source venv/bin/activate
pip3 install -r requirements.txt

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

pylibrus-0.0.1.tar.gz (3.9 kB view hashes)

Uploaded Source

Built Distribution

pylibrus-0.0.1-py3-none-any.whl (4.8 kB view hashes)

Uploaded Python 3

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