Snip-Its 1.0.0 introduces a feature we are excited about: Python-defined custom variables. Custom variables let you write Python scripts that run at expansion time, turning your snip-its from static text into dynamic, programmable templates.
What Are Custom Variables?
Snip-Its already supports built-in variables like date, time, and clipboard content. Custom variables take this further - you define your own variables as Python functions, and Snip-Its calls them every time the snippet expands.
The return value of your function replaces the variable placeholder in your snippet. This means your expanded text can include anything Python can compute: formatted dates, math results, generated text, data from files, or even API responses.
How It Works
Each custom variable is a Python function. You give it a name, write the function body, and Snip-Its handles the rest. The rules are simple:
- Define a function with the exact variable name:
def my_variable(): - The function must take no arguments
- It must contain at least one
returnstatement - The return value must be a string (or convertible to string)
- The function is called once per expansion - keep it fast
- Network requests are allowed but subject to a 5-second timeout
Here is the basic template:
def my_variable():
# Your code here
return "Hello from my_variable"
Then use {{my_variable}} anywhere in your snippet body.
Example: Fiscal Quarter
Say you frequently type dates in a specific format that the built-in date variable does not cover:
def fiscal_quarter():
from datetime import datetime
now = datetime.now()
quarter = (now.month - 1) // 3 + 1
return f"Q{quarter} FY{now.year}"
Use {{fiscal_quarter}} in your snippet, and it expands to something like Q1 FY2026 every time.
Example: Random Meeting ID
Need to generate a unique meeting ID for calendar invites?
def meeting_id():
import random
import string
code = ''.join(random.choices(string.ascii_uppercase + string.digits, k=8))
return f"MTG-{code}"
Each expansion produces a fresh ID like MTG-K7X2BN4P.
Example: Days Until Friday
A countdown you can drop into any message:
def days_until_friday():
from datetime import datetime
today = datetime.now()
days_ahead = 4 - today.weekday() # Friday = 4
if days_ahead <= 0:
days_ahead += 7
return f"{days_ahead} days until Friday"
What You Can Build
Because custom variables run real Python, the possibilities are broad:
- Formatted timestamps in any locale or format
- Calculated values like invoice totals, unit conversions, or countdowns
- Data lookups from local files, databases, or CSV spreadsheets
- Template generation for emails, reports, or code scaffolding
- Random data for test fixtures, placeholder content, or IDs
- Network requests to APIs, webhooks, or internal services (within 5s timeout)
Reserved Variable Names
The following names are used by built-in variables and cannot be used for custom variables:
date, time, datetime, clipboard,
username, hostname, os, cursor,
random, input, snippet.
Requirements
Custom variables require:
- Python 3.6 or later installed on your system
- Snip-Its 1.0.0 or later
By default, Snip-Its uses the Python interpreter found on your system PATH. You can also point Snip-Its to a specific Python interpreter in Settings - bring your own Python install, virtual environment, or conda environment. Execution timeout is 5 seconds per variable.
Security and Privacy
Custom variable scripts run locally on your machine, just like everything else in Snip-Its. Your scripts are stored alongside your snip-its in local storage - they are never sent to any server. You have full control over what your scripts do.
Get Started
Python-defined custom variables are available in Snip-Its 1.0.0 for all users. Download the latest version and start building dynamic snip-its.
Already have Snip-Its installed? The app will prompt you to update automatically. Once updated, head to the snippet editor, add a custom variable, write your Python function, and use {{your_variable}} in your snippet.