应用管理器客户端

App Manager Client

Provides API for managing application containers: - Install, start, stop, uninstall applications - Get application info and stats - Stream application logs

class neoruntime_ipc_sdk.app.AppInfo(id, name, version, state, container_id, pid, installed_at, started_at, stopped_at, restart_count, manifest_path, instance_path)[source]

Bases: object

Application information

id: str
name: str
version: str
state: str
container_id: str
pid: int
installed_at: int
started_at: int
stopped_at: int
restart_count: int
manifest_path: str
instance_path: str
__init__(id, name, version, state, container_id, pid, installed_at, started_at, stopped_at, restart_count, manifest_path, instance_path)
class neoruntime_ipc_sdk.app.AppStats(app_id, cpu_usage_percent, memory_usage_bytes, memory_limit_bytes, thread_count, uptime_seconds)[source]

Bases: object

Application runtime statistics

app_id: str
cpu_usage_percent: float
memory_usage_bytes: int
memory_limit_bytes: int
thread_count: int
uptime_seconds: int
__init__(app_id, cpu_usage_percent, memory_usage_bytes, memory_limit_bytes, thread_count, uptime_seconds)
class neoruntime_ipc_sdk.app.LogLine(timestamp, level, message)[source]

Bases: object

Single log line

timestamp: int
level: str
message: str
property datetime: datetime

Convert timestamp to datetime

__init__(timestamp, level, message)
class neoruntime_ipc_sdk.app.AppClient(endpoint=None)[source]

Bases: GrpcClient

Application Container Management Client

Usage:

app_client = AppClient()

# List all apps
apps = app_client.list_apps()
for app in apps:
    print(f"{app.name}: {app.state}")

# Get logs (last 100 lines)
for line in app_client.get_logs("my_app", max_lines=100):
    print(line)

# Follow logs in real-time
for line in app_client.get_logs("my_app", follow=True):
    print(line)
register_web_url(path='/')[source]

Register a web access path for this app.

After calling this method, the web console will show a “Visit App” button linking to http://{device_ip}:{inbound_port}{path}.

Requires the APP_ID environment variable to be set (injected automatically by the platform when the container starts).

Parameters:

path (str) – Web page path, default "/"

install_app(manifest_path, image_path)[source]

Install an application from manifest and image

Parameters:
  • manifest_path (str) – Path to app.yaml

  • image_path (str) – Path to container image tar

Returns:

app_id of installed application

Return type:

str

start_app(app_id)[source]

Start a stopped application

stop_app(app_id, timeout_seconds=30)[source]

Stop a running application

uninstall_app(app_id, keep_logs=True)[source]

Uninstall an application

restart_app(app_id, timeout_seconds=30)[source]

Restart a running application (stop + start).

This is a composite operation since the gRPC service does not expose a dedicated RestartApp RPC. It stops the app and then starts it again.

Parameters:
  • app_id (str) – Application ID

  • timeout_seconds (int) – Seconds to wait for the app to stop (default: 30)

list_apps()[source]

List all installed applications

get_app(app_id)[source]

Get application information

get_app_stats(app_id)[source]

Get application runtime statistics

get_logs(app_id, max_lines=100, follow=False)[source]

Get application logs

Parameters:
  • app_id (str) – Application ID

  • max_lines (int) – Maximum number of lines to return (default: 100)

  • follow (bool) – If True, stream logs continuously (default: False)

Yields:

LogLine objects

Examples

# Get last 100 lines
for line in app_client.get_logs("my_app", max_lines=100):
    print(line)

# Follow logs in real-time
for line in app_client.get_logs("my_app", follow=True):
    print(line)
get_logs_text(app_id, max_lines=100, follow=False)[source]

Get application logs as text lines

Parameters:
  • app_id (str) – Application ID

  • max_lines (int) – Maximum number of lines to return (default: 100)

  • follow (bool) – If True, stream logs continuously (default: False)

Yields:

Formatted log strings

Examples

# Print logs
for line in app_client.get_logs_text("my_app"):
    print(line)

使用示例

应用生命周期管理

from neoruntime_ipc_sdk import AppClient

app = AppClient()

# 列出所有应用
apps = app.list_apps()
for a in apps:
    print(f"{a.name}: {a.state}")

# 安装应用
app_id = app.install_app(
    manifest_path="/data/apps/my_app/app.yaml",
    image_path="/data/apps/my_app/image.tar"
)

# 启动应用
app.start_app(app_id)

# 重启应用(停止+启动)
app.restart_app(app_id, timeout_seconds=30)

# 停止应用
app.stop_app(app_id)

# 卸载应用
app.uninstall_app(app_id, keep_logs=True)

获取应用信息

# 获取应用详情
info = app.get_app("my_app")
print(f"名称: {info.name}")
print(f"版本: {info.version}")
print(f"状态: {info.state}")

# 获取应用统计
stats = app.get_app_stats("my_app")
print(f"CPU: {stats.cpu_usage_percent}%")
print(f"内存: {stats.memory_usage_bytes / 1024 / 1024:.1f} MB")

查看应用日志

# 获取最近 100 行日志
for line in app.get_logs("my_app", max_lines=100):
    print(line)

# 实时跟踪日志
for line in app.get_logs("my_app", follow=True):
    print(line)

# 获取文本格式日志
for text in app.get_logs_text("my_app"):
    print(text)

注册 Web 访问路径

# 在应用容器内注册 Web 访问路径
# 需要环境变量 APP_ID(平台自动注入)
app.register_web_url("/")

# 注册自定义路径
app.register_web_url("/dashboard")

上下文管理器

with AppClient() as app:
    apps = app.list_apps()
    for a in apps:
        print(f"{a.name}: {a.state}")