Metadata-Version: 2.5
Name: api-key-factory
Version: 1.4.0
Summary: A simple CLI tool to generate API Key
Project-URL: Homepage, https://gitlab.com/op_so/projects/api-key-factory
Author-email: FX Soubirou <soubirou@yahoo.fr>
License-Expression: MIT
License-File: LICENSE
Classifier: Environment :: Console
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Typing :: Typed
Requires-Python: >=3.13
Requires-Dist: typer>=0.27.3
Description-Content-Type: text/markdown

# `api-key-factory`

[![Software License](https://img.shields.io/badge/license-MIT-informational.svg?style=for-the-badge)](LICENSE)
[![semantic-release: angular](https://img.shields.io/badge/semantic--release-angular-e10079?logo=semantic-release&style=for-the-badge)](https://github.com/semantic-release/semantic-release)
[![Pipeline Status](https://img.shields.io/gitlab/pipeline-status/op_so/projects/api-key-factory?style=for-the-badge)](https://gitlab.com/op_so/projects/api-key-factory/pipelines)

<img src="https://gitlab.com/op_so/projects/api-key-factory/-/raw/main/api_key_factory.png?ref_type=heads" alt="Logo of api-key-factory" width="150px" height="150px" style="display: block; margin: 0 auto; border: solid; border-color: #5f6368; border-radius: 20px;">

## Overview

`api-key-factory` is a CLI tool to generate API keys and their corresponding [SHA-256](https://en.wikipedia.org/wiki/SHA-2) hashes. The secret part of the key is an [UUID (Universally Unique Identifier) version 4 (random)](https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_(random)).

Example of a generated API key:

```bash
mykey-8590efb6-0a68-4390-8537-99a54928c669
```

```bash
Usage: api-key-factory [OPTIONS] COMMAND [ARGS]...

 A simple CLI tool to generate API keys and their corresponding SHA-256 hashes.

╭─ Options ────────────────────────────────────────────────────────────────────╮
│ --version          Show the version and exit.                                │
│ --help             Show this message and exit.                               │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ───────────────────────────────────────────────────────────────────╮
│ generate  Command to generate API keys and their corresponding SHA-256       │
│           hashes.                                                            │
╰──────────────────────────────────────────────────────────────────────────────╯
```

## `generate`

Generate API keys and hashes in standard terminal output (stdout) or in 2 distinct files (`[prefix_]keys.txt`, `[prefix_]hashes.txt`) in a defined directory.

The files are created readable and writable by their owner only (mode `0600`) and an existing file is never overwritten. The prefix cannot contain whitespace, a path separator (`/`, `\`, `:`) or a control character.

```bash
Usage: api-key-factory generate [OPTIONS]

 Command to generate API keys and their corresponding SHA-256 hashes.

╭─ Options ────────────────────────────────────────────────────────────────────╮
│ --dir     -d      <directory>         Directory to output keys and hashes.   │
│                                       If not set output to stdout.           │
│ --num     -n      <int range> [x>=1]  Number of API keys to generate         │
│                                       [default: 1]                           │
│ --prefix  -p      <str>               Add a prefix at the beginning of the   │
│                                       key                                    │
│ --help                                Show this message and exit.            │
╰──────────────────────────────────────────────────────────────────────────────╯
```

Example:

```bash
$ api-key-factory generate --num 2
d097dccc-cd24-4137-8ddb-d03f8b07d8d9   8b89600015b273c28f966f368456e45e01df239a36bf939ff72a16881f775679
c2d79a40-388e-4709-9e4b-903035b0e71e   fb22be500af1ef0479745bbbce847854da33f5e910361ad278e0282995b95f4d
$ api-key-factory generate --prefix mykey
mykey-3532dceb-f38a-491b-814d-9607bc9a947a   83309f0b7cd16fbd02edc85dbe32fc3326367618cf80a885f649d8e4eaeb43b3
$ api-key-factory generate -p mykey -n 5 --dir out
Success! 5 keys and hashes have been written to the files:
 - out/mykey_keys.txt
 - out/mykey_hashes.txt
```

## Installation

### With `Python` environment

To use:

- Minimal Python version: 3.13

Installation with Python `pip`:

```bash
python3 -m pip install api-key-factory
api-key-factory --help
```

## Development

### With [uv](https://docs.astral.sh/uv/) and [Task](https://taskfile.dev/)

To use:

- Python version: 3.13 or 3.14
- `uv` installation documentation: [https://docs.astral.sh/uv/getting-started/installation/](https://docs.astral.sh/uv/getting-started/installation/)
- `task` installation documentation: [https://taskfile.dev/installation/](https://taskfile.dev/installation/)

```bash
# Set environment
uv sync
# Format
task 00:110-format
# Lint
task 00:120-lint
# Static typing
task 00:130-type-check
# Tests
task 00:220-run-tests
# Run
uv run api-key-factory --help
```

## Authors

- **FX Soubirou** - *Initial work* - [GitLab repositories](https://gitlab.com/op_so)

## License

This program is free software: you can redistribute it and/or modify it under the terms of the MIT License (MIT).
See the [LICENSE](https://opensource.org/licenses/MIT) for details.
