Skip to main content

funshell

跨平台 shell 命令执行与端口/进程查杀工具。 核心由 Rust 实现,同时提供 零依赖 Python 库、独立原生命令行二进制 和 Rust 核心库 三种形态。

  • Linux 下端口查询直接读取 /proc/net/* 与 /proc/<pid>/fd,不依赖 lsof / ss / ps / kill,精简容器开箱即用;无结果时自动回退 lsof / ss。
  • 进程列表枚举基于原生系统接口,信号发送直接调用原生系统调用,支持 Linux / macOS / Windows。
  • Python 侧零运行时依赖,执行阻塞命令时自动释放 GIL。

安装

命令行是独立的原生二进制,不需要 Python 环境。

pip install funshell 只提供 Python API,不带 funshell 命令,避免与系统 PATH 冲突并减小 wheel 体积。

apt(Debian / Ubuntu)

curl -fsSL https://farfarfun.github.io/packages/farfarfun.gpg \
  | sudo tee /usr/share/keyrings/farfarfun.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/farfarfun.gpg] https://farfarfun.github.io/packages/deb stable main" \
  | sudo tee /etc/apt/sources.list.d/farfarfun.list
sudo apt update && sudo apt install funshell

Homebrew(macOS / Linux)

brew tap farfarfun/packages https://github.com/farfarfun/packages
brew trust farfarfun/packages
brew install funshell

cargo

cargo install funshell

裸二进制

从 Releases 下载对应平台的预编译包(Linux 优先 musl 静态版):

curl -fsSL https://github.com/farfarfun/funshell/releases/latest/download/funshell-x86_64-unknown-linux-musl.tar.gz \
  | tar -xz
sudo install -m 0755 funshell /usr/local/bin/

作为 Python 库

pip install funshell
# 或
uv add funshell

需要 Python 3.12 或更高版本,零运行时依赖,各平台提供预编译 abi3-py312 wheel。

作为 Rust 库

[dependencies]
funshell-core = "0.1"

命令行

# 查询占用 8080 端口的进程
funshell port 8080

# 查询并杀掉
funshell port 8080 --kill

# 按进程名(含任一关键字)查询
funshell name node code-server

# 按进程名查询并用指定信号杀掉
funshell name node --kill --sig TERM

# 执行 shell 命令(支持 --cwd / --timeout / --capture)
funshell run "echo hello world"
funshell run "git status" --cwd /path/to/repo --timeout 10 --capture

注意:name 子命令按完整命令行(含参数)做大小写不敏感子串匹配,终止前建议先不带 --kill 查看一遍匹配结果。

Python API

run_shell / run_shell_list

from funshell import run_shell, run_shell_list

# 实时输出到终端,返回退出码字符串
exit_code = run_shell("echo hello world")  # "0"

# 捕获 stdout 输出(去除首尾空白)
output = run_shell("echo hello world", printf=False)  # "hello world"

# 指定工作目录与超时(秒)
run_shell("git status", cwd="/path/to/repo", timeout=5)

# 依次执行多条命令(用 && 连接,前一条失败则终止)
output = run_shell_list(["echo hello", "echo world"], printf=False)
参数 类型 默认值 说明
command / command_list str / list[str] 必填 要执行的 shell 命令
printf bool True True 实时输出并返回退出码字符串;False 捕获 stdout
cwd str | PathLike | None None 工作目录
timeout float | None None 超时时间(秒),超时自动终止子进程并返回 "run shell error: command timed out"
encoding str "utf-8" 捕获输出时使用的字符编码

kill_process / ProcessFinder

from funshell import kill_process
from funshell.kill import ProcInfo, ProcessFinder

# 一步到位:按端口和/或进程名匹配并杀掉
kill_process(port=8080)
kill_process(name=("code-server",))
kill_process(port=3000, name=("node",), sig="TERM")

# 或先查询再决定是否终止
finder = ProcessFinder().find_by_port(8080)
for proc in finder:
    print(proc)  # pid=42 name=python port=8080 | python3 -m myserver
finder.kill(sig="TERM")

License

MIT


关于 farfarfun

farfarfun 是一个专注于实用工具库的开源组织, 涵盖云存储、数据处理、AI、多媒体与开发工具链等方向。

本项目基于 MIT 协议开源。

Metadata

Release files for funshell 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for funshell 2.0.0
File Size Uploaded Provenance Actions
funshell-2.0.0.tar.gz 23.2 kB Without provenance Details for funshell-2.0.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for funshell 2.0.0
File Actions
funshell-2.0.0-cp312-abi3-win_amd64.whl CPython 3.12 abi3 Windows x86-64 Details for funshell-2.0.0-cp312-abi3-win_amd64.whl
funshell-2.0.0-cp312-abi3-musllinux_1_2_x86_64.whl CPython 3.12 abi3 Linux musl 1.2+ x86-64 Details for funshell-2.0.0-cp312-abi3-musllinux_1_2_x86_64.whl
funshell-2.0.0-cp312-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.12 abi3 Linux glibc 2.17+ x86-64 Details for funshell-2.0.0-cp312-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
funshell-2.0.0-cp312-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.12 abi3 Linux glibc 2.17+ ARM64 Details for funshell-2.0.0-cp312-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
funshell-2.0.0-cp312-abi3-macosx_11_0_arm64.whl CPython 3.12 abi3 macOS 11.0+ ARM64 Details for funshell-2.0.0-cp312-abi3-macosx_11_0_arm64.whl
funshell-2.0.0-cp312-abi3-macosx_10_12_x86_64.whl CPython 3.12 abi3 macOS 10.12+ x86-64 Details for funshell-2.0.0-cp312-abi3-macosx_10_12_x86_64.whl

Total release size: 3.1 MB

Release files / funshell-2.0.0.tar.gz

Download URL funshell-2.0.0.tar.gz
Size 23.2 kB
Tags Source
SHA-256 checksum
How to use checksums
a8fc075529a585ad4c53726c8b16a94ae495beac52bf3a28b83cd15ab87fb24b
BLAKE2b-256 checksum
How to use checksums
c81d6127b6b80a82e9cb48ff46a409ccfb0edb3ef43bccb603eb8f70df2ce7f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / funshell-2.0.0-cp312-abi3-win_amd64.whl

Download URL funshell-2.0.0-cp312-abi3-win_amd64.whl
Size 416.3 kB
Tags CPython 3.12 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
e0173516cf93a048c13c96e171c1e87127e64df7066c76788615bc873e85f6d5
BLAKE2b-256 checksum
How to use checksums
8c38da56a19c3a4971d7f9160a70125c6267c5d76a474a8445fe560b0b908d53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / funshell-2.0.0-cp312-abi3-musllinux_1_2_x86_64.whl

Download URL funshell-2.0.0-cp312-abi3-musllinux_1_2_x86_64.whl
Size 746.4 kB
Tags CPython 3.12 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
a67a586cc8110eff3f6971154ec0904668915e64a226314be51d04edd94ba352
BLAKE2b-256 checksum
How to use checksums
35b0582771ab70db18be70c06373b7696c1bb342b14c47df8bf7c541efd93759
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / funshell-2.0.0-cp312-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL funshell-2.0.0-cp312-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 534.6 kB
Tags CPython 3.12 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
cd17c62059472641f98e884e149175dd8eb16a9f8ced222f340902bac829bc29
BLAKE2b-256 checksum
How to use checksums
2f21e4793df64e31335e6c054954d49ef0dd18216b0d790de2ad5cdf4efae5ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / funshell-2.0.0-cp312-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL funshell-2.0.0-cp312-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 512.2 kB
Tags CPython 3.12 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
d70a04575555365a5899c431750cb40d19227976b1d1abfffab6e33cac5c9491
BLAKE2b-256 checksum
How to use checksums
a127b11646b0f4afce26689618bb479281f41d5cf905038f207156c21b70baa2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / funshell-2.0.0-cp312-abi3-macosx_11_0_arm64.whl

Download URL funshell-2.0.0-cp312-abi3-macosx_11_0_arm64.whl
Size 444.8 kB
Tags CPython 3.12 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
2fe63716ac936fec483a87595df7948dda2bc68453d764242834908d131683ef
BLAKE2b-256 checksum
How to use checksums
68aadfcc1227557fd248dc23cbf6aa920dab91cb4fb33aa5d9f1dc05c7fe6fb4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / funshell-2.0.0-cp312-abi3-macosx_10_12_x86_64.whl

Download URL funshell-2.0.0-cp312-abi3-macosx_10_12_x86_64.whl
Size 463.0 kB
Tags CPython 3.12 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
62fb4d96e85ba4ad2f6b8d2838fee66fa2d5604bffeb26531fc6f55fc45145ff
BLAKE2b-256 checksum
How to use checksums
d0a876b7667a282db537ed543ebacefcecf4b432e727b2f2582a1ed6965e1011
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for funshell 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page