# Usage Guide


# Setting up

Install the package:

``` bash
pip install spice-kernel-db
```


## First-run configuration

On first use, the tool prompts you to configure where to store things:

    spice-kernel-db: First-time setup

      Database location [~/.local/share/spice-kernel-db/kernels.duckdb]:
      Kernel storage directory [~/.local/share/spice-kernel-db/kernels/]:

      Config saved to ~/.config/spice-kernel-db/config.toml

Your choices are saved to `~/.config/spice-kernel-db/config.toml`:

``` toml
[database]
path = "~/.local/share/spice-kernel-db/kernels.duckdb"

[storage]
kernel_dirs = ["~/.local/share/spice-kernel-db/kernels"]
```

`kernel_dirs` is the list of kernel roots; none is special. A download lands in the root that already holds its metakernel or its mission, and with one root there is nothing to decide. A file written by an older version, with a single `kernel_dir` line, still loads: it becomes a one-root list, and the next save rewrites it as `kernel_dirs`.

You can edit this file directly at any time. The `--db` CLI flag overrides the configured database path for a single command.


## Multi-machine setup with Dropbox

If you want to share kernel files across machines via Dropbox (or similar sync services), the recommended setup is:

- **Kernel files on Dropbox** -- they're write-once, read-many, safe for sync
- **Database local to each machine** -- DuckDB uses file locking that doesn't play well with sync services

``` toml
[database]
path = "~/.local/share/spice-kernel-db/kernels.duckdb"

[storage]
kernel_dirs = ["~/Dropbox/spice-kernels"]
```

