Skip to main content

Python 3.7+ GNU AGPL V3 license ruff Documentation Status

Python library to interact with the UCS@school Kelvin REST API.

Features

  • Asynchronous

  • Automatic handling of HTTP(S) sessions

  • Type annotations

  • ~95% test coverage (unittests + integration tests)

  • Python 3.7, 3.8, 3.9, 3.10

Compatibility

A list of UCS@school Kelvin REST API server versions which introduce breaking changes can be found in the UCS@school Kelvin REST API Documentation.

Usage

The Session context manager opens and closes a HTTP session:

>>> import asyncio
>>> from ucsschool.kelvin.client import Session, User, UserResource
>>>
>>> async def get_user(username: str) -> User:
...     async with Session(
...         "USERNAME",
...         "PASSWORD",
...         "master.ucs.local",
...         verify="ucs-root-ca.crt"
...     ) as session:
...         return await UserResource(session=session).get(name=username)
...
>>> obj = asyncio.run(get_user("demo_student"))
>>>
>>> print(obj)
User('name'='test_user', dn='uid=test_user,cn=schueler,cn=users,ou=DEMOSCHOOL,dc=example,dc=com')
>>> print(obj.firstname, obj.lastname)
Test User

There are more examples in the docs usage section.

For HTTPS to work, the SSL CA of the target system (UCS Master) must either be publicly signed, installed on the client system or available as file (as in the example above). If the SSL CA certificate is not available verify=False. Obviously that is not safe! The CA of any UCS server can always be downloaded from http://FQDN.OF.UCS/ucs-root-ca.crt.

Installation

Install UCS@school Kelvin REST API Client via pip from PyPI:

$ pip install kelvin-rest-api-client

Tests

Development internal tests

The Kelvin-client-daily-job, an integration test for the Kelvin client, is run and daily with the newest UCS. The job takes around 10 minutes to run and can be configured to run with a feature branch and a Kelvin Rest Api version of your choice. This is the recommended way to run the full integration test suite.

Local Tests

There are some isolated unittests, but most tests run against a real UCS@school Kelvin REST API. A UCS 4.4 Docker container has been prepared for this (additionally to the Kelvin API Docker container). The Makefile automates downloading and starting the Docker containers (3.2 GB GB) and running the tests. It is also possible to use an existing UCS DC Master with UCS@school and the Kelvin API installed.

Install the dependencies for testing in your python virtual environment:

$ uv sync --extra test

The tests expect the existence of two schools (OUs) on the target system (the Kelvin API does not support creation of schools yet). The schools are DEMOSCHOOL and DEMOSCHOOL2. The first one usually already exists, but trying to create it again is safe. To create the schools run on the UCS DC Master:

$ /usr/share/ucs-school-import/scripts/create_ou DEMOSCHOOL
$ /usr/share/ucs-school-import/scripts/create_ou DEMOSCHOOL2

Furthermore an email domain must exist:

$ udm mail/domain create \
    --ignore_exists \
    --position "cn=domain,cn=mail,$(ucr get ldap/base)" \
    --set name="$(ucr get domainname)"

Since version 1.5.0 the Kelvin REST API supports UDM properties in all resources. A configuration is required for the tests for this feature:

$ cat > /etc/ucsschool/kelvin/mapped_udm_properties.json <<__EOF__
{
    "user": ["title"],
    "school_class": ["mailAddress"],
    "school": ["description"]
}
__EOF__

To use an existing UCS server for the tests, copy the file tests/test_server_example.yaml to tests/test_server.yaml and adapt the settings before starting the tests:

$ cp tests/test_server_example.yaml tests/test_server.yaml
$ $EDITOR tests/test_server.yaml
# check settings with a single test:
$ uv run python -m pytest tests/test_user.py::test_get

Run tests with current Python interpreter:

$ make test

Using tox the tests can be executed with all supported Python versions:

$ make test-all

Logging

Standard logging is used for tracking the libraries activity. To capture the log messages for this project, subscribe to a logger named ucsschool.kelvin.client. Attention: Passwords and session tokens will be logged at log level DEBUG!

The UCS@school Kelvin REST API on the UCS server logs into the file /var/log/univention/ucsschool-kelvin-rest-api/http.log. The UDM REST API on the UCS server logs into the file /var/log/univention/directory-manager-rest.log.

Release

- [ ] Check and update contents of [HISTORY.rst](./HISTORY.rst>)
- [ ] Check and update contents of [VERSION.txt](./VERSION.txt>)
- [ ] Kelvin client [Jenkins test](https://univention-dist-jenkins.k8s.knut.univention.de/job/UCSschool-5.0/view/Daily%20Tests/job/Kelvin-client-daily>) OK
- [ ] Tag commit in gitlab
- [ ] Run `make dist`
- [ ] Run `make docs`
- [ ] Run `make release-test` and verify the installation # uv auth login test.pypi.org/legacy
- [ ] Run `make release` and verify the installation # uv auth login pypi.org/legacy
- [ ] Verify packages on https://pypi.org/
- [ ] Release mail & chat announcement

Repo permissions

  • Github: @dansan and @JuergenBS

  • Gitlab: @JuergenBS

  • PyPI: @dansan and @SamuelYaron

  • RTD: @dansan and @SamuelYaron

Credits

Release files for kelvin-rest-api-client 2.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kelvin-rest-api-client 2.5.0
File Size Uploaded
kelvin_rest_api_client-2.5.0.tar.gz 58.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for kelvin-rest-api-client 2.5.0
File Interpreter ABI Platform
kelvin_rest_api_client-2.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 81.7 kB

Release files / kelvin_rest_api_client-2.5.0.tar.gz

Download URL kelvin_rest_api_client-2.5.0.tar.gz
Size 58.9 kB
Tags Source
SHA-256 checksum
How to use checksums
dc39fe7c6cb7d76876f7b76fbbc421eb1fa57765a6c61e1eaee3d130bf1894b0
BLAKE2b-256 checksum
How to use checksums
9987870a1a0de28ed9819f0321eeb58aa3f5104fd541b3c539d20828d8b0a46b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / kelvin_rest_api_client-2.5.0-py3-none-any.whl

Download URL kelvin_rest_api_client-2.5.0-py3-none-any.whl
Size 22.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7ae394309b06e51e3f6b06e5602dc8a1c8af55fca03886501d41903057bcae23
BLAKE2b-256 checksum
How to use checksums
c076266fec599f88fc0e0949042111bb1650c69579616f2bd747b09134fb37eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

2.5.0 This release

2 release files

2.4.2

2 release files

2.3.0

2 release files

2.2.3

2 release files

2.2.2

2 release files

2.2.1

2 release files

2.2.0

2 release files

2.1.0

1 release file

2.0.1

1 release file

2.0.0

2 release files

1.7.0

1 release file

1.6.1

2 release files

1.6.0

2 release files

1.5.2

2 release files

1.5.1

2 release files

1.5.0

2 release files

0.3.0

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page