Web Analytics

dbslice

⭐ 140 stars Japanese by nabroleonx

dbslice ロゴ

dbslice

PyPI バージョン ライセンス: MIT Python 3.10+

ローカル開発とデバッグのための最小限かつ参照整合性を保つデータベース部分集合を抽出します。

問題点

本番データベース全体を自分のマシンにコピーするのは現実的ではありません。しかし、バグを再現するには、そのバグを引き起こした正確なデータが必要なことが多いです。dbslice は必要なレコードだけを抽出し、外部キー関係をたどって参照整合性を保証することでこれを解決します。

dbslice — シードから部分集合へ

クイックスタート

# Install globally
uv tool install dbslice   # or: pip install dbslice

Extract an order and all related records

dbslice extract postgres://localhost/myapp --seed "orders.id=12345" > subset.sql

Import into local database

psql -d localdb < subset.sql

特徴

データベースサポート

| データベース | ステータス | |------------|-----------------------| | PostgreSQL | 完全対応 | | MySQL | 計画中(まだ実装されていません) | | SQLite | 計画中(まだ実装されていません) |

インストール

# Install with uv (recommended)
uv add dbslice

Try without installing

uvx dbslice --help

Or with pip

pip install dbslice

使用法

基本的な抽出

# Extract by primary key
dbslice extract postgres://user:pass@host:5432/db --seed "orders.id=12345"

Extract with WHERE clause

dbslice extract postgres://localhost/db --seed "orders:status='failed' AND created_at > '2024-01-01'"

Multiple seeds

dbslice extract postgres://localhost/db \ --seed "orders.id=100" \ --seed "orders.id=101"

コントロール・トラバーサル

# Limit depth (default: 3)
dbslice extract postgres://... --seed "orders.id=1" --depth 2

Direction: up (parents only), down (children only), both (default)

dbslice extract postgres://... --seed "orders.id=1" --direction up

匿名化

# Auto-anonymize detected sensitive fields
dbslice extract postgres://... --seed "users.id=1" --anonymize

Redact additional fields

dbslice extract postgres://... --seed "users.id=1" --anonymize --redact "audit_logs.ip_address"

カラムマッピングUI

カラムを視覚的にマッピングし、コンプライアンスプロファイルを適用し、すぐに使える設定を生成します — すべてローカルブラウザのUIから。

dbslice map postgres://localhost/myapp

Custom port

dbslice map postgres://localhost/myapp --port 8888

Also works with uvx (no install needed)

uvx dbslice map postgres://localhost/myapp
列を匿名化ルールにマッピング 設定を生成してエクスポート
列のマッピング 生成された設定

127.0.0.1:9473で動作し、一度限りのセッショントークンを使用 — データはマシンを離れません。GDPR、HIPAA、またはPCI-DSSプロファイルをワンクリックで適用し、マスクされる内容を確認してからYAMLをダウンロードしてください。

コンプライアンスプロファイル

# HIPAA Safe Harbor — auto-masks all 18 identifier types
dbslice extract postgres://... --seed "patients.id=1" --compliance hipaa --compliance-strict

Multiple profiles + audit manifest

dbslice extract postgres://... --seed "users.id=1" --compliance gdpr --compliance pci-dss -f subset.sql

Produces subset.sql + subset.manifest.json

出力形式

# SQL (default)
dbslice extract postgres://... --seed "orders.id=1" --output sql

JSON fixtures

dbslice extract postgres://... --seed "orders.id=1" --output json --out-file fixtures/

CSV

dbslice extract postgres://... --seed "orders.id=1" --output csv --out-file data/

仮想外部キー

データベーススキーマに定義されていないリレーションシップ(DjangoのGenericForeignKeys、暗黙のリレーションシップ)について:

# dbslice.yaml
database:
  url: postgres://localhost:5432/myapp

virtual_foreign_keys:

  • source_table: notifications
source_columns: [object_id] target_table: orders description: "Generic FK to orders via ContentType"

  • source_table: audit_log
source_columns: [user_id] target_table: users description: "Implicit FK without DB constraint"

dbslice extract --config dbslice.yaml --seed "users.id=1"

スキーマの検査

dbslice inspect postgres://localhost/myapp

設定ファイル

# Generate config from database
dbslice init postgres://localhost/myapp --out-file dbslice.yaml

Use config

dbslice extract --config dbslice.yaml --seed "orders.id=12345"

仕組み

比較

| 機能 | dbslice | Jailer | Greenmask | slice-db | |---------|---------|--------|-----------|----------| | 言語 | Python | Java | Go | Ruby | | 設定 | ゼロコンフィグ | モデルファイル必須 | 設定必須 | 手動YAML | | セットアップ時間 | 数秒 | 数時間 | 中程度 | 中程度 | | 匿名化 | 内蔵(Faker) | プラグインベース | 高度な変換器 | 利用不可 | | コンプライアンスプロファイル | GDPR, HIPAA, PCI-DSS | なし | なし | なし | | カラムマッピングUI | 内蔵(ローカル) | なし | なし | なし | | PII値スキャン | 二段階(マスク前後) | なし | なし | なし | | サブセット化 | 外部キー走査 | 外部キー走査 | 制限あり | 外部キー走査 | | 出力形式 | SQL, JSON, CSV | SQL, XML, CSV | SQL | SQLのみ | | 循環処理 | 自動 | 手動設定 | 該当なし | 手動 | | ストリーミング | 内蔵 | 設定可能 | 内蔵 | 利用不可 | | メンテナンス | 活発 | 活発 | 活発 | メンテナンス終了 |

dbslice は軽量でゼロコンフィグのPythonオプションです:インストールして1分以内に抽出できます。

開発

git clone https://github.com/nabroleonx/dbslice.git
cd dbslice
uv sync --dev
uv run pytest

License

MIT

--- Tranlated By Open Ai Tx | Last indexed: 2026-07-19 ---