The frontendless framework for high growth companies. Interval automatically generates apps by inlining the UI in your backend code. It's a faster and more maintainable way to build internal tools, rapid prototypes, and more.
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()
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)
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()
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()
Contributing
This project uses Poetry for dependency management
poetry install
to install dependenciespoetry 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 ifdemo_name
omitted)poe test
to runpytest
(can also runpytest
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for interval_sdk-1.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22cd59affa3cffe30b661ec35c9e4ac298b33de362f7158b420ddbb440c14c22 |
|
MD5 | 9d0013af4e8702d75b89a627de85468b |
|
BLAKE2b-256 | d0e4f55de84f93742651f70c31cb3b3f45e46127d7d4e3312954017c1eacc08e |