Skip to main content

Leesah Python in English

🇧🇻 Du finner den norske utgaven lengre ned.

Leesah-game is an event-driven application development game that challenges players to build an event-driven application. The application handles different types of tasks that it receives as events on a Kafka-based event stream. The tasks vary from very simple to more complex.

This is the Python library to play Leesah!

Getting started

There are two versions of the the Leesah game! On is for local play, directly in the terminal. While the other is running on the Nais platform, and you learn how to be a developer in Nav and use Nais. This library is used by both versions, but the following documentation is just for local play.

Setting up local environment

We recommend to use a virtual environment when playing Leesah, for example using Venv.

Start by creating the folder leesah-game. Then set up the virtual environment using the following commands.

For macOS/Linux

cd leesah-game
python3 -m venv venv
source ./venv/bin/activate

For Windows

cd leesah-game
python3 -m venv venv
.\venv\Scripts\activate

Install the library

There is only one dependency you need to play, and that is the leesah-game library.

python3 -m pip install leesah-game

Fetch Kafka certificates

You need some certificates to connect to the Kafka cluster, which is available at leesah.io/certs. The username is always leesah-game, and the password will be distributed.

You can also use the one-liner below:

curl -u leesah-game:<see presentation> -o leesah-certs.zip https://leesah.io/certs && unzip leesah-certs.zip

Using the command above you will end up with leesah-certs.yaml in the leesah-game directory you made earlier.

Example code

To make it easy to start we have made a working example that answer the first question, team-registration, with a dummy name and color. All you need to do is update TEAM_NAME and HEX_CODE, and your ready to compete!

Create a file called main.py and paste the code below.

"""Play Leesah Game

1. Download the Kafka certificate, and make sure that you have a file called leesah-certs.yaml in the same directory as this file
2. Set your own 'TEAM_NAME'
3. Set your own 'HEX_CODE' as team color
"""
import leesah

TEAM_NAME = "CHANGE ME"
HEX_CODE = "CHANGE ME"


class Rapid(leesah.QuizRapid):
    """The class that will answer the questions."""

    def run(self):
        """Start quiz!

        We recommend that you use seperate functions to answer each question.
        """
        while True:
            message = self.fetch_question()
            if message.category == "team-registration":
                self.handle_team_registration(message.question)

    def handle_team_registration(self, message):
        self.publish_answer(HEX_CODE)


if __name__ == "__main__":
    rapid = Rapid(TEAM_NAME, ignored_categories=[
        # "team-registration",
    ])

    try:
        rapid.run()
    except (KeyboardInterrupt, SystemExit):
        rapid.close()

Running code

Run you code:

python3 main.py

Leesah Python på norsk

🇬🇧 Go further up for the English documentation.

Leesah-game er et hendelsedrevet applikasjonsutviklingspill som utfordrer spillerne til å bygge en hendelsedrevet applikasjon. Applikasjonen håndterer forskjellige typer oppgaver som den mottar som hendelser på en Kafka-basert hendelsestrøm. Oppgavene varierer fra veldig enkle til mer komplekse.

Python-bibliotek for å spille Leesah!

Kom i gang

Det finnes to versjoner av Leesah-game! En hvor man lager en applikasjon som kjører på Nais, og en hvor man spiller lokalt direkte fra terminalen. Dette biblioteket kan brukes i begge versjoner, men denne dokumentasjonen dekker kun lokal spilling.

Sett opp lokalt miljø

Vi anbefaler at du bruker et virtuelt miljø for å kjøre koden din, som for eksempel Venv.

Start med å opprette en katalog leesah-game.

For macOS/Linux

cd leesah-game
python3 -m venv venv
source ./venv/bin/activate

For Windows

cd leesah-game
python3 -m venv venv
.\venv\Scripts\activate

Installer biblioteket

Det er kun en avhengighet du trenger, og det er biblioteket leesah-game.

python3 -m pip install leesah-game

Hent Kafkasertifikat

Sertifikater for å koble seg på Kafka ligger tilgjengelig på leesah.io/certs, passord får du utdelt.

Du kan også bruke kommandoen nedenfor:

curl -u leesah-game:<se presentasjon> -o leesah-certs.zip https://leesah.io/certs && unzip leesah-certs.zip

Du vil nå ende opp med filen leesah-certs.yaml i leesah-game-katalogen du lagde tidligere.

Eksempelkode

For å gjøre det enklere å komme i gang har vi et fungerende eksempel som svarer på spørsmålet om lagregistrering med et navn og en farge (hexkode). Opprett filen main.py og lim inn koden nedenfor.

"""Spill Leesah Game

1. Hent ned sertifikater, og sikre deg at de ligger i filen leesah-certs.yaml
2. Sett 'LAGNAVN' til ditt valgte lagnavn
3. Sett 'HEXKODE' til din valgte farge
"""
import leesah

LAGNAVN = "BYTT MEG"
HEXKODE = "BYTT MEG"


class Rapid(leesah.KvissRapid):
    """Klassen som svarer på spørsmålene."""

    def kjør(self):
        """Start quizen!

        Vi anbefaler at du bruker funksjoner til å svare på spørsmålene.
        """
        while True:
            melding = self.hent_spørsmål()
            if melding.kategori == "lagregistrering":
                self.behandle_lagregistrering(melding.spørsmål)

    def behandle_lagregistrering(self, spørsmål):
        self.publiser_svar(HEXKODE)


if __name__ == "__main__":
    rapid = Rapid(LAGNAVN, ignorerte_kategorier=[
        # "lagregistrering",
    ])

    try:
        rapid.kjør()
    except (KeyboardInterrupt, SystemExit):
        rapid.avslutt()

Kjør koden

Kjør koden din med:

python3 main.py

Metadata

Release files for leesah-game 1.4.1

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

Source distribution (sdist)

Source distribution for leesah-game 1.4.1
File Size Uploaded Provenance
leesah_game-1.4.1.tar.gz 10.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for leesah-game 1.4.1
File Interpreter ABI Platform
leesah_game-1.4.1-py3-none-any.whl Python 3 none any Details

Total release size: 20.8 kB

Release files / leesah_game-1.4.1.tar.gz

Download URL leesah_game-1.4.1.tar.gz
Size 10.6 kB
Tags Source
SHA-256 checksum
How to use checksums
b3dfea13e26b8a9a8bf86ea87c12d5a256082c10c2859dafc50fb8a404033d73
BLAKE2b-256 checksum
How to use checksums
ee881a9d0025421b8292c91d216c5258b9e82d4314147e9d6157727580b7bf92
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.7.15

Release files / leesah_game-1.4.1-py3-none-any.whl

Download URL leesah_game-1.4.1-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3140606f32ce0f354f86a42e067e5e6f3924926355eaf976db8f35ea4f5714da
BLAKE2b-256 checksum
How to use checksums
6d5d82b949541dcb134a7268f9021a164f44b06fca6ed20fcef75db1b1a9560b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.7.15

Security for leesah-game 1.4.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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