App Module (stx.app)
Runtime SDK for SciTeX applications. Provides a unified interface for file storage, configuration, and lifecycle management that works identically in local and cloud environments.
Note
stx.app delegates to the standalone
scitex-app package.
Install with: pip install scitex-app.
Overview
SciTeX applications are self-contained scientific tools that can run
locally or on the SciTeX cloud platform. The stx.app module
provides the runtime SDK that each application uses to interact with
its environment.
Quick Start
import scitex as stx
# Get current application info
info = stx.app.get_info()
# Access application preferences
prefs = stx.app.get_prefs()
# Check dependencies
stx.app.check_deps()
Key Features
- Unified File Storage
Read and write files through a single API that abstracts local filesystem and cloud storage.
# These work identically locally and in the cloud stx.app.write_file("results/output.csv", data) content = stx.app.read_file("config/settings.yaml")
- Configuration Management
Application preferences are stored in a standard location and accessible via dot-notation.
prefs = stx.app.get_prefs() print(prefs.theme) print(prefs.default_format) stx.app.set_prefs(theme="dark", default_format="pdf")
- Application Lifecycle
Query and manage the running application.
info = stx.app.get_info() print(info.name) print(info.version) current = stx.app.get_current() # Currently active app
- Dependency Checking
Verify that all required packages are available.
missing = stx.app.check_deps() if missing: print(f"Missing: {missing}")
Creating an Application
Scaffold a new SciTeX application from a template:
scitex template clone app my_tool
This creates a project with bridge-init configuration, MountPoint definitions, and EventBus integration pre-configured.
API Reference
scitex-app — Write-once interface for local + cloud SciTeX apps.
Standalone package. Zero dependencies (pure stdlib). When used with scitex, integration is automatic via scitex.app.
Public API (3 functions):
from scitex_app.sdk import get_files, register_backend, FilesBackend
# Get a file backend (auto-detects local vs cloud)
files = get_files("./project")
# Read/write files
content = files.read("data/config.yaml")
files.write("output/result.csv", csv_text)
# Register a custom backend
register_backend("s3", my_s3_factory)
- class scitex.app.FilesBackend(*args, **kwargs)[source]
Bases:
ProtocolFile storage backend protocol.
Implementations must provide these 7 methods. Uses
typing.Protocolfor structural subtyping — backends just implement the methods, no inheritance required.Implementations
FileSystemBackend— local pathlib (ships with scitex-app)CloudFilesBackend— HTTP via scitex_hub (provided at runtime)
- delete(path)[source]
Delete a file.
- Raises:
FileNotFoundError – If the file does not exist.
- Return type:
- rename(old_path, new_path)[source]
Rename/move a file within the namespace.
- Raises:
FileNotFoundError – If old_path does not exist.
FileExistsError – If new_path already exists.
- Return type:
- copy(src_path, dest_path)[source]
Copy a file within the namespace.
- Raises:
FileNotFoundError – If src_path does not exist.
- Return type:
- scitex.app.get_files(root=None, *, backend=None, **kwargs)[source]
Get a files backend instance.
Auto-detection logic:
If
backendis specified, use that.If
SCITEX_API_TOKENenv var is set and “cloud” backend is registered, use cloud.Otherwise, use filesystem (default).
- scitex.app.register_backend(name, factory)[source]
Register a files backend factory.
- Parameters:
name (
str) – Backend identifier (e.g., “cloud”, “s3”).factory (
Callable[...,FilesBackend]) – Callable(root,**kwargs) ->FilesBackendinstance.
- Return type:
- scitex.app.build_tree(backend, directory='', *, extensions=None, skip_hidden=True, max_depth=10)[source]
Build a nested tree structure from a FilesBackend.
- Parameters:
backend (
Any) – A file storage backend implementing the FilesBackend protocol.directory (
str) – Starting directory (relative to backend root). Default: root.extensions (
Optional[List[str]]) – Filter files by extension (e.g., [“.yaml”, “.png”]). Directories are always included for traversal.skip_hidden (
bool) – Skip files/directories starting with “.”. Default: True.max_depth (
int) – Maximum recursion depth to prevent runaway traversal. Default: 10.
- Returns:
Nested tree structure:
[ {"path": "subdir", "name": "subdir", "type": "directory", "children": [...]}, {"path": "file.yaml", "name": "file.yaml", "type": "file"}, ]
- Return type:
- scitex.app.hosts_to_allow(host)[source]
What a given
--hostbind implies for ALLOWED_HOSTS. Pure function.PUBLIC API, exported as
scitex_app.hosts_to_allow. It became public because it was about to be depended on privately: scitex-scholar and figrecipe each carried a verbatim copy of this function, and on the 0.10.1 release both were replacing their copy withfrom scitex_app._standalone import _hosts_to_allow— three repositories committing to an underscore path, which is a promise nobody made. Deciding the public name before the dependency exists is cheaper than deprecating an accidental one afterwards.That private alias is GONE as of 2026-09-04. It existed only for the migration window and was removed once both consumers had swapped, measured against their refs rather than their working trees. Import the public name.
Binding to an address IS the statement that you intend to be reached on it, so contribute it rather than making the caller set an env var to permit what they already asked for:
127.0.0.1 / localhost -> [] settings.py lists loopback 0.0.0.0 -> hostname + this machine’s interface addresses anything else -> [host]
The 0.0.0.0 rule is what makes DEBUG=False the safe default WITHOUT reintroducing the bug #126 fixed: a bind-all server receives requests whose Host header is the real interface address, and “0.0.0.0” in ALLOWED_HOSTS never matches that. Measured 2026-09-02 on the published 1.9.0 wheel: –host 0.0.0.0 with DJANGO_DEBUG=false answered 400 to every real address while loopback answered 200.
- scitex.app.read_file(path, *, root='.', binary=False)[source]
Read a single file via the resolved
FilesBackend.Equivalent to
get_files(root).read(path, binary=binary); mirrors theapp_read_fileMCP tool.
- scitex.app.write_file(path, content, *, root='.')[source]
Write a file via the resolved
FilesBackend.Mirrors the
app_write_fileMCP tool.- Return type:
- scitex.app.list_files(directory='', *, root='.', extensions=None)[source]
List file paths under directory.
Mirrors the
app_list_filesMCP tool.
- scitex.app.file_exists(path, *, root='.')[source]
Return whether path exists in the resolved backend.
Mirrors the
app_file_existsMCP tool.- Return type:
- scitex.app.delete_file(path, *, root='.')[source]
Delete path in the resolved backend.
Mirrors the
app_delete_fileMCP tool.- Return type:
- scitex.app.copy_file(src_path, dest_path, *, root='.')[source]
Copy src_path to dest_path within the resolved backend.
Mirrors the
app_copy_fileMCP tool.- Return type:
- scitex.app.rename_file(old_path, new_path, *, root='.')[source]
Rename old_path to new_path within the resolved backend.
Mirrors the
app_rename_fileMCP tool.- Return type:
- scitex.app.scaffold(target_dir='.', *, name=None, label=None, icon='fas fa-puzzle-piece', description='', frontend='html', overwrite=False)[source]
Generate a new SciTeX workspace app skeleton.
Mirrors the
app_scaffoldMCP tool. Auto-appends_app/-appto name (matching the MCP tool’s behaviour) so Python and MCP callers see the same result for the same inputs.