This release is a pre-release and may not be stable for production use.
Psych Ingestor
A simple web server for ingesting, routing, and saving data from behavioral tasks in the psych research world
Status: early. There's a working service you can run and point a task at -- see
docs/trying_it.md. It does the four things in docs/api.md and not much else; the
deferred features below are still deferred. If you're writing a task against it, read
docs/api.md -- it ends with a list of what's still moving.
Overview
Psych Ingestor (Pig) is set up to handle data streams from a variety of online studies -- in principle, all of your lab's tasks can share this service. You'll set up a file containing a set of task definitions, and your tasks will send HTTPS requests to it to signal start and end of tasks, as well as send data. Data is sent as a series of JSON lines (one JSON object per recorded event) and stored with minimal processing.
Your task itself will generally be statically-hostable; it will normally consist of HTML, javascript, and CSS. There's nothing saying you can't have a separate server-side component to this, but you don't need one. Similarly, if you're building your tasks as standalone apps, that works too -- a task can collect a whole session offline and send everything at once when the device next has a network.
Technically, Pig consists of a few components:
- A Python / FastAPI service that handles data collection and storage
- A file, in version control, containing your task definitions
- A SQLite database of runtime state -- runs in progress, participants seen, which events have been stored
- Somewhere on the server to keep the data, one directory per run, with any audio or video a task recorded alongside its events
- A command-line program that does everything happening on a schedule rather than on request, plus checking your configuration
Tasks are the top level: there's no notion of a study or a project that owns them. A lab running one project with six tasks configures six tasks.
The words
Pig uses BIDS' vocabulary, because most people here have already met it:
- A participant takes part in a study
- They come in for a session --
baseline,3mo, whatever your study calls its timepoints - At each session they do a task -- a Stroop task, a delay-discounting game
- Each time they do that task is a run, and a run records events
A run is the thing Pig tracks. It starts when a participant arrives, collects events while they work, and finishes when the task says so. If the same participant starts the same task twice, that's two runs, and Pig keeps both -- nothing overwrites anything.
See docs/definitions.md if you need the precise version.
How a task talks to Pig
Four URLs, and you only need the first three. All of them take and return JSON.
| URL | What it does |
|---|---|
POST /v1/task/{task_code}/run |
Start a run. Send the parameters from the participant's link; get back a run ID. |
POST /v1/task/{task_code}/run/{run_id} |
Send events. One JSON object per event, keyed by an event ID you make up. |
POST /v1/task/{task_code}/run/{run_id}/finalize |
Say you're done. Pig finishes up from there. |
GET /v1/task/{task_code}/run/{run_id} |
Check on a run -- its status and which events Pig has. |
A task that records audio, video, or anything else too big for an event has three more,
under /v1/task/{task_code}/run/{run_id}/media: start a media item (which is an ordinary
event, with a media ID handed back), send its bytes in numbered parts, and say how many
parts you sent. It's off unless a task's configuration turns it on.
The event ID is the important part. You assign one to every event, unique within the run, and Pig stores each ID exactly once. That means a failed request is always safe to send again: retry the whole batch and Pig will keep what it's missing and ignore what it already has. It also means a flaky connection can't quietly put a duplicate trial in your data file.
When you send events, Pig replies with everything it's stored for the run so far, so you always know where you stand. If the participant closes the tab before you finalize, the events you already sent are still saved.
See docs/api.md for the full detail, including a complete worked example.
Task configuration
Each task gets an entry in a configuration file, kept in version control. The entry answers things like:
- What parameters Pig expects from the link to define a run (
participant_id? plus asessionfor repeated visits?) - What (if any) settings will Pig send back to the task when a run starts?
- How long a run may stay open before Pig closes it
- Is the task accepting more data, or is it currently closed?
See docs/configuration.md.
Command-line programs
The web service only does web service things -- it takes requests, checks them, and writes data. Everything that happens on a schedule instead of on request lives in a command-line program you run from cron or a systemd timer: finishing runs that have closed, copying them offsite, expiring runs that have been open too long.
There's also a check command for configuration, because a typo in a task definition
should surface before a participant hits the task, not during.
The commands are pig check, pig serve, pig sweep, pig runs, pig health, and
pig migrate, for a database an older Pig made. The machine where the data ends up has
its own, under pigsty. See docs/trying_it.md.
Documentation
| File | What's in it |
|---|---|
docs/trying_it.md |
Getting a server running on your own machine. Start here if you want to poke at it. |
docs/api.md |
The requests your task makes. Start here if you're writing a task. |
docs/definitions.md |
What Pig means by task, session, run, dataset, event, participant. |
docs/configuration.md |
Task definitions, where data lands, the CLI. |
docs/security.md |
What Pig defends against and what it doesn't. |
docs/deployment.md |
Running the service. |
docs/design_assumptions.md |
Why Pig is shaped the way it is. Read before arguing about a design decision. |
docs/documentation_style.md |
How to write Pig's user-facing prose. |
Deferred features
These may prove important, but they're not what we're building first.
Parameter signing
If you want to stop people from editing their own session parameters, we can generate per-study (or per-participant or per-session) keys, and either distribute a signing key to clients, or distribute signed values to them (eg, we put a participant_id signature in REDCap and pass that to tasks). When starting a run we can check that the value has been correctly signed.
This is worth doing eventually and it's a real complication for testing -- you can't type a URL by hand any more -- so it'll be optional and set per task.
Limiting the number of runs
Right now, a participant who starts the same task five times gets five runs, all kept. A
task might reasonably want to say "one and done," or "at most three" -- a max_runs
setting. That needs a defined answer for what the participant past the limit gets told,
since turning someone away mid-study is a real event and the task has to say something
useful to them.
Pre-defining the participants / runs for a study
Maybe you want a bit more security than just "hey anyone can gin up a json request and barf data into the study" and that's a pretty reasonable thing to want to limit. So we can add a CLI that lets study managers / scripts add participants and/or sessions to a database of people who are allowed to do a task.
When that happens, a roster will be a named thing that tasks point at, rather than a list written into each task's definition -- so the six tasks in one project can share one roster by naming it.
Metadata
Release files for psych-ingestor 1.0.0rc3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| psych_ingestor-1.0.0rc3.tar.gz | 83.4 kB | Without provenance | Details for psych_ingestor-1.0.0rc3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| psych_ingestor-1.0.0rc3-py3-none-any.whl | Python 3 | none | any | Details for psych_ingestor-1.0.0rc3-py3-none-any.whl |
Total release size: 178.1 kB
Release files / psych_ingestor-1.0.0rc3.tar.gz
| Download URL | psych_ingestor-1.0.0rc3.tar.gz |
|---|---|
| Size | 83.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e347a74d5a5e49fa412e3b9e8566f7c9ebe673132847e2a56709bd9bec4fd75f
|
|
BLAKE2b-256 checksum How to use checksums |
e16830296136a012eb9361a91da59b2c09cf3a2a868d0076c320966bfd5d0143
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / psych_ingestor-1.0.0rc3-py3-none-any.whl
| Download URL | psych_ingestor-1.0.0rc3-py3-none-any.whl |
|---|---|
| Size | 94.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
76a3a46d037dc60e4f9690645ebcd170897f24335e53979684efd433530d4411
|
|
BLAKE2b-256 checksum How to use checksums |
fe0c1e5ebd63c1314bc40ab8e3bab2761c6fcb8fb46be983ed9fb2de3bc5a4bb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for psych-ingestor 1.0.0rc3
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.