Package: gotify
python-gotifypython-gotify is a python client library to interact with yourgotifyserver without having to handle requests manually.It offers both a synchronous and an asynchronous interface powered byhttpx.
Optionally, push messages can be received via websockets.Installationpython-gotify can be installed fromPyPiusing pip:pip install gotifyIf you want to listen to push messages, the additional dependency onwebsocketscan be installed withpip install gotify[stream]UsageTo send messages:fromgotifyimportGotifygotify=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 setapp_tokenaccordingly.You can also manage things like applications:fromgotifyimportGotifygotify=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 inCreated 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 setclient_tokenaccordingly.This library tries to implement every endpoint of the gotify API as an instance method of theGotifyclass.More details about the capabilities of gotify's API can be found in itsAPI documentation.Note:since I don't use any gotify plugins, plugin-related functions are currently completely untested.Async Usagepython-gotify's asynchronous client works similar to the synchronous one, you just need toawaitall methods. It is recommended to use it as a context manager if you want to send multiple requests.importasynciofromgotifyimportAsyncGotifyasyncdefsend_message_async():async_gotify=AsyncGotify(base_url="https://gotify.example.com",app_token="AsWIJhvlHb.xgKe",)awaitasync_gotify.create_message("This message was sent asynchronously!",title="Hello Asynchronous World",)asyncio.run(send_message_async())Reusing HTTP sessionsIf you want to send multiple requests to a server you can use bothGotifyandAsyncGotifyas a (asynchronous) context manager which will use a single HTTP session to reduce some connection overhead.withGotify(...)asgotify:...asyncwithAsyncGotify(...)asasync_gotify:...Receive push messages via websocketsAsyncGotifyimplements gotify's/streamendpoint which allows to receive push messages via websockets. To use it make sure you installed python-gotify withpip install gotify[stream].AsyncGotify.stream()is implemented as an asynchronous generator that waits for incoming messages and yieldsMessagedictionaries.importasynciofromgotifyimportAsyncGotifyasyncdeflog_push_messages():async_gotify=AsyncGotify(base_url="https://gotify.example.com",client_token="CoLwHBCAr8z2MMA",)asyncformsginasync_gotify.stream():print(msg)asyncio.run(log_push_messages())ContributingPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.Please usenoxto format, lint, type-check and test your code by callingnoxin 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.LicenseThis project is licensed under the MIT License.SeeLICENSEfor more information.