Metadata-Version: 2.5
Name: atmovault-client
Version: 0.2.0
Summary: Client library, command line and local HTTP gateway for Atmovault, end-to-end encrypted file storage
Project-URL: Homepage, https://atmovault.app
Project-URL: Documentation, https://atmovault.app/docs/index.html
Project-URL: Repository, https://github.com/hb1dys/atmovault-client
Author: Aleksandar Ivanov Ivanov
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: atmovault,encryption,end-to-end,storage,zero-knowledge
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Security :: Cryptography
Classifier: Topic :: System :: Archiving
Requires-Python: >=3.11
Requires-Dist: cryptography>=44.0
Requires-Dist: httpx>=0.28
Provides-Extra: gateway
Requires-Dist: fastapi>=0.115; extra == 'gateway'
Requires-Dist: uvicorn>=0.34; extra == 'gateway'
Description-Content-Type: text/markdown

# atmovault-client

Read and write files in an [Atmovault](https://atmovault.app) vault from your own program.

Atmovault is end-to-end encrypted file storage: files are encrypted before they leave the
machine, so the server stores ciphertext and never sees a file's contents or its name.
That means a program cannot simply call a REST API on the server and get a document
back. Something on your side has to hold the key and do the encryption. This package is
that something, in three forms:

- **A gateway.** A small HTTP server you run next to your program. Your code makes plain
  HTTP requests to `127.0.0.1`, in any language, and the gateway encrypts and decrypts.
- **A Python library**, if your program is written in Python.
- **A command line**, `atmovault-service`, for scripts and for trying things out.

All three use the same code and the same API key.

```
your program  --plain HTTP-->  gateway (your machine)  --ciphertext-->  Atmovault
```

## Contents

- [Getting a key](#getting-a-key)
- [Install](#install)
- [Quickstart](#quickstart)
- [HTTP API](#http-api)
- [Command line](#command-line)
- [Python library](#python-library)
- [Configuration](#configuration)
- [Security](#security)
- [Development](#development)
- [License](#license)

## Getting a key

The owner of the vault makes one in **Settings -> Services -> New API key**. They pick a
folder, choose **View** (read only) or **Edit** (add, rename, move, trash), and set an
end date. The key is shown once:

```
atmv1_...   (156 characters)
```

A key reaches only the folder it was made for. Nothing a key does is permanent: what it
deletes goes to the owner's trash, what it replaces keeps its old version, and the owner
sees everything it did, with Undo.

## Install

Python 3.11 or newer. The package is [on PyPI](https://pypi.org/project/atmovault-client/).

```
pip install "atmovault-client[gateway]"
```

Leave out `[gateway]` if you only want the library and the command line. That drops
FastAPI and uvicorn and leaves two dependencies, `cryptography` and `httpx`.

Or build the gateway as a container:

```
docker build -t atmovault-gateway https://github.com/hb1dys/atmovault-client.git
docker run -d --name atmovault-gateway \
  -p 127.0.0.1:8200:8200 \
  -v atmovault-state:/state \
  atmovault-gateway
```

## Quickstart

Put the key in the environment, never in your code or your repository:

```
export ATMOVAULT_API_KEY=atmv1_...
```

Start the gateway:

```
atmovault-service serve
```

Upload a file into the folder the key was made for, here called `Finance`:

```
curl -T invoice.pdf -H "Authorization: Bearer $ATMOVAULT_API_KEY" \
  http://127.0.0.1:8200/v1/files/Finance/invoice.pdf
```

List the folder:

```
curl -H "Authorization: Bearer $ATMOVAULT_API_KEY" http://127.0.0.1:8200/v1/list/Finance
```

Download the file:

```
curl -o invoice.pdf -H "Authorization: Bearer $ATMOVAULT_API_KEY" \
  http://127.0.0.1:8200/v1/files/Finance/invoice.pdf
```

The same three calls from PHP, Node, Go or anything else are ordinary HTTP requests with
one header.

## HTTP API

Base URL `http://127.0.0.1:8200`. Every request except `/healthz` carries
`Authorization: Bearer <key>`. A path starts at the name of the key's folder.

| Method and path | Needs | What it does |
|---|---|---|
| `GET /healthz` | nothing | `{"ok": true}` when the gateway is up |
| `GET /v1` | any key | Checks the key and lists the folders it reaches |
| `GET /v1/list/<path>` | View | What is in a folder. `?limit=`, `?offset=` |
| `GET /v1/meta/<path>` | View | One file or folder, without its bytes |
| `GET /v1/files/<path>` | View | A file's bytes. `?download=1`, `Range` |
| `PUT /v1/files/<path>` | Edit | Upload the request body. `?replace=true` adds a version |
| `POST /v1/folders/<path>` | Edit | Make a folder |
| `POST /v1/move` | Edit | Rename or move: `{"from": "<path>", "to": "<path>"}` |
| `DELETE /v1/files/<path>` | Edit | Move a file or folder to the owner's trash |
| `GET /v1/versions/<path>` | Edit | Every version a file has had, newest first |

Errors always look the same, with a `code` to match on:

```json
{"error": {"code": "not_found", "message": "nothing called 'a.pdf' here"}}
```

The full reference, with the item format, every error code and the limits, is in
[docs/api.md](src/atmovault_client/docs/api.md). A running gateway serves the same pages
at `/docs` and an OpenAPI description at `/openapi.json`.

## Command line

```
atmovault-service ls                             the folders this key reaches
atmovault-service ls Finance                     what is in a folder
atmovault-service get Finance/invoice.pdf        download and decrypt
atmovault-service put scan.pdf Finance           encrypt and upload
atmovault-service put scan.pdf Finance --replace a new version of Finance/scan.pdf
atmovault-service mkdir Finance/2026
atmovault-service rename Finance/scan.pdf invoice.pdf
atmovault-service mv Finance/invoice.pdf Finance/2026
atmovault-service rm Finance/old.txt             to the owner's trash
atmovault-service serve                          run the gateway
```

Any part of a path can be an item's id instead of its name. Two items in one folder can
share a name, because the server never sees names, and the id is how you tell them apart.

## Python library

```python
import os
from atmovault_client import connect

key = os.environ["ATMOVAULT_API_KEY"]

with connect("https://atmovault.app/api", key, "atmovault-state") as vault:
    finance = vault.find("Finance")

    for item in vault.children(finance):
        print(item.path, item.size)

    with open("invoice.pdf", "rb") as f:
        vault.upload(finance, "invoice.pdf", f, "application/pdf")

    data = vault.read(vault.find("Finance/invoice.pdf"))
```

| Method | |
|---|---|
| `grants()` | the folders the key reaches |
| `find(path)` | an item by path |
| `children(folder)`, `walk(folder)` | what is in a folder, or everything beneath it |
| `read(file)`, `read_into(file, out)`, `read_chunks(file)` | a file's bytes, whole or a chunk at a time |
| `upload(folder, name, data, mime)` | add a file; `data` is bytes or an open binary file |
| `new_version(file, data)` | replace a file's bytes, keeping the old ones in its history |
| `mkdir(folder, name)`, `rename(item, name)`, `move(item, folder)`, `trash(item)` | |
| `versions(file)` | a file's history |

Large files are read and written 4 MiB at a time, so memory use stays flat. An upload
resumes by itself if the connection drops.

Exceptions: `ApiError` (the server refused; it has `status` and `detail`), `Untrusted`
(a folder the owner did not sign over to this key), `KeyOutOfDate` (the owner changed
their password; ask for a new key), `Ambiguous` (two items share that name) and
`DecryptError`.

## Configuration

| Option | Environment | Default | |
|---|---|---|---|
| | `ATMOVAULT_API_KEY` | | the key, for the command line. The gateway takes it per request |
| `--url` | `ATMOVAULT_URL` | `https://atmovault.app/api` | the vault's API root |
| `--state` | `ATMOVAULT_STATE` | `atmovault-state` | the state folder, see below |
| `serve --host` | | `127.0.0.1` | where the gateway listens |
| `serve --port` | | `8200` | |

**The state folder** holds one small file per key: the newest key version seen of each
folder and the newest version written of each file. That is what lets the client notice
a server replaying something old. It contains no key and nothing readable. Keep it on
storage that survives a restart (a Docker volume, not the container's own filesystem)
and writable only by the user the program runs as.

More on running it in production: [docs/running.md](src/atmovault_client/docs/running.md).

## Security

The short version. The long one is in
[docs/security.md](src/atmovault_client/docs/security.md).

- **The API key is a private key.** It carries the token the server knows your program
  by and the private key that opens the folder. Only the token is ever sent to the
  server. Whoever has the string can read the folder, so keep it in the environment of
  the one process that needs it.
- **The server is not trusted to say what the key may open.** A folder is used only if
  the vault's owner signed it over to this key, and the client checks that signature
  before reading or writing anything.
- **After the owner changes their password, the key stops working** and the client says
  so. The owner issues a replacement with one click.
- **The gateway listens on `127.0.0.1` and speaks plain HTTP.** Do not expose it. It
  keeps no key on disk and writes no request log, because a path is a decrypted name.
- **Treat what you read as untrusted input.** File names, types and contents are
  whatever the writer put there. Do not build a path, a shell command or an HTML page
  from them without checking.
- `https://` only. A plain `http://` vault address is refused unless it is this machine
  or you pass `--allow-http`, and redirects are never followed.

Found a vulnerability? Please report it privately, as described at
<https://atmovault.app/security.html>, rather than in a public issue.

## Development

```
git clone https://github.com/hb1dys/atmovault-client
cd atmovault-client
uv sync
uv run pytest -q
uv run ruff check . && uv run ruff format --check . && uv run mypy
```

The tests need no network and no vault. `tests/conftest.py` is a fake server, including
one that forges grants and signatures the way a hostile server could. `tests/fixtures`
holds known-answer vectors shared with the Atmovault web app, so the two implementations
are held to the same bytes.

Issues and pull requests are welcome. The encrypted format is fixed by those vectors and
by files people have already stored, so a change to it is not something a pull request
can make on its own.

## License

[Apache License 2.0](LICENSE). It covers this client and gateway. The Atmovault server
and web app are not open source.
