Skip to main content

nltsecret

Project description

nltsecret

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

适合存这些内容:

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

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

安装

pip install nltsecret

如果你要同步到 MySQL:

pip install "nltsecret[mysql]"

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

pip install -e .

命令行快速开始

写入一个 secret:

nltsecret write my-password app prod mysql password

读取一个 secret:

nltsecret read app prod mysql password

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

nltsecret list

查看当前存储信息:

nltsecret info

清空当前本地 secret:

nltsecret clear

跳过确认直接清空:

nltsecret clear --yes

命令说明

write

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

示例:

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

read

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

示例:

nltsecret read openai prod api_key
nltsecret read mysql local root password

list

nltsecret list

输出示例:

openai prod api_key
mysql local root password

注意:list 不会输出 secret value。

info

nltsecret info

输出示例:

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

save

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

nltsecret save DB_URL

保存到 MySQL:

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

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

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

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

load

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

nltsecret load DB_URL

从 MySQL 加载:

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

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

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

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

Python 用法

写入:

from nltsecret import write_secret

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

读取:

from nltsecret import read_secret

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

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

from nltsecret import read_secret

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

默认存储位置

默认使用本地 sqlite:

~/.secret/.nltsecret.db

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

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

快照扩展

快照功能需要单独安装:

pip install nltsecret_snapshot

保存快照:

from nltsecret_snapshot import save_snapshot

save_snapshot(bin_id, cipher_key, security_key)

读取快照:

from nltsecret_snapshot import load_snapshot

load_snapshot(bin_id, cipher_key, security_key)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nltsecret-1.4.82-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file nltsecret-1.4.82-py3-none-any.whl.

File metadata

  • Download URL: nltsecret-1.4.82-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for nltsecret-1.4.82-py3-none-any.whl
Algorithm Hash digest
SHA256 0bfe666e8a0947e49f267bb8ad71bc8f6da0099e6fd4c7f7c3d32e63b0c438f2
MD5 f44e1029184a897c41ac8bb438a33c2e
BLAKE2b-256 9280ab4b610525a0d500f6212ba2df24ed07aa62f10dbc976ea77d2f94124f2e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page