Skip to main content

python-gotify

PyPI Python License Code Style CI Codecov

python-gotify is a python client library to interact with your gotify server without having to handle requests manually.

It offers both a synchronous and an asynchronous interface powered by httpx. Optionally, push messages can be received via websockets.

Installation

python-gotify can be installed from PyPi using pip:

pip install gotify

If you want to listen to push messages, the additional dependency on websockets can be installed with

pip install gotify[stream]

Usage

To send messages:

from gotify import Gotify

gotify = Gotify(
    base_url="https://gotify.example.com",
    app_token="AsWIJhvlHb.xgKe",
)

gotify.create_message(
    "Hello you wonderful people!",
    title="Hello World",
    priority=0,
)

Note: To send messages you need to create a new application and set app_token accordingly.

You can also manage things like applications:

from gotify import Gotify

gotify = Gotify(
    base_url="https://gotify.example.com",
    client_token="CoLwHBCAr8z2MMA",
)

app = gotify.create_application("foobar", description="test application")

print("Created new application:", app)

would result in

Created new application: {'id': 42, 'token': 'ArHD_yGYf63-A13', 'name': 'foobar', 'description': 'test application', 'internal': False, 'image': 'static/defaultapp.png'}

Note: For most things you need to create a new client and set client_token accordingly.

This library tries to implement every endpoint of the gotify API as an instance method of the Gotify class.

More details about the capabilities of gotify's API can be found in its API documentation.

Note: since I don't use any gotify plugins, plugin-related functions are currently completely untested.

Async Usage

python-gotify's asynchronous client works similar to the synchronous one, you just need to await all methods. It is recommended to use it as a context manager if you want to send multiple requests.

import asyncio
from gotify import AsyncGotify

async def send_message_async():
    async_gotify = AsyncGotify(
        base_url="https://gotify.example.com",
        app_token="AsWIJhvlHb.xgKe",
    )

    await async_gotify.create_message(
        "This message was sent asynchronously!",
        title="Hello Asynchronous World",
    )

asyncio.run(send_message_async())

Reusing HTTP sessions

If you want to send multiple requests to a server you can use both Gotify and AsyncGotify as a (asynchronous) context manager which will use a single HTTP session to reduce some connection overhead.

with Gotify(...) as gotify:
    ...

async with AsyncGotify(...) as async_gotify:
    ...

Receive push messages via websockets

AsyncGotify implements gotify's /stream endpoint which allows to receive push messages via websockets. To use it make sure you installed python-gotify with pip install gotify[stream].

AsyncGotify.stream() is implemented as an asynchronous generator that waits for incoming messages and yields Message dictionaries.

import asyncio
from gotify import AsyncGotify

async def log_push_messages():
    async_gotify = AsyncGotify(
        base_url="https://gotify.example.com",
        client_token="CoLwHBCAr8z2MMA",
    )

    async for msg in async_gotify.stream():
        print(msg)

asyncio.run(log_push_messages())

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please use nox to format, lint, type-check and test your code by calling nox in your project directory.

The test suite downloads a server binary and starts a preconfigured test server on port 30080 (this doesn't work on MacOS). If you encounter issues starting the test server, please create an issue.

License

This project is licensed under the MIT License.

See LICENSE for more information.

Release files for gotify 0.6.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 gotify 0.6.0
File Size Uploaded
gotify-0.6.0.tar.gz 22.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gotify 0.6.0
File Interpreter ABI Platform
gotify-0.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 33.8 kB

Release files / gotify-0.6.0.tar.gz

Download URL gotify-0.6.0.tar.gz
Size 22.8 kB
Tags Source
SHA-256 checksum
How to use checksums
47bdc0332143cd5c251e284ffa487467429c624a1d40aefb013774f6f4dd4b7d
BLAKE2b-256 checksum
How to use checksums
60e5f7d6b37c70adce7533a93aadd9624a67ab79323766c8b3978a6653f16ea8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.31.0

Release files / gotify-0.6.0-py3-none-any.whl

Download URL gotify-0.6.0-py3-none-any.whl
Size 11.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
184faec76de78279c5acd6e21dfefd11223d74a816b607f1063ac22df40641b2
BLAKE2b-256 checksum
How to use checksums
732ea8eb9b07219346c1f87ff5fb810898a8de3eeeed758aa620cd43a53a2fc1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.31.0

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 release files

0.5.0

2 release files

0.4

2 release files

0.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1

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