Sciris utils

From sciris/sciris · View interactive version

Sciris utils is an AI agent skill from the GitHub repository sciris/sciris. Use when working with Sciris miscellaneous utilities — sc.mergedicts, sc.mergelists, sc.tolist, sc.toarray, sc.isnumber, sc.suggest, sc.download, sc.runcommand, sc.importbypath, sc.loadtext, sc.help, sc.traceback, sc.autolist, sc.pp, or type checking/conversion.

How to use this skill

Skill file

Sciris Miscellaneous Utilities

Reference for type handling, downloading, and other tools. See full tutorial: docs/tutorials/tut_utils.ipynb.

If you need more detail, use your MCP tools (Context7 or GitMCP) to look up current Sciris documentation, or consult the other Sciris skills.

Type Conversion

Merge dicts (handles None)

def my_func(json=None, **kwargs):
    default = dict(a=1, b=2)
    output = sc.mergedicts(default, json, kwargs)  # None inputs are OK
    return output

Merge lists (auto append/extend)

sc.mergelists(['a', 'b'], 'c', None, {'d': 1})  # ['a', 'b', 'c', {'d': 1}]

Flexible conversion

sc.tolist('single')       # ['single'] — safe to iterate
sc.tolist(['already'])    # ['already'] — unchanged
sc.toarray(2)             # array([2]) — handles scalars (np.array doesn't)
sc.toarray([1, 2, 3])    # array([1, 2, 3])
sc.cat(1, [2, 3], np.array([4, 5]))  # array([1, 2, 3, 4, 5]) — concatenates

Auto-incrementing list

output = sc.autolist()
for item in data:
    output += f'Result: {item}'   # Appends automatically with +=

Type Checking

sc.isnumber(3)            # True
sc.isnumber(3.14j)        # True
sc.isnumber('3')          # False

Fuzzy Matching

sc.suggest('Scirys', ['Python', 'NumPy', 'Sciris'])  # 'Sciris'

Downloading

data = sc.download(urls, save=False)     # Download to memory (parallel)
sc.download(urls, save=True)             # Download to disk

Running Shell Commands

out = sc.runcommand('ls *.py', printoutput=True) # Use instead of Popen()

Import by Path

old = sc.importbypath('sim_v1/sim.py')   # Import without sys.path
new = sc.importbypath('sim_v2/sim.py')   # Two modules with same name
plt = sc.lazyimport('matplotlib.pyplot') # Only imported when first used

Help and Debugging

sc.help('interpol')                  # Search all Sciris source code
sc.help('interpol', context=True)    # With surrounding context
sc.traceback()                       # Get exception traceback as string
sc.loadtext('file.py')              # Load text file as string
sc.pp(obj)                          # Pretty-print any object
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.