Skip to main content

The Air Raid Alert API wrapper for Python3

Project description

AlertAPI

Async and static typed Air Raid Alert microframework for Python3.

Python 3.8, 3.9 and 3.10 are currently supported.

Installation

Install AlertAPI from PyPi with the following command:

pip install alertapi

Updating

pip install --upgrade alertapi

Start up basic client

import asyncio

import alertapi


async def main() -> None:
    client = alertapi.Client(access_token='...')
    print(await client.fetch_states())


loop = asyncio.get_event_loop()
loop.run_until_complete(main())

Example

import asyncio

import alertapi


async def main() -> None:
    client = alertapi.Client(access_token='...')

    print('State list:', await client.fetch_states())
    print('First 5 active alerts:', await client.fetch_states(with_alert=True, limit=5))
    print('Inactive alerts:', await client.fetch_states(with_alert=False))
    print('Kyiv info:', await client.fetch_state(25))
    print('Kyiv info:', await client.fetch_state('Kyiv'))
    print('Is active alert in Lviv oblast:', await client.is_alert('Lviv oblast'))


loop = asyncio.get_event_loop()
loop.run_until_complete(main())

Or run GatewayClient

import alertapi

client = alertapi.GatewayClient(access_token='...')


@client.listen(alertapi.ClientConnectedEvent)
async def on_client_connected(event: alertapi.ClientConnectedEvent) -> None:
    states = await event.app.fetch_states()
    print(states)


@client.listen(alertapi.PingEvent)
async def on_ping(event: alertapi.PingEvent) -> None:
    print('Ping event')


@client.listen(alertapi.StateUpdateEvent)
async def on_state_update(event: alertapi.StateUpdateEvent) -> None:
    print('State updated:', event.state)


client.connect()

Python optimization flags

CPython provides two optimisation flags that remove internal safety checks that are useful for development, and change other internal settings in the interpreter.

  • python main.py - no optimisation - this is the default.
  • python -O main.py - first level optimisation - features such as internal assertions will be disabled.
  • python -OO main.py - second level optimisation - more features (including all docstrings) will be removed from the loaded code at runtime.

A minimum of first level of optimizations is recommended when running applications in a production environment.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

alertapi-0.0.2-py3-none-any.whl (35.8 kB view details)

Uploaded Python 3

File details

Details for the file alertapi-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: alertapi-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 35.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.2

File hashes

Hashes for alertapi-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 73f2ccce04b48622f853eb359729aa1d68b121d8ec3fb56f92902f357903fd5c
MD5 9f2c52c49e07b74ad6a9d439c67096ce
BLAKE2b-256 fe72e41a5a273347a78deb787c87533f9348ba0f79d5148c3fff2a600a54c1cf

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