Skip to main content

Python SDK for Interval.

Project description

interval-sdk

Installation

Install using pip, (or your python package manager of choice):

pip install interval-sdk

API

Note: Proper documentation is in progress!

See src/demos/basic.py and src/tests for a better overview, but in short:

from interval_sdk import Interval, IO

# Initialize Interval
interval = Interval("API_KEY")

# Add an action using the function name as the slug
@interval.action
async def hello_interval():
    return {"hello": "from python!"}

# Add an action using a custom slug (can contain hyphens) and additional configuration
@interval.action(slug='echo-message', unlisted=True)
async def echo_message(io: IO):
    [message] = await io.group(io.input.text("Hello!", help_text="From python!"))

    return {"message": message}


# Synchronously listen, blocking forever
interval.listen()

To not block, interval can also be run asynchronously using interval.listen_async(). You must provide your own event loop.

The task will complete as soon as connection to Interval completes, so you likely want to run forever or run alongside another permanent task.

import asyncio

# This is what synchronous `listen()` does under the hood
loop = asyncio.get_event_loop()
loop.create_task(interval.listen_async())
loop.run_forever()

If you are using run_forever(), you'll probably want to add signal handlers to close the loop gracefully on process termination:

import asyncio, signal

loop = asyncio.get_event_loop()
loop.create_task(interval.listen_async())
for sig in {signal.SIGINT, signal.SIGTERM}:
    loop.add_signal_handler(sig, loop.stop)
loop.run_forever()

Contributing

This project uses Poetry for dependency management

  1. poetry install to install dependencies
  2. poetry shell to activate the virtual environment

Tasks are configured using poethepoet (installed as a dev dependency).

  • poe demo [demo_name] to run a demo (basic by default if demo_name omitted)
  • poe test to run pytest (can also run pytest directly in virtual env)

Code is formatted using Black. Please configure your editor to format on save using Black, or run poe format to format the code before committing changes.

Tests

Note: Tests currently require a local instance of the Interval backend.

Tests use pytest and playwright.

Currently assumes the test-runner@interval.com user exists already. Run yarn test in the web directory at least once to create it before running these.

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

interval_sdk-0.37.0.dev3.tar.gz (42.7 kB view hashes)

Uploaded Source

Built Distribution

interval_sdk-0.37.0.dev3-py3-none-any.whl (48.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page