After you’ve initialized your project with Trigger.dev, add these build settings to your trigger.config.ts file:
trigger.config.ts
Copy
Ask AI
import { pythonExtension } from "@trigger.dev/python/extension";import { defineConfig } from "@trigger.dev/sdk/v3";export default defineConfig({ runtime: "node", project: "<your-project-ref>", // Your other config settings... build: { extensions: [ pythonExtension({ // The path to your requirements.txt file requirementsFile: "./requirements.txt", // The path to your Python binary devPythonBinaryPath: `venv/bin/python`, // The paths to your Python scripts to run scripts: ["src/python/**/*.py"], }), ], },});
Learn more about executing scripts in your Trigger.dev project using our Python build extension
here.
This task uses the python.runScript method to run the image-processing.py script with the given image URL as an argument. You can adjust the image processing parameters in the payload, with options such as height, width, quality, output format, etc.
src/trigger/pythonPdfTask.ts
Copy
Ask AI
import { task } from "@trigger.dev/sdk/v3";import { python } from "@trigger.dev/python";export const processPdfForm = task({ id: "process-pdf-form", run: async (payload: { pdfUrl: string }, io: any) => { const { pdfUrl } = payload; const args = [pdfUrl]; const result = await python.runScript("./src/python/extract-pdf-form.py", args); // Parse the JSON output from the script let formData; try { formData = JSON.parse(result.stdout); } catch (error) { throw new Error(`Failed to parse JSON output: ${result.stdout}`); } return { formData, stderr: result.stderr, exitCode: result.exitCode, }; },});