PSDify: A PowerShell Module for Workspace Management for Dify¶
PSDify is a PowerShell module designed to enable workspace management for Dify from the command line.
Here are some examples of what you can do with PSDify:
- ✨ Export and import apps
- ✨ Create knowledge and upload files
- ✨ Manage members: retrieve, invite, remove, and change roles
- ✨ Add models and update system models
- ✨ Search and install plugins
- ✨ Initialize instances for the Community Edition
- ✨ Copy login commands from your browser with the companion Chrome/Edge extension
For a full list of available cmdlets, refer to the 📚Documentation.
Warning
- 🚨 This is an unofficial project. LangGenius does not provide any support for this module.
- 🚨 It uses undocumented APIs of Dify, which means it may break with future updates to Dify.
- 🚨 The Enterprise Edition of Dify (multi-workspace environments) is not supported.
- 🚨 Currently, the focus is on "making it work." This means error handling and documentation are incomplete, and it does not strictly follow PowerShell best practices.
Tested Environments¶
The latest tested Dify version is 1.17.0.
Note
- This module has been tested mainly against Dify Community Edition and Dify Cloud Edition, with Windows PowerShell (PowerShell 5.1) and PowerShell 7.4.
- The Enterprise Edition of Dify (multi-workspace environments) can also be operated by this module, but it is not fully tested.
Quick Start¶
For a full list of available cmdlets, refer to the 📚Documentation.
Installation¶
Connecting to Dify¶
[!TIP]
**For Dify Cloud Edition**, email code login is no longer available due to Cloudflare Turnstile.
Instead, use the **PSDify Helper** browser extension to copy a ready-to-paste `Connect-Dify` command with `-AuthMethod "AccessToken"` from your browser with a single right-click, without needing to extract tokens manually.
See the [Browser Extension](#browser-extension) section below.
# Authenticate with a password (for Community Edition)
Connect-Dify -AuthMethod "Password" -Server "https://dify.example.com" -Email "dify@example.com"
# Authenticate with tokens (for Dify Cloud or Enterprise Edition)
# The PSDify Helper browser extension can extract the tokens and construct the command for you with a single right-click.
# See the "Browser Extension" section below for details.
$AccessToken = ConvertTo-SecureString -String "eyJhbGci..." -AsPlainText -Force
$CSRFToken = ConvertTo-SecureString -String "eyJhbGci..." -AsPlainText -Force
Connect-Dify -AuthMethod "AccessToken" -Server "https://cloud.dify.ai" -AccessToken $AccessToken -CSRFToken $CSRFToken
# Authenticate with a one-time code (for Enterprise Edition with Email Code Login enabled)
Connect-Dify -AuthMethod "Code" -Server "https://dify.example.com" -Email "dify@example.com"
Managing Apps¶
# Retrieve apps
Get-DifyApp
# Export apps (as .\DSLs\*.yml)
Get-DifyApp | Export-DifyApp
# Import apps
Get-Item -Path "DSLs/*.yml" | Import-DifyApp
Managing Knowledge¶
# Retrieve knowledge
Get-DifyKnowledge
# Create knowledge
New-DifyKnowledge -Name "My New Knowledge"
# Upload files to knowledge and wait for indexing to complete
$Knowledge = Get-DifyKnowledge -Name "My New Knowledge"
Get-Item -Path "Docs/*.md" | Add-DifyDocument -Knowledge $Knowledge -Wait
Managing Members¶
# Retrieve members
Get-DifyMember
# Invite a new member
New-DifyMember -Email "user@example.com" -Role "normal"
# Change a member's role
Get-DifyMember -Email "user@example.com" | Set-DifyMemberRole -Role "editor"
Managing Models¶
# Retrieve models
Get-DifyModel
# Add a predefined model
New-DifyModel -Provider "openai" -From "predefined" `
-Credential @{
"openai_api_key" = "sk-proj-****************"
}
# Add a customizable model
New-DifyModel -Provider "openai" -From "customizable" `
-Type "llm" -Name "gpt-4o-mini" `
-Credential @{
"openai_api_key" = "sk-proj-****************"
}
# Update the system model
Set-DifySystemModel -Type "llm" -Provider "openai" -Name "gpt-4o-mini"
Managing Plugins¶
# Search plugins
Find-DifyPlugin -Id "langgenius/openai"
# Install a plugin and wait for it to be installed
Find-DifyPlugin -Id "langgenius/openai" | Install-DifyPlugin -Wait
# Get installed plugins
Get-DifyPlugin
Initializing a Community Edition Instance¶
# Start a Dify instance with Docker Compose
docker compose up -d
# Wait for the instance to be ready
Wait-Dify -Server "https://dify.example.com"
# Initialize the instance
Initialize-Dify -Server "https://dify.example.com" -Email "dify@example.com" -Name "Dify"
Browser Extension¶
PSDify Helper is a companion Chrome/Edge extension that copies a ready-to-paste Connect-Dify command from the Dify console, without needing to extract tokens manually.
Note
PSDify Helper is available on the Chrome Web Store. It is also compatible with Microsoft Edge. See the 📚Documentation for installation and usage instructions.
Right-click any Dify console page to open the PSDify submenu:
- Copy Login Command: Places the following on your clipboard:
Import-Module PSDify
$env:PSDIFY_URL="https://cloud.dify.ai"
$env:PSDIFY_AUTH_METHOD="AccessToken"
$env:PSDIFY_ACCESS_TOKEN="eyJhbGci..."
$env:PSDIFY_CSRF_TOKEN="eyJhbGci..."
Connect-Dify
- Copy Access Token: Copies the raw access token.
- Copy CSRF Token: Copies the raw CSRF token.
The extension works with cloud.dify.ai out of the box. Self-hosted instances can be added from the extension's options page.
The extension reads session cookies solely to copy them to the clipboard upon your request. No data is transmitted to any server or stored locally.