Repository navigation
Conversation
This is a first step. It's not fully tested. It doesn't keep the full API space of the previous parent's internals but it does keep the features we know are used in the wild. Needs testing.
(cherry picked from commit 0379c61)
…d expand minimally with some much needed compilers (cherry picked from commit 5fba2e5)
(cherry picked from commit 3063183)
(cherry picked from commit da5fa38)
(cherry picked from commit 6882a65)
…st context (cherry picked from commit 8f3622e)
… parts of the helper function, so we don't need to be backward compatible with them (cherry picked from commit 81c7dbb)
…port for providing scope, wait_for_triplestore no longer does a sudo query to not break non-sudo services (cherry picked from commit 8533639)
(cherry picked from commit 726317f)
…th an example implementation services could use while waiting for the real deal (cherry picked from commit d02fbb6)
Raising a BaseHTTPException results in a JSONAPI error response. It is available without import and takes the same arguments as in the FastAPI based semantic-ai/mu-python-template. A sudo query without permission raises it with status 403. Co-authored-by: Joachim van der Herten <joachim@ml2grow.com>
Services may configure helpers.sparqlQuery and helpers.sparqlUpdate (e.g. a timeout or custom headers such as mu-auth-sudo), which earlier versions of the template applied to every query. Copying those per query keeps that working while staying thread-safe. As every query starts from a copy, the sudo and scope headers no longer need to be cleared.
- validate_resource_type compared strings by identity, rejecting valid resource types - validate_json_api_content_type crashed on requests without Content-Type - update_modified used the time the service started as default date
The Uvicorn worker sizes its WSGI thread pool with gunicorn's threads setting (default 1, e.g. GUNICORN_CMD_ARGS="--threads 4"), so a worker handles one request at a time like with meinheld. It also stops when gunicorn's reloader requests so, which Uvicorn didn't check. The uvicorn-worker package replaces the deprecated uvicorn.workers module. DEV_SERVER=gunicorn runs the production server with live-reloading in development mode. app.before_first_request, removed in Flask 2.3, is emulated with a deprecation warning.
Co-authored-by: Joachim van der Herten <joachim@ml2grow.com> Co-authored-by: karel kremer <karel.kremer@redpencil.io>
Member
Author
|
I will also remove the logs being written to a file, since that's not in-line with other templates. If you want to keep logs this can be done through docker. |
added 6 commits
October 27, 2026 08:31
Other templates only write to stdout and logs are available through stdout. Removing this for consistency. Log files require management and it's easiest if this is done in one place (through docker logs)
to keep .git and CI config out of the image
In line with the js template. Allowed groups resolved by mu-authorization are stored per request and forwarded to the client.
uv is a fast, pip-compatible installer. The pip-style interface is used with --system: no virtual environments (the container provides the isolation)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Server & base image
tiangolo/meinheld-gunicorn:python3.8base withpython:3.13-slim, running Gunicorn with a custom Uvicorn worker class (gunicorn_worker.py) that serves the Flask WSGI app. Behaviour is unchanged: 1 worker (WEB_CONCURRENCY), one request at a time, other Gunicorn settings available viaGUNICORN_CMD_ARGS.DEV_SERVER=gunicorndevelopment mode: production server with live reload, e.g. to test multi-worker/thread behaviour. Flask dev server (debugger) stays the default.Helpers
query()andupdate()execute on a per-call copy of the sharedSPARQLWrapperinstances, making the helpers safe under threads and multiple workers. Configuration set on the shared instances (timeouts, custom headers) still applies to every query.sudoandscopekeyword arguments.sudo=Truebypasses the requester's access rights but requires the container-level opt-inALLOW_MU_AUTH_SUDO;DEFAULT_MU_AUTH_SCOPEprovides a fallback scope.BaseHTTPException: raise a JSONAPI error response from anywhere in a handler; registered error handler turns it into a response (also available as a builtin like app).before_first_requestpolyfill for services written against older templates (deprecated).LOG_DIRconfigurable;wait_for_triplestoreremoved (documented workaround in README).Compatibility
Python 3.13, Flask ≥ 3.1, SPARQLWrapper ≥ 2.0, rdflib ≥ 7.1. See README "Upgrading from earlier versions"
Tested
Verified against a real service (catalog-harvester): builds, boots, and behaves identically to v2.0.0-beta.3.