alfred-python
alfred-python is the Python client for the Alfred (TagShelf) REST API and its real-time event stream. It wraps the endpoints for sessions, files, jobs, data points and standalone classification, handles authentication, retries and rate-limit throttling, and can push job and file events to your code as they happen.
Install
pip install alfred-python
The SDK detects the type of every local file you upload with python-magic, which needs the libmagic system library. The SDK loads it when you import alfred.rest, so a missing library shows up as an import error:
- Debian and Ubuntu:
apt-get install libmagic1 - macOS:
brew install libmagic - Windows: nothing to install. The SDK depends on
python-magic-bin, which bundles the library.
Supported Python versions are listed in docs/compatibility.md.
Quickstart
Upload a local file, process it as a job and read the extracted data points. You need an API key (see authentication).
import time
from alfred.base.config import Configuration
from alfred.http.typed import AuthConfiguration
from alfred.rest import AlfredClient
client = AlfredClient(
config=Configuration.v1(),
auth_config=AuthConfiguration({"api_key": "YOUR_API_KEY"}),
)
session_id = client.sessions.create()["session_id"]
with open("invoice.pdf", "rb") as local_file:
file_id = client.files.upload_file(
{"file": local_file, "session_id": session_id}
)["file_id"]
job_id = client.jobs.create({"session_id": session_id})["job_id"]
stopped = ("completed", "failed", "invalid", "canceled", "expired")
while client.jobs.get(job_id)["stage"] not in stopped:
time.sleep(5)
print(client.data_points.get_values(file_id))
Polling is the simplest way to wait. To be notified instead, use the real-time client. Getting started explains each step.
Documentation
Every page stands on its own. Start at the documentation index.
| Page | What it covers |
|---|---|
| Getting started | Install, create a client, and an end-to-end walkthrough from session to results. |
| Authentication | API key, OAuth (username and password) and HMAC; the ALFRED_API_KEY environment variable. |
| Configuration | Base URLs, HTTP settings (timeout, retries, throttling), response types, logging and custom HTTP clients. |
| Files | Upload local files and remote URLs, read file details, download the original. |
| Sessions | Deferred sessions: group several uploads into one job. |
| Jobs | Create jobs, read their status, list them, and cancel, restart or check the sources of a job. |
| Data points | Read the values Alfred extracted from a file, with their confidence and validation results. |
| Classification | Standalone classification: classify a text or a file against criteria you send with the request, without setting up document types first. |
| Real-time events | Subscribe to job and file events over a socket; the full event catalogue. |
| Error handling | What the SDK raises and how to handle it. |
| Compatibility | Supported Python versions and dependency policy. |
Development
Install the pinned dependencies, then run the tests:
pip install -r requirements.txt
python -m unittest
The unit tests (tests/test_*.py) need no credentials and never leave your machine. tests/__init__.py holds integration tests that call a real Alfred environment. They create a session and a job, so point them at a test tenant. They are skipped unless ALFRED_API_KEY is set. The variables they read:
| Variable | Default | Meaning |
|---|---|---|
ALFRED_API_KEY |
none | API key. Without it the integration tests are skipped. |
ALFRED_BASE_URL |
https://app.tagshelf.com |
Alfred environment to call. |
ALFRED_TEST_FILE_ID |
none | A file ID for test_get_file. The test is skipped when unset. |
ALFRED_TEST_UPLOAD_FILE |
none | Path of a local file for test_upload_file. The test is skipped when unset. |
Run one integration test with, for example, python -m unittest tests.TestMain.test_get_file.
Build the source distribution and wheel into dist/ with make build (it runs python -m build). make test runs the unit tests and make clean removes build output.
Contributing
- Pull requests target the
developmentbranch.masterholds reviewed releases, which are published from it. - Pull request titles are checked for a semantic prefix:
chore,docs,fix,feat,misc,testorrelease, for examplefix(files): keep the original file name. - The test suite runs on every pull request. Add or update tests with your change, and update the matching page in
docs/when behaviour changes.
License
MIT. See LICENSE.
Metadata
Release files for alfred-python 0.7.0
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 |
|---|---|---|---|---|
| alfred_python-0.7.0.tar.gz | 78.9 kB | With provenance | Details for alfred_python-0.7.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| alfred_python-0.7.0-py3-none-any.whl | Python 3 | none | any | Details for alfred_python-0.7.0-py3-none-any.whl |
Total release size: 125.4 kB
Release files / alfred_python-0.7.0.tar.gz
| Download URL | alfred_python-0.7.0.tar.gz |
|---|---|
| Size | 78.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7dea8399b16e10a93b32033d2f6d553607121947fd8a567e2e18e394f4dbf293
|
|
BLAKE2b-256 checksum How to use checksums |
45ebc34501d02a51b9f5e352fc55ff6f119d8fb259886d39893d15c354f32890
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.
Transparency logRelease files / alfred_python-0.7.0-py3-none-any.whl
| Download URL | alfred_python-0.7.0-py3-none-any.whl |
|---|---|
| Size | 46.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
45c147b09a33c00112050fdf6286e20c3fe76f418802db474509fc5d477127e9
|
|
BLAKE2b-256 checksum How to use checksums |
aa235db29c2cf8660b6f10a2e077312f94936278aafce03489a263839c1d795b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.
Transparency logSecurity for alfred-python 0.7.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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for alfred_python-0.7.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.
Transparency logA 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.