Skip to content

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

License

Notifications You must be signed in to change notification settings

ChimekKoo/pylibrus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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