#Dagger SDK FastAPI
1 messages · Page 1 of 1 (latest)
Hi! 👋 Could you describe your goal a bit more?
Are you creating a Dagger client connection in your containerized Python FastAPI app?
Guessing you may want to point to your Dagger Engine with the env var _EXPERIMENTAL_DAGGER_RUNNER_HOST
https://docs.dagger.io/configuration/custom-runner/#connection-interface
Hi @limber mantle. Yes, I am creating a Dagger client connection in my containerized Python FastAPI. I have also tried the env var. I even tried using Cursor with agents and it kept trying things until it ran out of options and created a TROUBLESHOOTING.md. The plan is to use Dagger for the AI logic of the app, much like LangChain etc.
Cc @thick ruin in case there is something tricky here
@limber mantle Are there any demo projects that use the Dagger SDK and an API framework like FastAPI?
We were daggerizing a FastAPI project the other day, but that was to give build, test, etc workflows to the app.
Sounds like you want to present an api that calls dagger in the backend?
@sullen dragon you might find these docs helpful:
https://docs.dagger.io/configuration/custom-runner/
it sounds like you are embedding the client into your fastapi application? If that’s the case you need to configure the client to talk to the other container like in the docs above
This might also be helpful https://docs.dagger.io/api/sdk#custom-applications
not sure if this is what you need but there is an example at https://github.com/vikram-dagger/fastapi-sample-app/blob/main/.dagger/src/agent/main.py
lmk if you need any help with it
This is how I deployed Dagger for a hosting platform (in the api with a remote runner). I can try to whip something up for an example if it’s helpful
@chrome lark Thanks for sharing. Let me check if I missed something and I’ll report back. An example is always helpful.
@solid raptor Thanks for sharing, I am looking into it.
@limber mantle Thanks for the prompt response.
Yeah @sullen dragon, Jason is on point. ☝️ You need to provision the Dagger engine outside your FastAPI container however is best for you, then give it access in the FastAPI container. There's a couple env vars you need other than _EXPERIMENTAL_DAGGER_RUNNER_HOST. You'll need the port and token to connect to it. When you establish a client connection with the Python SDK, it's only when port and token are missing that it tries to provision the engine for you. You can also let the Python SDK download the Dagger CLI and create that session since it's starting the engine itself that's probably more problematic for you.
Hi @sullen dragon, I made an example repo, with a docker compose customer runner and a go application (should work similarily with Python) showing you how to embed Dagger into an application and connect to the runner over TCP (not secure just an fyi). Here is also a quick screen recording of the application in action. Here is the link to the repo with the code: https://github.com/jasonmccallister/dagger-embedded-go-api
Hopefully this helps, have a great weekend