Skip to main content

Klokku REST API client

Project description

Klokku Python Client

A Python client for interacting with the Klokku REST API.

Installation

Using pip

pip install klokku-python-client

Using Poetry

poetry add klokku-python-client

Usage

The client provides an asynchronous interface to the Klokku API:

import asyncio
from klokku_python_client import KlokkuApi

async def main():
    # Create a client instance
    async with KlokkuApi("https://api.klokku.example.com/") as client:
        # Authenticate with a username
        authenticated = await client.authenticate("your_username")
        if not authenticated:
            print("Authentication failed")
            return

        # Get all budgets
        budgets = await client.get_all_budgets()
        if budgets:
            print(f"Found {len(budgets)} budgets:")
            for budget in budgets:
                print(f"- {budget.name} (ID: {budget.id})")

        # Get current event
        current_event = await client.get_current_event()
        if current_event:
            print(f"Current budget: {current_event.budget.name}")
            print(f"Started at: {current_event.startTime}")

        # Set a different budget
        if budgets and len(budgets) > 1:
            new_budget_id = budgets[1].id
            result = await client.set_current_budget(new_budget_id)
            if result:
                print(f"Set current budget to ID: {new_budget_id}")

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

Features

  • Asynchronous API client using aiohttp
  • Authentication with username
  • Get list of users
  • Get all budgets
  • Get current event/budget
  • Set current budget
  • Context manager support for proper resource cleanup

Development

CI/CD

This project uses GitHub Actions for continuous integration and deployment:

  1. Build Workflow: Runs on every push to the main branch, executing tests and building the package.
  2. Publish Workflow: Automatically publishes the package to PyPI when a new GitHub Release is created.

To set up the publishing workflow:

  1. Generate a PyPI API token at https://pypi.org/manage/account/token/
  2. Add the token as a GitHub repository secret named PYPI_API_TOKEN
  3. Create a new GitHub Release to trigger the publishing workflow

Setup

  1. Clone the repository
  2. Install dependencies with Poetry:
poetry install

Testing

The project uses pytest for testing with aioresponses for mocking HTTP requests.

To install test dependencies:

pip install -e ".[test]"

Or with Poetry:

poetry install --with test

To run the tests:

pytest

Or with Poetry

poetry run pytest

For more details about testing, see the tests README.

Releasing

  1. Upgrade the version in pyproject.toml
  2. Create a new GitHub Release
  3. The GitHub Actions build workflow will automatically publish the package to PyPI

Requirements

  • Python 3.13+
  • aiohttp 3.12+

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

klokku_python_client-0.3.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

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

klokku_python_client-0.3.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file klokku_python_client-0.3.0.tar.gz.

File metadata

  • Download URL: klokku_python_client-0.3.0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.13.9 Linux/6.11.0-1018-azure

File hashes

Hashes for klokku_python_client-0.3.0.tar.gz
Algorithm Hash digest
SHA256 07432f9c2661ea7ef65ede3831acd81650bfa2c6641db035ec0561298c415d5e
MD5 efad20f44e1a37b0b82744de4e5555dc
BLAKE2b-256 3118526f44f7a22fa3ca63c56ea5a1d807a5392cbd964358fba48c76c7d1129a

See more details on using hashes here.

File details

Details for the file klokku_python_client-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: klokku_python_client-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.13.9 Linux/6.11.0-1018-azure

File hashes

Hashes for klokku_python_client-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1d1e61684ef5687c4b03a9a0d23295c843ec87a0d0d42e8becc469f7dd57bbae
MD5 52ef036a3bdf404c47924626d1d95cf6
BLAKE2b-256 25e0ec2b0a49f0102c985938902f3e06f465c7607510d99e5f2c345ed24b35eb

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