REST for Duit
A web-based REST API for duit datafields.
This is an addon module for the data ui toolkit (duit) which adds REST API support for DataFields.
Installation
The package can be installed directly from PyPI.
pip install duit-rest
Documentation
Duit-rest uses FastAPI as REST backend to handle HTTP requests. The main class is the
RESTService which handles the HTTP server and maps the annotated DataFields to the corresponding endpoints.
RESTEndpoint
It is possible to annotate existing DataFields with the RESTEndpoint annotation. This annotation later tells the
RESTService if the field has to be exposed over REST. It is recommended to gather all DataFields in a single object:
from duit_rest.RESTEndpoint import RESTEndpoint
class Config:
def __init__(self):
self.name = DataField("Cat") | RESTEndpoint()
By default, the name of the variable (e.g. name) is used as REST endpoint identifier. It is possible to change the
name through the RESTEndpoint annotation.
self.name = DataField("Cat") | RESTEndpoint(name="the-cats-name")
RESTService
The RESTService handles the HTTP server and mapping with the DataFields. Here is a simple example on how to create a
RESTService, add the previously defined config and start the service.
# create an actual instance of the config
config = Config()
# create a rest service
rest_service = RESTService()
# add the config object (create mapping) under the route "/config"
rest_service.add_route("/config", config)
# run the service
rest_service.run()
Settings
The RESTService has several default arguments that can be changed before the service is started:
# RESTService parameters and their default values
host: str = "0.0.0.0", # on which interface the service is running
port: int = 9420, # on which port the service is running
title: str = "REST API" # title of the API
Routes
It is possible to add various objects to the RESTService, each with a unique route (address).
rest_service.add_route("/config", config)
Each DataField is accessible under this route, so for example the name field would be available at /config/name.
API Usage
Getting values:
# Get entire configuration
GET http://localhost:9420/config
# Get specific field
GET http://localhost:9420/config/name
Setting values:
# Update entire configuration
POST http://localhost:9420/config
Content-Type: application/json
{
"name": "NewName",
"age": 25
}
# Update specific field
GET http://localhost:9420/config/name?value="NewName"
Start
To start the service, call the run() method. This is a blocking method that doesn't return until the service is
shutdown:
# run blocking
rest_service.run()
To start the service in its own thread, set the blocking argument to `False:
# run non-blocking
thread = rest_service.run(blocking=False)
About
Copyright (c) 2025 Florian Bruggisser
Metadata
Release files for duit-rest 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| duit_rest-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for duit_rest-0.1.0-py3-none-any.whl |
Release files / duit_rest-0.1.0-py3-none-any.whl
| Download URL | duit_rest-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1a63e14d22dcc89d7c3ab2e88a759ffba15f89279f060d7284e7e4b1405c92c7
|
|
BLAKE2b-256 checksum How to use checksums |
289f9891d1134d4d6ecdc7070f493919c165134f5251d4717f3e7dffb4873bf7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.12.8
|
Security for duit-rest 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.