2016-05-29 19:00:21 -04:00
|
|
|
# pass2csv
|
2020-06-08 02:16:58 -04:00
|
|
|
|
2023-01-04 06:13:22 -05:00
|
|
|
pass2csv is a tool that exports a
|
|
|
|
[pass(1)](https://www.passwordstore.org/) password store to a CSV. It
|
|
|
|
can export whole stores, subdirectories of a store, and single password
|
|
|
|
files. It can use regexp patterns to find and group data after the first
|
|
|
|
line of each password into additional CSV columns, as well as exclude
|
|
|
|
data from the export.
|
2020-06-08 02:16:58 -04:00
|
|
|
|
2023-01-04 06:13:22 -05:00
|
|
|
Source is available [at GitHub](https://github.com/reinefjord/pass2csv),
|
|
|
|
and the package is published to the
|
|
|
|
[Python Package Index](https://pypi.org/project/pass2csv/).
|
|
|
|
|
|
|
|
You can install the package with [pipx](https://pypa.github.io/pipx/)
|
|
|
|
(recommended):
|
|
|
|
|
|
|
|
pipx install pass2csv
|
|
|
|
|
|
|
|
or with pip:
|
2020-08-08 12:02:27 -04:00
|
|
|
|
|
|
|
python3 -m pip install --user pass2csv
|
|
|
|
|
2016-05-30 05:31:00 -04:00
|
|
|
|
2020-06-07 16:39:28 -04:00
|
|
|
## Usage
|
|
|
|
|
|
|
|
```
|
|
|
|
$ pass2csv --help
|
2024-01-17 06:47:38 -05:00
|
|
|
usage: pass2csv [-h] [-b path] [-g executable] [-a]
|
|
|
|
[--encodings encodings] [-e pattern] [-f name pattern]
|
|
|
|
[-l name pattern] [--version]
|
2022-11-15 15:29:55 -05:00
|
|
|
STOREPATH OUTFILE
|
2020-06-07 16:39:28 -04:00
|
|
|
|
|
|
|
positional arguments:
|
2022-11-15 15:29:55 -05:00
|
|
|
STOREPATH path to the password-store to export
|
|
|
|
OUTFILE file to write exported data to, use - for stdout
|
2020-06-07 16:39:28 -04:00
|
|
|
|
2022-11-15 15:29:55 -05:00
|
|
|
options:
|
2020-06-07 16:39:28 -04:00
|
|
|
-h, --help show this help message and exit
|
2021-05-19 15:30:10 -04:00
|
|
|
-b path, --base path path to use as base for grouping passwords
|
|
|
|
-g executable, --gpg executable
|
2024-01-17 06:47:38 -05:00
|
|
|
path to the gpg binary you wish to use (default:
|
|
|
|
'gpg')
|
2021-05-19 15:30:10 -04:00
|
|
|
-a, --use-agent ask gpg to use its auth agent
|
2021-07-28 16:33:39 -04:00
|
|
|
--encodings encodings
|
2024-01-17 06:47:38 -05:00
|
|
|
comma-separated text encodings to try, in order,
|
|
|
|
when decoding gpg output (default: 'utf-8')
|
2021-07-28 16:33:39 -04:00
|
|
|
-e pattern, --exclude pattern
|
2024-01-17 06:47:38 -05:00
|
|
|
regexp for lines which should not be exported, can
|
|
|
|
be specified multiple times
|
2021-05-19 15:30:10 -04:00
|
|
|
-f name pattern, --get-field name pattern
|
2024-01-17 06:47:38 -05:00
|
|
|
a name and a regexp, the part of the line matching
|
|
|
|
the regexp will be removed and the remaining line
|
|
|
|
will be added to a field with the chosen name.
|
|
|
|
only one match per password, matching stops after
|
|
|
|
the first match
|
2021-05-19 15:30:10 -04:00
|
|
|
-l name pattern, --get-line name pattern
|
2024-01-17 06:47:38 -05:00
|
|
|
a name and a regexp for which all lines that match
|
|
|
|
are included in a field with the chosen name
|
|
|
|
--version show program's version number and exit
|
2020-06-07 16:39:28 -04:00
|
|
|
```
|
|
|
|
|
|
|
|
|
2021-05-19 15:30:10 -04:00
|
|
|
### Format
|
2016-05-30 05:31:00 -04:00
|
|
|
|
2021-05-19 15:30:10 -04:00
|
|
|
The output format is
|
2016-05-30 05:31:00 -04:00
|
|
|
|
2021-05-19 15:30:10 -04:00
|
|
|
Group(/),Title,Password,[custom fields...],Notes
|
2018-08-15 00:48:57 -04:00
|
|
|
|
2021-05-19 15:30:10 -04:00
|
|
|
You may add custom fields with `--get-field` or `--get-line`. You supply
|
2021-05-19 15:33:58 -04:00
|
|
|
a *name* for the field and a regexp *pattern*. The field name is used for
|
2021-05-19 15:30:10 -04:00
|
|
|
the header of the output CSV and to group multiple patterns for the same
|
|
|
|
field; you may specify multiple patterns for the same field by
|
|
|
|
specifying `--get-field` or`--get-line` multiple times with the same
|
2021-07-25 10:42:45 -04:00
|
|
|
name. Regexp patterns are case-insensitive.
|
2018-08-15 00:48:57 -04:00
|
|
|
|
|
|
|
|
2024-01-16 13:50:51 -05:00
|
|
|
### Example usage
|
2018-08-15 00:48:57 -04:00
|
|
|
|
2021-05-19 15:30:10 -04:00
|
|
|
```
|
2024-01-16 13:50:51 -05:00
|
|
|
$ gpg -d ~/.password-store/sites/example/login.gpg
|
2021-05-19 15:30:10 -04:00
|
|
|
password123
|
|
|
|
---
|
|
|
|
username: user_name
|
|
|
|
email user@example.com
|
|
|
|
url:example.com
|
|
|
|
Some note
|
2018-08-15 00:48:57 -04:00
|
|
|
|
2024-01-16 13:50:51 -05:00
|
|
|
$ pass2csv ~/.password-store - \
|
|
|
|
--exclude '^---$' \
|
|
|
|
--get-field Username '(username|email):?' \
|
|
|
|
--get-field URL 'url:?'
|
2018-08-15 00:48:57 -04:00
|
|
|
|
2024-01-16 13:50:51 -05:00
|
|
|
"Group(/)","Title","Password","URL","Username","Notes"
|
|
|
|
"sites/example","login","password123","example.com","user_name","email user@example.com
|
2018-08-15 00:48:57 -04:00
|
|
|
|
2024-01-16 13:50:51 -05:00
|
|
|
Some note"
|
2021-05-19 15:30:10 -04:00
|
|
|
```
|
2018-08-15 00:48:57 -04:00
|
|
|
|
2020-06-07 17:04:08 -04:00
|
|
|
|
2021-05-19 15:30:10 -04:00
|
|
|
### Grouping
|
2018-08-15 00:48:57 -04:00
|
|
|
|
2021-05-19 15:33:58 -04:00
|
|
|
The group is relative to the path, or the `--base` if given.
|
2021-05-19 16:19:06 -04:00
|
|
|
Given the password `~/.password-store/sites/example/login.gpg`:
|
2018-08-15 00:48:57 -04:00
|
|
|
|
2021-05-19 16:19:06 -04:00
|
|
|
$ pass2csv ~/.password-store/sites
|
|
|
|
# Password will have group "example"
|
2018-08-15 00:48:57 -04:00
|
|
|
|
2021-07-25 10:42:45 -04:00
|
|
|
$ pass2csv ~/.password-store/sites --base ~/.password-store
|
2021-05-19 16:19:06 -04:00
|
|
|
# Password will have group "sites/example"
|
2020-06-07 17:04:08 -04:00
|
|
|
|
|
|
|
|
2021-05-19 16:38:36 -04:00
|
|
|
## gpg-agent password timeout
|
|
|
|
|
|
|
|
If your private key is protected by a password, `gpg` will ask for it
|
|
|
|
with the `pinentry` program if you haven't set it to something else. If
|
|
|
|
using `gpg2` or the `-a` option with `gpg`, by default, the password is
|
|
|
|
cached for 10 minutes but the timer is reset when using a key. After 2
|
|
|
|
hours the cache will be cleared even if it has been accessed recently.
|
|
|
|
|
|
|
|
You can set these values in your `~/.gnupg/gpg-agent.conf`:
|
|
|
|
|
|
|
|
```
|
|
|
|
default-cache-ttl 600
|
|
|
|
max-cache-ttl 7200
|
|
|
|
```
|
|
|
|
|
|
|
|
|
2020-06-07 17:04:08 -04:00
|
|
|
## Development
|
2021-05-19 15:30:10 -04:00
|
|
|
|
2020-06-07 17:04:08 -04:00
|
|
|
Create a virtual environment:
|
|
|
|
|
2020-08-08 12:02:27 -04:00
|
|
|
python3 -m venv venv
|
2020-06-07 17:04:08 -04:00
|
|
|
|
|
|
|
Activate the environment:
|
|
|
|
|
2020-08-08 12:02:27 -04:00
|
|
|
. venv/bin/activate
|
2020-06-07 17:04:08 -04:00
|
|
|
|
|
|
|
Now you may either use `pip` directly to install the dependencies, or
|
|
|
|
you can install `pip-tools`. The latter is recommended.
|
|
|
|
|
2020-08-08 12:02:27 -04:00
|
|
|
|
2020-06-07 17:04:08 -04:00
|
|
|
### pip
|
|
|
|
|
2020-08-08 12:02:27 -04:00
|
|
|
pip install -r requirements.txt
|
2020-06-07 17:04:08 -04:00
|
|
|
|
|
|
|
|
|
|
|
### pip-tools
|
2021-05-19 15:30:10 -04:00
|
|
|
|
2020-06-07 17:04:08 -04:00
|
|
|
[pip-tools](https://github.com/jazzband/pip-tools) can keep your virtual
|
2020-08-08 12:02:27 -04:00
|
|
|
environment in sync with the `requirements.txt` file, as well as
|
|
|
|
compiling a new `requirements.txt` when adding/removing a dependency in
|
|
|
|
`requirements.in`.
|
2020-06-07 17:04:08 -04:00
|
|
|
|
2020-08-08 12:02:27 -04:00
|
|
|
It is recommended that pip-tools is installed within the virtual
|
2020-06-07 17:04:08 -04:00
|
|
|
environment.
|
|
|
|
|
2020-08-08 12:02:27 -04:00
|
|
|
pip install pip-tools
|
|
|
|
pip-compile # only necessary when adding/removing a dependency
|
|
|
|
pip-sync
|
2021-08-21 12:12:39 -04:00
|
|
|
|
|
|
|
|
|
|
|
### Packaging
|
|
|
|
|
2024-01-27 13:07:38 -05:00
|
|
|
See [Python Packaging User Guide](https://packaging.python.org/tutorials/packaging-projects/) for detailed info.
|
2021-08-21 12:12:39 -04:00
|
|
|
|
|
|
|
0. `pip-sync requirements.txt dev-requirements.txt`
|
2024-01-27 13:07:38 -05:00
|
|
|
1. Increment `__version__` in `pass2csv.py`.
|
|
|
|
2. `rm -rf dist/* && python3 -m build`
|
|
|
|
4. `python3 -m twine upload dist/*`
|