Skip to main content

funsecret

funsecret 是一个简单的本地密钥管理工具。

适合存这些内容:

  • 账号密码
  • token / access key
  • 数据库连接信息
  • 其他不想写进代码里的敏感配置

它默认把数据保存在本机,按多级分类读取,例如 app prod mysql password。

安装

pip install funsecret

如果你要同步到 MySQL:

pip install "funsecret[mysql]"

如果你修改了本仓库源码并希望本地直接使用命令:

pip install -e .

命令行快速开始

写入一个 secret:

funsecret write my-password app prod mysql password

读取一个 secret:

funsecret read app prod mysql password

查看有哪些 key,只显示路径,不显示 value:

funsecret list

查看当前存储信息:

funsecret info

清空当前本地 secret:

funsecret clear

跳过确认直接清空:

funsecret clear --yes

命令说明

write

funsecret write VALUE CATE1 CATE2 [CATE3] [CATE4] [CATE5]

示例:

funsecret write sk-xxxxx openai prod api_key
funsecret write root123 mysql local root password

read

funsecret read CATE1 CATE2 [CATE3] [CATE4] [CATE5]

示例:

funsecret read openai prod api_key
funsecret read mysql local root password

list

funsecret list

输出示例:

openai prod api_key
mysql local root password

注意:list 不会输出 secret value。

info

funsecret info

输出示例:

backend: sqlite
database_url: sqlite:////Users/you/.secret/.funsecret.db
database_file: /Users/you/.secret/.funsecret.db
secret_count: 2
cipher_key_configured: yes
mysql_example_url: mysql+pymysql://username:password@127.0.0.1:3306/funsecret

save

把当前本地 secret 保存到一个数据库。

funsecret save DB_URL

保存到 MySQL:

funsecret save mysql+pymysql://username:password@127.0.0.1:3306/funsecret

如果传了 --cipher-key,写入目标库时会加密:

funsecret save mysql+pymysql://username:password@127.0.0.1:3306/funsecret --cipher-key my-secret-key

如果不传 --cipher-key,保存到目标库时不加密。

load

从一个数据库加载 secret 到当前本地库。

funsecret load DB_URL

从 MySQL 加载:

funsecret load mysql+pymysql://username:password@127.0.0.1:3306/funsecret

如果源库里的数据是加密的,可以传 --cipher-key:

funsecret load mysql+pymysql://username:password@127.0.0.1:3306/funsecret --cipher-key my-secret-key

如果不传 --cipher-key,默认按未加密数据读取。

Python 用法

写入:

from funsecret import write_secret

write_secret("my-password", "app", "prod", "mysql", "password")
write_secret("sk-xxxxx", "openai", "prod", "api_key")

读取:

from funsecret import read_secret

password = read_secret("app", "prod", "mysql", "password")
api_key = read_secret("openai", "prod", "api_key")

也可以用 read_secret(..., value=...) 直接写入:

from funsecret import read_secret

read_secret("app", "prod", "mysql", "password", value="my-password")

默认存储位置

默认使用本地 sqlite:

~/.secret/.funsecret.db

也可以通过环境变量控制:

  • FUN_SECRET_PATH:本地 secret 目录
  • FUN_SECRET_URL:直接指定数据库 URL

快照扩展

快照功能需要单独安装:

pip install "funsecret-snapshot" "fundrive[dropbox]"

设置 Dropbox access token:

export DROPBOX_ACCESS_TOKEN="your-dropbox-access-token"

保存或读取快照:

import os

from fundrive.drives.dropbox import DropboxDrive
from funsecret.snapshot import load_snapshot, save_snapshot

drive = DropboxDrive()
if not drive.login(access_token=os.environ["DROPBOX_ACCESS_TOKEN"]):
    raise RuntimeError("Dropbox login failed")

table_fid = "/funsecret-snapshots"
if not drive.exist(table_fid):
    drive.mkdir("", "funsecret-snapshots")

save_snapshot(table_fid=table_fid, drive=drive)
load_snapshot(table_fid=table_fid, drive=drive)

table_fid 是保存快照的云盘目录 ID;其他 fundrive 驱动也可替换 DropboxDrive,具体认证方式参见 fundrive 文档。


关于 farfarfun

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

本项目基于 MIT 协议开源。

Metadata

Release files for funsecret 1.4.99

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

Built distribution (wheel)

Table of built distributions (wheels) for funsecret 1.4.99
File Interpreter ABI Platform Actions
funsecret-1.4.99-py3-none-any.whl Python 3 none any Details for funsecret-1.4.99-py3-none-any.whl

Release files / funsecret-1.4.99-py3-none-any.whl

Download URL funsecret-1.4.99-py3-none-any.whl
Size 13.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d065439d7f2e5cb1b19d317c019b261b70b1712250db870f69e7f133785da34b
BLAKE2b-256 checksum
How to use checksums
2c0e0e69571fe539a24046ba855c02e0d522aab871cc2c9cae75f82dfd239485
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","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":null}

Security for funsecret 1.4.99

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.

Release history Release notifications | RSS feed

This release

1.4.99 This release

1 release file No provenance

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