Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

interval/interval-py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Interval

Interval Python SDK

pypi version Documentation Twitter Discord

Interval lets you quickly build internal web apps (think: customer support tools, admin panels, etc.) just by writing backend Python code.

This is our Python SDK which connects to the interval.com web app. If you don't have an Interval account, you can create one here. All core features are free to use.

Why choose Interval?

"Python code > no-code"

Interval is an alternative to no-code/low-code UI builders. Modern frontend development is inherently complicated, and teams rightfully want to spend minimal engineering resources on internal dashboards. No-code tools attempt to solve this problem by allowing you to build UIs in a web browser without writing any frontend code.

We don't think this is the right solution. Building UIs for mission-critical tools in your web browser — often by non-technical teammates, outside of your codebase, without versioning or code review — is an anti-pattern. Apps built in this manner are brittle and break in unexpected ways.

With Interval, all of the code for generating your web UIs lives within your app's codebase. Tools built with Interval (we call these actions) are just asynchronous functions that run in your backend. Because these are plain old functions, you can access the complete power of your Python app. You can loop, conditionally branch, access shared functions, and so on. When you need to request input or display output, await any of our I/O methods to present a form to the user and your script will pause execution until input is received.

Here's a simple app with a single "Hello, world" action:

from interval_sdk import Interval, IO

# Initialize Interval
interval = Interval(api_key="<YOUR API KEY>")

@interval.action
async def hello_world(io: IO):
    name = await io.input.text("Your name")
    return f"Hello, {name}"


# 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, signal

loop = asyncio.get_event_loop()
task = loop.create_task(interval.listen_async())
def handle_done(task: asyncio.Task[None]):
    try:
        task.result()
    except:
        loop.stop()

task.add_done_callback(handle_done)
for sig in {signal.SIGINT, signal.SIGTERM}:
    loop.add_signal_handler(sig, loop.stop)
loop.run_forever()

Interval:

  • Makes creating full-stack apps as easy as writing CLI scripts.
  • Can scale from a handful of scripts to robust multi-user dashboards.
  • Lets you build faster than no-code, without leaving your codebase & IDE.

With Interval, you do not need to:

  • Write REST or GraphQL API endpoints to connect internal functionality to no-code tools.
  • Give Interval write access to your database (or give us any of your credentials, for that matter).
  • Build web UIs with a drag-and-drop interface.

More about Interval

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 [email protected] user exists already. Run yarn test in the web directory at least once to create it before running these.