After setting up a new machine, rebuild the index with `spice-kernel-db scan`, which scans every configured kernel root (here the Dropbox folder). The [get](../reference/get.md#spice_kernel_db.get) command downloads into the shared Dropbox folder, and kernels sync to other machines automatically.


## Adding a second kernel store

A second directory of kernels, such as planetarypy's store, becomes a second kernel root:

``` bash
skd config add-root ~/planetarypy_data/spice_kernels
skd scan
```

`config add-root` appends the directory to `kernel_dirs`. [scan](../reference/scan.md#spice_kernel_db.scan) with no argument then indexes every root, and `which`, [check](../reference/check.md#spice_kernel_db.check) and `dedup` see the files of both. A kernel that exists in both stores is recorded once and linked by `dedup`. `skd config remove-root <dir>` takes a root out of the list again and leaves its files and database rows alone. See [Several kernel roots](cli.md#several-kernel-roots) for the details.

From Python, `add_root(dir)` does the same without a prompt, and `ensure_config(seed_root=dir)` writes a first configuration with `dir` as its root when none exists yet.


## Python API

``` python
from rich.console import Console
from spice_kernel_db import KernelDB

db = KernelDB()                    # the configured database; prints nothing
db = KernelDB("/path/to/custom.duckdb")
db = KernelDB(console=Console())   # prints what the CLI prints
```

The library is quiet unless it is given a console, and it downloads only with `yes=True`. The Python snippets on this page show the calls; [Using skd from Python](python.md) walks through a whole session.


# Setting up a mission

The primary workflow begins with mission configuration. This tells the tool which SPICE server to use, which mission you're working with, and whether you want deduplication enabled for that mission.


## Interactive mission setup

``` bash
spice-kernel-db mission add
```

The interactive dialog walks you through:

1.  **Choose a server**: NASA NAIF or ESA SPICE

<!-- -->

    Available SPICE archive servers:

      [1] NASA NAIF  (https://naif.jpl.nasa.gov/pub/naif/)
      [2] ESA SPICE  (https://spiftp.esac.esa.int/data/SPICE/)

    Select server [1-2]:

2.  **Pick a mission**: The tool fetches the list of available missions from the selected server

<!-- -->

    Fetching missions from NASA NAIF...

    Available missions (157):

      [  1] CASSINI
      [  2] CLEMENTINE
      ...
      [ 45] JUICE
      [ 46] JUNO
      ...
      [157] VOYAGER2

    Select mission [1-157] or type name:

3.  **Configure deduplication**: Choose whether this mission's kernels can be deduplicated with symlinks

<!-- -->

    Enable deduplication for JUICE? [Y/n]:

After confirmation, the mission is registered:

    Mission 'JUICE' (NASA NAIF) configured.
      Deduplication: enabled
      mk/ directory: https://naif.jpl.nasa.gov/pub/naif/JUICE/kernels/mk/

    Next steps:
      spice-kernel-db browse JUICE
      spice-kernel-db get <metakernel>.tm --mission JUICE

Mission names are matched case-insensitively and support prefix matching, so you can type `browse ju` instead of `browse JUICE`, or `get juice_ops.tm --mission bepi` to match `BEPICOLOMBO`.


## Python API

``` python
from spice_kernel_db import KernelDB

db = KernelDB()

# Missions are stored with their server and mk/ directory URLs
db.add_mission(
    name="JUICE",
    server_url="https://naif.jpl.nasa.gov/pub/naif/",
    mk_dir_url="https://naif.jpl.nasa.gov/pub/naif/JUICE/kernels/mk/",
    dedup=True,
)
```


## Listing configured missions

``` bash
spice-kernel-db mission list
```

    Configured missions:

      Mission  Server  Dedup  mk/ URL
      ───────  ──────  ─────  ──────────────────────────────
      JUICE    NASA    yes    https://naif.jpl.nasa.gov/pub/naif/JUICE/kernels/mk/
      MRO      NASA    yes    https://naif.jpl.nasa.gov/pub/naif/MRO/kernels/mk/
      ROSETTA  ESA     no     https://spiftp.esac.esa.int/data/SPICE/ROSETTA/kernels/mk/


## Removing a mission

``` bash
spice-kernel-db mission remove JUICE
```

This removes the mission configuration from the database. It doesn't delete any downloaded kernel files.


# Browsing remote metakernels

Once you've configured a mission, you can browse the available metakernels on the remote server:

``` bash
spice-kernel-db browse JUICE
```

The tool fetches the listing of `.tm` files from the mission's `mk/` directory and groups them by base name (ignoring version tags like `_v461_20251127_001`):

    Remote metakernels: JUICE (https://spiftp.esac.esa.int/data/SPICE/JUICE/kernels/mk/)

      Metakernel              Versions  Latest           Local
      ──────────────────────  ────────  ──────────────── ────────
      juice_crema_5_1.tm            12  2024-11-27 09:30 yes
      juice_ops.tm                   8  2024-12-03 14:00 outdated
      juice_sci.tm                   5  2024-10-15 11:00 no
      juice_struct.tm                1  2024-01-10 08:00 no

      Total: 4 unique | 26 files | 1 locally acquired
      Run 'spice-kernel-db get <name>' to update outdated metakernels.
      Use --show-versioned to see individual snapshots.

- **Versions**: How many versioned snapshots exist (including the current version)
- **Latest**: Date of the most recent version
- **Local**: `yes` (up to date), `outdated` (remote copy is newer), or `no` (not acquired)


## Showing versioned snapshots

Use `--show-versioned` to see all versioned files:

``` bash
spice-kernel-db browse JUICE --show-versioned
```

    Remote metakernels: JUICE (https://naif.jpl.nasa.gov/pub/naif/JUICE/kernels/mk/)

      Metakernel                              Latest      Status
      ──────────────────────────────────────  ──────────  ──────
      juice_crema_5_1.tm                      2024-11-27  local
        juice_crema_5_1_v460_20241015_001.tm  2024-10-15  remote
        juice_crema_5_1_v461_20241127_001.tm  2024-11-27  remote
        (10 more versions...)
      juice_ops.tm                            2024-12-03  remote
        juice_ops_v42_20241130_001.tm         2024-11-30  remote
        juice_ops_v43_20241203_001.tm         2024-12-03  remote
        (6 more versions...)
      ...


## Python API

``` python
# the table appears only on a console: KernelDB(console=Console())
rows = db.browse_remote_metakernels(
    "https://naif.jpl.nasa.gov/pub/naif/JUICE/kernels/mk/",
    mission="JUICE",
    show_versioned=True,
)
```


# Acquiring a metakernel

This is the main workflow: point the tool at a remote metakernel and it automatically downloads all missing kernels, creates symlinks for kernels you already have, and makes the metakernel ready to use immediately.


## Using a metakernel filename

If you've configured the mission, you can use just the filename:

``` bash
spice-kernel-db get juice_ops.tm
```

The tool:

1.  Resolves the mission from your configured missions table
2.  Constructs the full URL using the stored `mk_dir_url`
3.  Fetches and parses the `.tm` file
4.  Resolves all kernel entries to full URLs
5.  Checks which kernels are already in your local database
6.  Queries file sizes for all kernels (parallel HTTP HEAD requests)
7.  Displays a summary table:

<!-- -->

    Fetching https://naif.jpl.nasa.gov/pub/naif/JUICE/kernels/mk/juice_ops.tm ...

    Metakernel: juice_ops.tm (42 kernels)

      Kernel                                    Size       Status
      ────────────────────────────────────────  ─────────  ────────
      naif0012.tls                                 5.2 KB  in db
      pck00011.tpc                               123.4 KB  in db
      de432s.bsp                                  31.2 MB  in db
      juice_sc_ops_v01.bc                         78.9 MB  missing
      juice_sa_ops_v01.bc                         12.3 MB  missing
      juice_orb_ops_v01.bsp                      156.7 MB  missing
      juice_step_240501.tsc                        1.2 KB  missing
      ...

      Total: 42 | In DB: 38 | Missing: 4 | Download: 248.9 MB

    Download 4 missing kernels (248.9 MB)? [y/N]:

If you confirm:

- Missing kernels are downloaded into your configured kernel storage directory
- The remote subdirectory structure is preserved (`lsk/`, `spk/`, `ck/`, etc.)
- Downloaded files are automatically registered in the database
- For kernels already in the database, symlinks are created so the metakernel works immediately
- The `.tm` file itself is saved locally and indexed

After acquisition, the metakernel is ready to use:

``` python
import spiceypy as spice

spice.furnsh("~/.local/share/spice-kernel-db/kernels/JUICE/mk/juice_ops.tm")
# All kernels load via local paths or symlinks
```


## Using a full URL

You can also provide a full URL (useful for one-off downloads or missions you haven't configured):

``` bash
spice-kernel-db get https://naif.jpl.nasa.gov/pub/naif/MRO/kernels/mk/mro_v16.tm --mission MRO
```


## Skipping the confirmation prompt

``` bash
spice-kernel-db get juice_ops.tm -y
```


## Python API

``` python
db.get_metakernel(
    "https://naif.jpl.nasa.gov/pub/naif/JUICE/kernels/mk/juice_ops.tm",
    mission="JUICE",
    yes=True,  # without a console there is nobody to ask, so this is required to download
)
```

Or with an explicit kernel root instead of the derived one:

``` python
db.get_metakernel(
    url,
    download_dir="/data/spice/juice",
    mission="JUICE",
    yes=True,
)
```

The one-call form is `get(url, yes=True)` from `spice_kernel_db`.


# Listing tracked metakernels


## List all fetched metakernels

``` bash
spice-kernel-db ls
```

                       Tracked metakernels
    ┏━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┓
    ┃ Mission ┃ Metakernel         ┃ Kernels ┃ Source            ┃
    ┡━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━┩
    │ JUICE   │ juice_ops.tm       │      42 │ naif.jpl.nasa.gov │
    │ JUICE   │ juice_crema_5_1.tm │     102 │ naif.jpl.nasa.gov │
    │ MRO     │ mro_v16.tm         │      31 │ naif.jpl.nasa.gov │
    └─────────┴────────────────────┴─────────┴───────────────────┘


## Show details for a specific metakernel

``` bash
spice-kernel-db show juice_ops.tm
```

    Metakernel: juice_ops.tm
      Mission:      JUICE
      Source:       https://naif.jpl.nasa.gov/pub/naif/JUICE/kernels/mk/juice_ops.tm
      Acquired:     2024-12-03 14:23:11.502892
      Local path:   ~/.local/share/spice-kernel-db/kernels/JUICE/mk/juice_ops.tm
    ┏━━━━━━━━━━━━━━┳━━━━━━┳━━━━━━━━━┳━━━━━━━━┓
    ┃ Kernel       ┃ Type ┃    Size ┃ Status ┃
    ┡━━━━━━━━━━━━━━╇━━━━━━╇━━━━━━━━━╇━━━━━━━━┩
    │ naif0012.tls │ lsk  │  5.2 KB │ in db  │
    │ de432s.bsp   │ spk  │ 31.2 MB │ in db  │
    │ ...          │      │         │        │
    └──────────────┴──────┴─────────┴────────┘

      Total: 42 | In DB: 42 | Missing: 0


## Filter by mission

``` bash
spice-kernel-db ls JUICE
```


## Python API

``` python
# List all: the rows come back; the table appears only on a console
rows = db.list_metakernels()

# Filter by mission
rows = db.list_metakernels(mission="JUICE")

# Details of one metakernel (printed on a console; the registry row is db.registry_row(name))
db.info_metakernel("juice_ops.tm")
```


# Listing kernels in a metakernel

The `show` command, given a tracked metakernel, prints the kernel table shown above. Given a `.tm` file that is not tracked, it lists every kernel the file loads, with the counts by type:

``` bash
spice-kernel-db show ~/spice/JUICE/mk/juice_ops.tm
```

    Metakernel: ~/spice/JUICE/mk/juice_ops.tm
    Kernels: 42 total
    (5 ck, 2 fk, 1 ik, 1 lsk, 3 pck, 1 sclk, 29 spk)

       #  Type  Kernel
      ──  ────  ──────────────────────────────────
       1  lsk   naif0012.tls
       2  pck   pck00011.tpc
       3  spk   de432s.bsp
       ...

    Not tracked; spice-kernel-db import ~/spice/JUICE/mk/juice_ops.tm tracks it.

Filter by kernel type:

``` bash
spice-kernel-db show juice_ops.tm --type spk
```

Without arguments, you'll be prompted to pick from locally acquired metakernels.


# Rewriting for local use

If you've already downloaded kernels from other sources (e.g., bulk downloads, manual copies), you can use `rewrite` to create a local metakernel that works with your existing files.

This is the core symlink-tree workflow. The tool creates:

1.  **A symlink tree** mirroring the original directory structure
2.  **A rewritten `.tm` file** with only `PATH_VALUES` changed


## Basic rewrite

``` bash
spice-kernel-db rewrite /data/spice/JUICE/kernels/mk/juice_crema_5_1.tm \
  -o /data/spice/local/juice_crema_5_1.tm \
  --mission JUICE
```

This produces:

**Symlink tree** at `/data/spice/local/kernels/`:

    /data/spice/local/kernels/
    ├── ck/
    │   └── juice_sc_default_v01.bc  →  /data/spice/JUICE/kernels/ck/juice_sc_default_v01.bc
    ├── lsk/
    │   └── naif0012.tls             →  ~/.local/share/spice-kernel-db/kernels/lsk/naif0012.tls
    ├── spk/
    │   └── jup365.bsp               →  /data/generic_kernels/spk/satellites/jup365.bsp
    └── ...

**Rewritten `.tm` file** with minimal edits:

``` diff
-  PATH_VALUES  = ( '..' )
+  PATH_VALUES  = ( '/data/spice/local/kernels' )
```

The `KERNELS_TO_LOAD` list is untouched. The header comments are preserved. You can `diff` the files to confirm.


## Custom symlink location

By default, symlinks are created in `kernels/` next to the output file. Use `--link-root` to change this:

``` bash
spice-kernel-db rewrite juice_crema_5_1.tm \
  -o ~/work/juice.tm \
  --link-root ~/work/my_kernels
```


## Python API

``` python
out_path, warnings = db.rewrite_metakernel(
    "/data/spice/JUICE/kernels/mk/juice_crema_5_1.tm",
    output="/data/spice/local/juice_crema_5_1.tm",
    mission="JUICE",
    link_root="/data/spice/local/kernels",  # optional
)

# Use the rewritten metakernel
import spiceypy as spice
spice.furnsh(out_path)
```


## How the symlink tree works

The tool:

1.  Parses the original metakernel to extract `KERNELS_TO_LOAD` entries
2.  For each kernel entry (e.g., `$KERNELS/lsk/naif0012.tls`):
    - Resolves the filename (`naif0012.tls`)
    - Queries the local database for the file (preferring the specified mission)
    - Creates a symlink at the expected relative path pointing to the actual file location
3.  Rewrites the metakernel with `PATH_VALUES` pointing to the symlink root

This preserves the original metakernel structure while bridging the gap between where files "should be" and where they actually live on disk. SPICE doesn't care that symlinks are used -- it just follows them.


# Resolving single kernels

To find where a specific kernel lives on disk:

``` bash
spice-kernel-db which naif0012.tls --mission JUICE
```

    /data/spice/JUICE/kernels/lsk/naif0012.tls

If the kernel isn't found in the preferred mission, the tool searches other missions:

``` bash
spice-kernel-db which mro_sc_2024.bc --mission JUICE
```

    /data/spice/MRO/kernels/ck/mro_sc_2024.bc
      ⚠ mro_sc_2024.bc: not found in [JUICE] registry, using copy from [MRO]

To resolve every kernel a metakernel loads, one `kernel<TAB>path` line each, pass `--metakernel`:

``` bash
spice-kernel-db which --metakernel juice_ops
```

When the kernel's content is known under more than one filename, `which` also prints the filenames and the on-disk locations after the path.


## Python API

``` python
path, warnings = db.resolve_kernel("naif0012.tls", preferred_mission="JUICE")
print(path)
# /data/spice/JUICE/kernels/lsk/naif0012.tls

path, warnings = db.resolve_kernel("mro_sc_2024.bc", preferred_mission="JUICE")
print(path)
# /data/spice/MRO/kernels/ck/mro_sc_2024.bc
print(warnings)
# ['mro_sc_2024.bc: not found in [JUICE] registry, using copy from [MRO]']
```


# Scanning existing kernel directories

If you have kernel files from other sources (manual downloads, old archives), you can register them in the database:

``` bash
spice-kernel-db scan /data/spice/generic_kernels --mission generic
```

The tool recursively finds all files with known SPICE kernel extensions (`.tls`, `.tpc`, `.bsp`, `.bc`, `.tf`, `.ti`, `.tsc`, `.bds`, `.tm`) and registers them:

    Scanning /data/spice/generic_kernels...
    Registered 847 kernel files.

    Database statistics:
      Unique kernels:   847
      Total locations:  847
      Unique content:   4.23 GB
      Missions:         generic

You can re-scan directories at any time. Existing files are updated (not duplicated) based on their SHA-256 hash and path. `spice-kernel-db scan` with no directory scans every configured kernel root.


## Auto-detecting mission names

The tool tries to guess the mission from the directory path:

``` bash
spice-kernel-db scan /data/spice/JUICE/kernels
```

This automatically detects `mission="JUICE"` and registers files under that mission.

Under a configured kernel root the mission is the first directory below the root, so `<root>/JUICE/mk/x.tm` is a JUICE file. A file directly in a root, or in a type directory such as `mk`, is classified from its filename alone. The directory name of the root itself is never taken as a mission. Before \#43 was fixed, the default store gave `SPICE-KERNEL-DB`.


## Archiving while scanning

The `--archive` flag moves scanned files into the kernel root that holds their mission (the only root, when there is one) and leaves symlinks in place:

``` bash
spice-kernel-db scan /data/downloads/kernels --archive --mission JUICE
```

This consolidates kernels from multiple sources into a central location without breaking existing references.


## Python API

``` python
# Scan with explicit mission labels
db.scan_directory("/data/spice/generic_kernels", mission="generic")
db.scan_directory("/data/spice/JUICE/kernels", mission="JUICE")

# Or let the tool guess the mission from the path
db.scan_directory("/data/spice/JUICE/kernels")  # auto-detects "JUICE"
```


# Statistics

Check database statistics at any time:

``` bash
spice-kernel-db stats
```

    ==================================================
    SPICE Kernel Database: ~/.local/share/spice-kernel-db/kernels.duckdb
    ==================================================
      Unique kernels:   1847
      Total locations:  2402
      Unique content:   12.34 GB
      Duplicated files: 127
      Missions:         JUICE, MRO, generic

      By type:
        spk       423 files    8234.1 MB
        ck        892 files    3102.5 MB
        pck        34 files     456.2 MB
        lsk        12 files       0.2 MB
        ...

The gap between "unique kernels" and "total locations" tells you how much duplication exists.


## Python API

``` python
db.stats()
```


# Finding and removing duplicates

Deduplication is **optional** and controlled per mission. The tool identifies identical kernel files across missions using SHA-256 hashing and can replace duplicates with symlinks.


## Per-mission deduplication control

When you configure a mission with `mission add`, you choose whether deduplication is enabled:

    Enable deduplication for JUICE? [Y/n]:

- **Dedup enabled** (`dedup=True`): Files in this mission can be replaced with symlinks during deduplication
- **Dedup disabled** (`dedup=False`): Files in this mission are **protected** and will never be touched

This gives you fine-grained control. For example:

- Enable dedup for `generic_kernels` (reference files, safe to symlink)
- Enable dedup for `JUICE` (active mission, willing to consolidate)
- Disable dedup for `MRO` (legacy archive, want to preserve original file structure)


## Viewing duplicates

The duplicate report is the second half of [stats](../reference/KernelDB.stats.md#spice_kernel_db.KernelDB.stats), after the database statistics:

``` bash
spice-kernel-db stats
```

    ╭────────────────────────── Duplicate kernels ──────────────────────────╮
    │ 127 files with 2+ copies                                              │
    │ Total wasted space: 2847.3 MB                                         │
    ╰───────────────────────────────────────────────────────────────────────╯

      de432s.bsp  (31.2 MB × 3 copies)
        [generic] /data/spice/generic_kernels/spk/planets/de432s.bsp
        [JUICE]   /data/spice/JUICE/kernels/spk/de432s.bsp
        [MRO]     /data/spice/MRO/kernels/spk/de432s.bsp

      jup365.bsp  (323.4 MB × 2 copies)
        [generic] /data/spice/generic_kernels/spk/satellites/jup365.bsp
        [JUICE]   /data/spice/JUICE/kernels/spk/jup365_19900101_20500101.bsp
      ...

Notice how `jup365.bsp` and `jup365_19900101_20500101.bsp` are correctly identified as the same file despite different names -- the tool uses SHA-256 content hashing.


## Preview deduplication (dry run)

``` bash
spice-kernel-db dedup
```

      WOULD replace /data/spice/JUICE/kernels/lsk/naif0012.tls
        -> symlink to /data/spice/generic_kernels/lsk/naif0012.tls
      WOULD replace /data/spice/JUICE/kernels/spk/de432s.bsp
        -> symlink to /data/spice/generic_kernels/spk/de432s.bsp

      PROTECTED: [MRO] has dedup=False, 43 duplicate files preserved

    Would save: 2847.3 MB

Files from missions with `dedup=False` are **never replaced**, even if duplicates exist elsewhere.


## Execute deduplication

When you're satisfied with the preview:

``` bash
spice-kernel-db dedup --execute
```

After deduplication, all paths still work -- they're just symlinks now. The database remains accurate. Metakernels continue to function normally since SPICE follows symlinks transparently.


## Python API

``` python
# Preview first (dry run)
db.deduplicate_with_symlinks(dry_run=True)

# Execute
db.deduplicate_with_symlinks(dry_run=False)
```


## Python API

``` python
dups = db.report_duplicates()
```


# Using the context manager

[KernelDB](../reference/KernelDB.md#spice_kernel_db.KernelDB) supports the context manager protocol:

``` python
with KernelDB() as db:
    count, missions = db.scan_directory("/data/spice/JUICE/kernels")
    dups = db.report_duplicates()   # a list; printed as a table only on a console
# connection is closed automatically
```


# Typical workflow

A typical session for a multi-mission researcher:


## 1. Set up missions

``` bash
spice-kernel-db mission add
# Choose NASA NAIF → JUICE → Enable deduplication

spice-kernel-db mission add
# Choose NASA NAIF → MRO → Disable deduplication (legacy archive)
```


## 2. Browse available metakernels

``` bash
spice-kernel-db browse JUICE
```


## 3. Acquire a metakernel

``` bash
spice-kernel-db get juice_ops.tm
```

This downloads missing kernels, creates symlinks for kernels you already have, and makes the metakernel ready to use immediately.


## 4. Use with spiceypy

``` python
import spiceypy as spice

spice.furnsh("~/.local/share/spice-kernel-db/kernels/JUICE/mk/juice_ops.tm")

# Now compute ephemerides, transformations, etc.
et = spice.utc2et("2024-12-03T00:00:00")
pos, lt = spice.spkpos("JUICE", et, "J2000", "NONE", "EARTH")
```


## 5. Optionally deduplicate

If you've acquired kernels from multiple missions and want to save space:

``` bash
spice-kernel-db dedup          # preview
spice-kernel-db dedup --execute  # execute
```

Missions with `dedup=False` are protected and their files are never touched.


## Python API example

``` python
from rich.console import Console
from spice_kernel_db import KernelDB

with KernelDB(console=Console()) as db:   # a console, so the tables below print
    # 1. Configure missions
    db.add_mission(
        "JUICE",
        "https://naif.jpl.nasa.gov/pub/naif/",
        "https://naif.jpl.nasa.gov/pub/naif/JUICE/kernels/mk/",
        dedup=True,
    )

    # 2. Browse remote metakernels
    db.browse_remote_metakernels(
        "https://naif.jpl.nasa.gov/pub/naif/JUICE/kernels/mk/",
        mission="JUICE",
    )

    # 3. Get a metakernel (with a console the download question is asked; yes=True skips it)
    db.get_metakernel(
        "https://naif.jpl.nasa.gov/pub/naif/JUICE/kernels/mk/juice_ops.tm",
        mission="JUICE",
        yes=True,
    )

    # 4. Optionally scan existing local kernels
    db.scan_directory("/data/spice/generic_kernels", mission="generic")

    # 5. Optionally deduplicate to save space
    db.deduplicate_with_symlinks(dry_run=False)
```


# Advanced: Multi-machine Dropbox setup

For researchers working across multiple machines, sharing kernel files via Dropbox while keeping databases local:

**Config on all machines** (`~/.config/spice-kernel-db/config.toml`):

``` toml
[database]
path = "~/.local/share/spice-kernel-db/kernels.duckdb"  # local

[storage]
kernel_dirs = ["~/Dropbox/spice-kernels"]  # shared
```

**Initial setup on machine 1**:

``` bash
spice-kernel-db mission add  # configure JUICE
spice-kernel-db get juice_ops.tm
# Kernels download to ~/Dropbox/spice-kernels/ and start syncing
```

**Setup on machine 2** (after Dropbox sync completes):

``` bash
spice-kernel-db mission add  # configure JUICE again (local database)
spice-kernel-db scan ~/Dropbox/spice-kernels
# Rebuilds the local database index from synced kernels
```

Both machines now share the kernel files but maintain independent database indices. When you [get](../reference/get.md#spice_kernel_db.get) on one machine, the kernels sync to the other automatically.
