Ask Inkeep
how does one pin the python dependencies
Answer
To pin Python dependencies in Windmill, you can use the
#requirements:
or #extra_requirements:
comments at the top of your script. Here's how you can do it:
1. Using #requirements:
:
If you want to override the inferred imports or pin specific versions, you can use the #requirements:
comment. Here's an example:
(1)
2. Using #extra_requirements:
:
If you want to combine Windmill's automatic inference with pinned dependencies, use the #extra_requirements:
comment:
These methods allow you to specify exact versions of dependencies or add extra dependencies that might not be automatically inferred by Windmill.
It's worth noting that Windmill automatically manages dependencies for you in standard mode. When you import libraries in your Python script, Windmill parses these imports upon saving the script and automatically generates a list of dependencies. (2)
If you need to use a specific version of a library that's different from what Windmill infers, or if you're encountering conflicts between dependencies, these pinning methods can be particularly useful. (3)4 replies
how does one pin the python dependencies
-----------------------------
While I generate an answer, here are some sources that might be helpful:
* Dependencies in Python
* Jobs
* Python Quickstart
* python dependencies version
-----------------------------
4 replies
how do I share logic between scripts
You can use both relative and absolute imports, but relative imports are preferred for compatibility with local editors.
Important Considerations
1. In both the web editor and CLI, scripts don't necessarily need a main function. If they don't have one, they're assumed to be shared logic and not runnable scripts. (1)
2. When using relative imports, make sure you have view rights on the scripts you're importing at the time of execution. (2)
3. The folder layout for sharing logic is identical to the one used with the CLI for syncing scripts locally and on Windmill.
4. For TypeScript, path depths can vary, and relative imports will work at any level, ensuring consistency between local and Windmill environments. (3)
By using these methods, you can effectively share common logic between your scripts in Windmill, improving code reusability and maintainability. (1) (2) (3)
5 replies
how do I share logic between scripts
Answer
Windmill allows you to share common logic between your scripts using relative imports in both Python and TypeScript. (1) This feature works well with local development and can be easily synced using the CLI.
Python Relative Imports
For Python scripts, you can import directly from other scripts by following the path layout. (2) Here's an example:
You can use relative imports for scripts in the same folder or user-space, or access scripts in different folders.
TypeScript Relative Imports
For TypeScript scripts using Deno or Bun, you can similarly import from other scripts. (3) Here's an example:
5 replies
how do I share logic between scripts
-----------------------------
While I generate an answer, here are some sources that might be helpful:
* Sharing Common Logic
* Dependency Management & Imports
* Dependencies in Python
* Dependencies in TypeScript
-----------------------------
5 replies
how do I get and set custom flow states
(1)
Remember that to use these functions, you need to import the
wmill
client library. For TypeScript, you would use import * as wmill from "windmill-client@1.297.0"
, and for Python, you would include #extra_requirements: #wmill==1.297.0
at the top of your script. (3) (1)
Custom flow states allow you to set and retrieve values from any step of a flow, and they will be available globally within the flow. This feature was introduced in Windmill version v1.296.0. (2)6 replies
how do I get and set custom flow states
Answer
To get and set custom flow states in Windmill, you can use the
setFlowUserState
and getFlowUserState
functions. These functions allow you to store and retrieve data across steps in a flow. Here's how you can use them:
1. Setting a custom flow state:
You can use the setFlowUserState
function to set a value for a given key. (1)
2. Getting a custom flow state:
You can use the getFlowUserState
function to retrieve a value for a given key. The custom flow states are stored in the flow state itself and have the same lifetime as the flow job. It's important to note that custom flow states are a powerful feature when passing data as output/input is not feasible, and using getResource/setResource
might clutter the workspace or create an inconvenient user experience. These functions are supported in both TypeScript and Python. (2) Here's an example in Python:
6 replies
how do I get and set custom flow states
-----------------------------
While I generate an answer, here are some sources that might be helpful:
* Within Windmill: Not recommended
* Architecture and Data Exchange
* Resources and Resource Types
* set flow user state POST /w/{workspace}/jobs/flow/user_states/{id}/{key}
-----------------------------
6 replies
relative imports in python
Answer
In Windmill, when working with Python scripts, you can share common logic between your scripts using relative imports. This feature allows you to easily reuse code across different scripts in your project. Here's how you can do it:
- To import directly from another Python script, you can follow the path layout. For instance, to import a function
foo
from a script called common_logic
located in the same user space, you would use the following syntax:
- It works with scripts contained in folders and for scripts contained in user spaces, such as f.<foldername>.script_path
or u.<username>.script_path
.
- Keep in mind that you can only import scripts that you have view rights on at the time of execution. This ensures that your code respects the necessary access controls (1) .
Remember, this flexibility in sharing common logic enhances your ability to maintain and organize your code efficiently, making your development process with Windmill more streamlined and effective.3 replies
relative imports in python
-----------------------------
While I generate an answer, here are some sources that might be helpful:
* Sharing Common Logic
* Dependency Management & Imports
* Python Quickstart
* bug: Scheduled script with relative import fails when import added to upstream
-----------------------------
3 replies