Skip to main content

API client for Wilma school portal

Project description

Wilhelmina - Wilma API Client

A Python API client for the Wilma school platform. This client allows you to authenticate, fetch messages, and view message contents from the Wilma platform.

Why is this not called Wilma? The reason is simple, PyPi sees "Wilma" as a prohibited packages name. It is not taken on PyPi, it just is not allowed. Wilhelmina is the long/full version of the name Wilma which is the reason for the name.

Wilma API Features

  • Messages
    • List (API)
    • Get single (API)
    • Get unread (Scraping w/ Playwright)*

* There is an API that returns the status of a message (0=read, 1=unread) but this is not enabled on all instances, specifically not on the Turku instance that I was interested in.

Home Assistant compatibility

This library has support for passing in an existing aiohttp to allow for easier integration with Home Assistant. The version of aiohttp has also been slightly restricted in order to be installable in Home Assistant. mashumaro was chosen for type safe models instead of Pydantic to not need to go through the v1 vs. v2 hassle.

Features

  • Asynchronous API using aiohttp
  • Type-safe models using mashumaro
  • Optional unread message detection using Playwright for JavaScript rendering
  • Graceful fallback when Playwright is not installed (messages won't be marked as unread)
  • Comprehensive test suite

Note about AI

Sonnet 3.7 has written a lot code in this repository. Far from one-shotted however and a lot of refactoring has been done in order to get things into this state. The main purpose for creating this library was to get quick access to the Wilma API through Python.

Installation

# Basic installation
pip install wilma

# (Optional) Installation with Playwright support (for unread message detection)
pip install wilma[playwright]

# Playwright browser will be installed automatically on import

# Using Poetry
poetry add wilma -E playwright

API Client Usage

import asyncio
from wilma import WilmaClient

async def main():
    # Initialize client with an optional existing aiohttp session
    # Use headless=False to see the browser
    session = aiohttp.ClientSession()  # Optional - provide your own session
    
    async with WilmaClient("https://turku.inschool.fi", session=session, headless=True) as client:
        # Login
        await client.login("username", "password")
        
        # Get messages
        messages = await client.get_messages()
        
        # Print messages
        for msg in messages:
            # Show unread status
            unread_status = "UNREAD" if msg.unread else "read"
            print(f"{msg.id}: {msg.subject} - {msg.timestamp} - {msg.sender} - {unread_status}")
            
            # Get message content
            content = await client.get_message_content(msg.id)
            print(f"Content: {content.content[:100]}...")

# Run the main function
asyncio.run(main())

Development

Setup

# Clone the repository
git clone https://github.com/yourusername/wilma.git
cd wilma

# Install development dependencies
poetry install

# Install Playwright browser
poetry run playwright install chromium

Running Tests

# Run all tests
poetry run pytest

# Run specific tests
poetry run pytest wilma/tests/test_client.py

# Run with coverage
poetry run pytest --cov=wilma

Linting and Type Checking

# Format with ruff
poetry run ruff format wilma

# Run ruff for linting
poetry run ruff check wilma --fix

# Run mypy for type checking
poetry run mypy wilma

License

MIT

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

wilhelmina-0.1.0.tar.gz (17.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wilhelmina-0.1.0-py3-none-any.whl (21.6 kB view details)

Uploaded Python 3

File details

Details for the file wilhelmina-0.1.0.tar.gz.

File metadata

  • Download URL: wilhelmina-0.1.0.tar.gz
  • Upload date:
  • Size: 17.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.10 Darwin/24.2.0

File hashes

Hashes for wilhelmina-0.1.0.tar.gz
Algorithm Hash digest
SHA256 10c310635543808143f9fd1a3a50f646f8bb5b01a1cc90206b424706b0dfd4b2
MD5 17e787c89c54e3544df36a33c3cbd07b
BLAKE2b-256 fa1cc16e4f9a85ff607594950423a9f7335462dcfd8f4a0f9a36b14bc4239e4d

See more details on using hashes here.

File details

Details for the file wilhelmina-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: wilhelmina-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 21.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.10 Darwin/24.2.0

File hashes

Hashes for wilhelmina-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d07304c5b95e5a10f5e329d90cb536c016b807390c5e909281fb7af342b6c911
MD5 2040c9ba12f56a4a5c67546bde192808
BLAKE2b-256 4c5a006c01572ce8701d6603acfb87d89d3c2c4413e4b6d82d7b8fd2e66115e8

See more details on using hashes here.

Supported by

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