Python API client for AUTOMATIC1111/stable-diffusion-webui enabling programmatic Stable Diffusion image generation
Complete model lifecycle management including loading, switching, and querying available models, samplers, schedulers, and other resources. These functions provide essential model discovery and configuration capabilities.
Retrieve information about available models and resources installed in the WebUI instance.
def get_sd_models() -> List[Dict]:
"""
Get list of available Stable Diffusion models.
Returns:
List of model dictionaries containing:
- title: Model display name
- model_name: Internal model name
- hash: Model hash
- sha256: SHA256 hash
- filename: Model file path
- config: Model configuration file
"""
def get_samplers() -> List[Dict]:
"""
Get list of available sampling methods.
Returns:
List of sampler dictionaries containing:
- name: Sampler name
- aliases: Alternative names
- options: Sampler-specific options
"""
def get_schedulers() -> List[Dict]:
"""
Get list of available schedulers.
Returns:
List of scheduler dictionaries containing:
- name: Scheduler name
- label: Display label
- aliases: Alternative names
"""
def get_upscalers() -> List[Dict]:
"""
Get list of available upscaling models.
Returns:
List of upscaler dictionaries containing:
- name: Upscaler name
- model_name: Internal model name
- model_path: Path to model file
- model_url: Download URL (if available)
- scale: Upscaling factor
"""
def get_sd_vae() -> List[Dict]:
"""
Get list of available VAE models.
Returns:
List of VAE dictionaries containing:
- model_name: VAE model name
- filename: VAE file path
"""
def get_loras() -> List[Dict]:
"""
Get list of available LoRA models.
Returns:
List of LoRA dictionaries containing LoRA metadata
"""
def get_hypernetworks() -> List[Dict]:
"""
Get list of available Hypernetwork models.
Returns:
List of hypernetwork dictionaries
"""
def get_face_restorers() -> List[Dict]:
"""
Get list of available face restoration models.
Returns:
List of face restorer dictionaries
"""
def get_realesrgan_models() -> List[Dict]:
"""
Get list of available Real-ESRGAN models.
Returns:
List of Real-ESRGAN model dictionaries
"""
def get_prompt_styles() -> List[Dict]:
"""
Get list of available prompt styles.
Returns:
List of style dictionaries containing:
- name: Style name
- prompt: Style prompt template
- negative_prompt: Style negative prompt template
"""
def get_embeddings() -> List[Dict]:
"""
Get list of available textual inversions/embeddings.
Returns:
List of embedding dictionaries
"""
def get_latent_upscale_modes() -> List[Dict]:
"""
Get list of available latent upscaling modes.
Returns:
List of latent upscale mode dictionaries containing:
- name: Mode name
- description: Mode description
"""
def get_artist_categories() -> List[Dict]:
"""
Get artist categories (deprecated).
Returns:
List of artist category dictionaries
Note: This method is deprecated but still available for backwards compatibility.
"""
def get_artists() -> List[Dict]:
"""
Get list of artists (deprecated).
Returns:
List of artist dictionaries
Note: This method is deprecated but still available for backwards compatibility.
"""Switch between models and refresh model lists.
def refresh_checkpoints() -> None:
"""
Refresh the list of available checkpoints/models.
Forces WebUI to rescan the models directory and update
the available model list.
"""
def util_set_model(name: str) -> None:
"""
Set the active Stable Diffusion model with fuzzy matching.
Parameters:
- name: Model name (supports partial matching)
Uses fuzzy string matching to find the best match among
available models if exact name not found.
"""
def util_get_current_model() -> str:
"""
Get the currently active Stable Diffusion model name.
Returns:
String containing the current model name
"""Helper functions for common model management tasks.
def util_get_model_names() -> List[str]:
"""
Get sorted list of available model names.
Returns:
Sorted list of model names for easy selection
"""
def util_get_sampler_names() -> List[str]:
"""
Get sorted list of available sampler names.
Returns:
Sorted list of sampler names
"""
def util_get_scheduler_names() -> List[str]:
"""
Get sorted list of available scheduler names.
Returns:
Sorted list of scheduler names
"""AI-powered prompt generation using specialized models for creative prompt enhancement and expansion.
def list_prompt_gen_models() -> List[str]:
"""
Get list of available prompt generation models.
Returns:
List of model names for prompt generation, such as:
- "AUTOMATIC/promptgen-lexart"
- "AUTOMATIC/promptgen-majinai-safe"
- "AUTOMATIC/promptgen-majinai-unsafe"
"""
def prompt_gen(
text: str,
model_name: str = "AUTOMATIC/promptgen-lexart",
batch_count: int = 1,
batch_size: int = 1,
min_length: int = 20,
max_length: int = 150,
num_beams: int = 1,
temperature: float = 1.0,
repetition_penalty: float = 1.0,
length_preference: float = 1.0,
sampling_mode: str = "Top K",
top_k: int = 12,
top_p: float = 0.15
) -> List[str]:
"""
Generate enhanced prompts using AI models.
Parameters:
- text: Base text to expand into a full prompt
- model_name: Prompt generation model to use
- batch_count: Number of batches to generate
- batch_size: Number of prompts per batch
- min_length: Minimum prompt length
- max_length: Maximum prompt length
- num_beams: Number of beams for beam search
- temperature: Sampling temperature (higher = more creative)
- repetition_penalty: Penalty for repeated words
- length_preference: Preference for longer prompts
- sampling_mode: Sampling method ("Top K", "Top P", "Typical P")
- top_k: Top-K sampling parameter
- top_p: Top-P (nucleus) sampling parameter
Returns:
List of generated prompts
"""Usage Examples:
import webuiapi
api = webuiapi.WebUIApi()
# Discover available models
models = api.get_sd_models()
for model in models:
print(f"Model: {model['title']}")
print(f"Filename: {model['filename']}")
print(f"Hash: {model['hash']}")
print("---")
# Get current model
current_model = api.util_get_current_model()
print(f"Current model: {current_model}")
# Switch to a different model (with fuzzy matching)
api.util_set_model("realistic_vision") # Matches "realisticVisionV40_v40VAE.safetensors"
# Get available samplers and schedulers
samplers = api.get_samplers()
sampler_names = [s['name'] for s in samplers]
print(f"Available samplers: {sampler_names}")
schedulers = api.get_schedulers()
scheduler_names = [s['name'] for s in schedulers]
print(f"Available schedulers: {scheduler_names}")
# Check upscaling options
upscalers = api.get_upscalers()
upscaler_names = [u['name'] for u in upscalers]
print(f"Available upscalers: {upscaler_names}")
# Refresh model list after adding new models
api.refresh_checkpoints()
# Use utility functions for easy access
model_names = api.util_get_model_names()
print(f"All available models: {model_names}")
# Generate enhanced prompts
available_prompt_models = api.list_prompt_gen_models()
print(f"Available prompt models: {available_prompt_models}")
prompts = api.prompt_gen(
text="a beautiful cat",
model_name="AUTOMATIC/promptgen-lexart",
batch_size=3,
temperature=1.2,
max_length=100
)
print("Generated prompts:")
for i, prompt in enumerate(prompts):
print(f"{i+1}: {prompt}")class Upscaler(str, Enum):
"""Enumeration of standard upscaling algorithms."""
none = "None"
Lanczos = "Lanczos"
Nearest = "Nearest"
LDSR = "LDSR"
BSRGAN = "BSRGAN"
ESRGAN_4x = "R-ESRGAN 4x+"
R_ESRGAN_General_4xV3 = "R-ESRGAN General 4xV3"
ScuNET_GAN = "ScuNET GAN"
ScuNET_PSNR = "ScuNET PSNR"
SwinIR_4x = "SwinIR 4x"
class HiResUpscaler(str, Enum):
"""Enumeration of high-resolution upscaling methods."""
none = "None"
Latent = "Latent"
LatentAntialiased = "Latent (antialiased)"
LatentBicubic = "Latent (bicubic)"
LatentBicubicAntialiased = "Latent (bicubic antialiased)"
LatentNearest = "Latent (nearest)"
LatentNearestExact = "Latent (nearest-exact)"
Lanczos = "Lanczos"
Nearest = "Nearest"
ESRGAN_4x = "R-ESRGAN 4x+"
LDSR = "LDSR"
ScuNET_GAN = "ScuNET GAN"
ScuNET_PSNR = "ScuNET PSNR"
SwinIR_4x = "SwinIR 4x"Install with Tessl CLI
npx tessl i tessl/pypi-webuiapi