Metadata-Version: 2.4
Name: generateApiKey
Version: 0.4.8
Summary: This package provides a convenient way to generate API keys using a secret, seed, and an optional include keyword. The generated keys are unique and secure, making them suitable for use in a variety of applications
Home-page: https://github.com/nuhmanpk/generate-api-key
Author: Nuhman Pk
Author-email: nuhmanpk7@gmail.com
License: MIT
Project-URL: Documentation, https://github.com/nuhmanpk/generate-api-key/blob/main/README.md
Project-URL: Funding, https://github.com/sponsors/nuhmanpk
Project-URL: Source, https://github.com/nuhmanpk/generate-api-key/
Project-URL: Tracker, https://github.com/nuhmanpk/generate-api-key/issues
Classifier: Programming Language :: Python :: 3.9
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: cryptography
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license
Dynamic: license-file
Dynamic: project-url
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

[![Downloads](https://static.pepy.tech/personalized-badge/generateApiKey?period=total&units=abbreviation&left_color=grey&right_color=yellow&left_text=Total-Downloads)](https://pepy.tech/project/generateApiKey)
[![Supported Versions](https://img.shields.io/pypi/pyversions/generateApiKey.svg)](https://pypi.org/project/YoutubeTags)
![GitHub](https://img.shields.io/github/license/nuhmanpk/generate-api-key)
![PyPI](https://img.shields.io/pypi/v/generateApiKey)
![PyPI - Downloads](https://img.shields.io/pypi/dm/generateApiKey)
[![Downloads](https://static.pepy.tech/personalized-badge/generateApiKey?period=week&units=international_system&left_color=grey&right_color=brightgreen&left_text=Downloads/Week)](https://pepy.tech/project/generateApiKey)
[![Upload to PIP](https://github.com/nuhmanpk/generate-api-key/actions/workflows/pypi-upload.yml/badge.svg)](https://github.com/nuhmanpk/generate-api-key/actions/workflows/pypi-upload.yml)
![PyPI - Format](https://img.shields.io/pypi/format/generateApiKey)
# API Key Generation Package

Timestamp and Numeric Representation: Now, the package incorporates a time-based and date-based hashing mechanism, adding an extra layer of security to your API keys. It captures the current timestamp and numeric representation of the key generation process, creating a unique identifier that's closely tied to the moment it was generated. This feature adds an element of time-based uniqueness to your keys, making them even more secure and less predictable.

This package provides a convenient way to generate API keys using a secret, seed, and an optional include keyword. The generated keys are unique and secure, making them suitable for use in a variety of applications.

The package supports generating API keys using a variety of methods such as UUID v5 and SHA-256 algorithm. The keys are generated using a combination of seed, secret, and include keyword. Additionally, the package allows you to insert the include keyword at a random position in the seed which will make it more difficult to guess.

It is important to keep the secret used to generate the keys secure and not share it with unauthorized parties. Additionally, the package can only be used for legitimate and legal purposes.

Please keep in mind that, even though this package provides a secure way to generate API keys, it is still important to use other security measures such as rate limiting, IP whitelisting, and encryption to protect your API and the data it accesses.

By using this package, you agree to take all necessary precautions to protect the data and resources accessed with the keys from unauthorized access or misuse. It is recommended to consult with a security expert before using this package or handling sensitive data.

# Privacy Policy

This package generates API keys that can be used to access sensitive data or resources. By using this package, you agree to keep the secret used to generate the keys secure and not share it with unauthorized parties. Additionally, the package can only be used for legitimate and legal purposes.

Please be aware that the package may cause a security risk if not used properly. The authors of this package cannot be held responsible for any unauthorized access or misuse of the keys generated by this package.

It is the user's responsibility to ensure the security of the keys and the protection of the data. It is recommended to consult with a security expert before using this package or handling sensitive data.

By using this package, you agree to take all necessary precautions to protect the data and resources accessed with the keys from unauthorized access or misuse.



# Installation
To install your package, you can use the pip package manager by running the following command in your command line:

```python
pip install generateApiKey
```

# Quick start

The simplest way to get a secure key — no arguments, no `await`:

```python
from generateApiKey import generate_api_key

api_key = generate_api_key()   # 'uYTvAuzrTHAeU202ScbN6jV8kxIMogDf'
```

That's it. Everything below is optional.

## Common recipes

```python
generate_api_key(length=48)                       # longer key
generate_api_key(prefix="sk")                      # 'sk-gRsNbb2lQ1cZxoT3...'
generate_api_key(dashes=True)                      # 'GdBA-6DhM-M3Fv-g99C...'
generate_api_key(charset="hex", length=32)         # hex only
generate_api_key(charset="base58")                 # no ambiguous 0/O/I/l
generate_api_key(charset="ABC123", length=10)      # your own alphabet
generate_api_key(case="upper", charset="alphabetic")
```

## Charsets

Pass a preset name or a literal string of characters to `charset`:

| Preset | Characters |
|--------|-----------|
| `alphanumeric` (default) | `A-Z a-z 0-9` |
| `base62` | `A-Z a-z 0-9` |
| `base58` | base62 minus `0 O I l` |
| `base64url` | `A-Z a-z 0-9 - _` |
| `alphabetic` | `A-Z a-z` |
| `numeric` | `0-9` |
| `hex` | `0-9 a-f` |
| `base16` | `0-9 A-F` |

## Expiring keys

Set `expiry` (minutes). The returned key **is a string** but also carries expiry metadata:

```python
key = generate_api_key(expiry=60)

headers = {"Authorization": key}   # works — it's a str
key.expires_at                     # unix timestamp
key.is_expired                     # False (until 60 min pass)
```

## Derived keys (secret + seed)

Provide both `secret` and `seed` to derive the key deterministically from them
(HMAC-SHA256). A random salt still makes each generated key unique:

```python
generate_api_key("mysecret", "user-42", length=20, include="prod")
```

## Async is optional

The library is synchronous by default. When you need an awaitable:

```python
from generateApiKey import generate_api_key_async

api_key = await generate_api_key_async(length=48, prefix="sk")
```

> The original `await generateApiKey(secret, seed, ...)` still works unchanged
> for backwards compatibility, but `generate_api_key` is recommended.

## Error handling

```python
try:
    api_key = generate_api_key(length=32)
except ValueError as e:
    print(e)   # e.g. bad length, or only one of secret/seed given
```

# Parameters

All parameters are optional. Call `generate_api_key()` with nothing for a secure default.

| **Parameter** | **Type** | **Default** | **Description** |
|---------------|----------|-------------|-----------------|
| `secret` | `str` | `None` | Optional secret. Given with `seed`, the key is HMAC-derived instead of random. |
| `seed` | `str` | `None` | Optional per-key value, used together with `secret`. |
| `length` | `int` | `32` | Number of characters in the key body. |
| `charset` | `str` | `"alphanumeric"` | Preset name (see table) or a literal string of allowed characters. |
| `case` | `str` | `"mixed"` | `"mixed"`, `"lower"` or `"upper"`. Affects letters only. |
| `prefix` | `str` | `None` | Prefix joined with `separator`, e.g. `sk-...`. |
| `separator` | `str` | `"-"` | String between prefix and key. |
| `dashes` | `bool` | `False` | Group the key with dashes for readability. |
| `dash_group` | `int` | `4` | Group size when `dashes=True`. |
| `include` | `str` | `None` | Extra value mixed into a derived key (needs `secret` + `seed`). |
| `expiry` | `int` | `None` | Expiry in minutes; sets `.expires_at` / `.is_expired`. |

Returns an `ApiKey` — a `str` subclass, so it works anywhere a string does.


By using this package, you are solely liable for any legal issues that may arise from its unauthorized use or misuse, as well as any security risks that may result from not properly securing the secret key used to generate the API keys.

# Fair Use Policy:

This package is provided as is, without any warranties or guarantees of any kind. We are not liable for any damages or losses that may result from its use. We reserve the right to change or discontinue the package at any time without notice.

We encourage you to use the package responsibly, and to report any security issues or bugs you may encounter.



Made with ❤️ , **Happy coding! 🚀**
