Skip to main content

A tiny, secure key generator.

Project description

On PyPI Downloads Total Downloads Python Version License

TinyGenKey

A tiny, secure, and easy-to-use key generator in Python. Generate cryptographically strong keys for your needs.


Features

  • Cryptographically secure keys using os.urandom
  • Customizable alphabet, length, prefix, and suffix
  • Lightweight and dependency-free
  • Type-hinted for modern Python

Installation

pip install tinygenkey

Usage

import tinygenkey as tgk


# Generate a default 42-character key
key = tgk.gen_key()
print(key)

# Generate a key with a prefix and suffix
key2 = tgk.gen_key(prefix="user_", suffix="_end", length=16)
print(key2)

# Use a custom alphabet
custom_alphabet = list("ABC123")
key3 = tgk.gen_key(alphabet=custom_alphabet, length=8)
print(key3)

keys_seq()

This function returns a list of keys, determined with argument count and customized with **kwargs.

api_key = tgk.keys_seq(5) # Generates 5 keys

new_tokens = tgk.keys_seq(5, prefix="new_", suffix=f"_{tgk.keys_gen(length=6)}", preset="hex")

# Align with keys_align()
print(tgk.keys_align(new_tokens))

keys_align()

Separates a list of tokens with a passed separator argument (default is newline \n). Examples could be seen on keys_seq()


Advanced Usage

Recursive Key Generation

Create structured, hierarchical keys by cleanly nesting keys_gen() (or outdated gen_key()) calls:

api_key = tgk.keys_gen(
    prefix=f"api_{tgk.gen_key(length=8)}_",
    length=32,
    suffix=f"_{tgk.gen_key(length=4)}"
)
# Result = api_<8 random chars>_<32 random>_<4 random>
# Organized and polished identifiers!

This composable design allows you to build complex key structures while maintaining cryptographic security at every level.

Why This Is Better Than secrets

With Python's built-in secrets module:

# pretend we imported secrets and have an alphanumeric
# list of characters

# awkward..
secrets_key = (
    f"api_"
    f"{''.join(secrets.choice(chars) for _ in range(8))}_"
    f"{''.join(secrets.choice(chars) for _ in range(32))}"
    f"_{''.join(secrets.choice(chars) for _ in range(8))}"
)

With tinygenkey

import tinygenkey as tgk

# Much better
tgk_key = tgk.keys_gen(
    prefix=f"api_{tgk.gen_key(length=8)}_",
    length=32,
    suffix=f"_{tgk.gen_key(length=4)}"
)

Cleaner, more readable, easier to maintain.


!!!! WARNING Syntax Migration !!!!

In version 0.2.0, the syntax for gen_key() will be replaced by a more powerful and consistent keys_gen(). You may still use gen_key() as usual, but it is deprecated.

On version stable 0.5.0, gen_key() will be deleted, but optional deprecated-supported versions will still be maintained as version >0.5-dep and is NOT preserved in minor updates.

By version 1.0.0, gen_key() will be removed entirely and deprecated-supported versions will stop being maintained.

Save Your Program

If your program cannot be modified and is very important for others, you may ask for a special version that supports gen_key().


GitHub

This project is open-sourced at GitHub: tinygenkey on GitHub

You may further verify the security of the code yourself.


License

This project is protected by the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tinygenkey-0.2.1.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tinygenkey-0.2.1-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file tinygenkey-0.2.1.tar.gz.

File metadata

  • Download URL: tinygenkey-0.2.1.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for tinygenkey-0.2.1.tar.gz
Algorithm Hash digest
SHA256 04d36ea6408f6ae70b3dab7881a02605a36bd8c06c2ff456cc91ac465102a46f
MD5 62b20d3cf4ba02f11fdc1418a2d66824
BLAKE2b-256 cb8ec3e805f1783625e54e22d4cc55178d0cf8fd22feaec1521c19a3e4684cdd

See more details on using hashes here.

File details

Details for the file tinygenkey-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: tinygenkey-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 14.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for tinygenkey-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 92fd573ec4d2c0d286e75bbc25d84d6209ef155c8f3c3b5766cecb3d8ad51813
MD5 1844b468bbb90e52c83bccbdf6fdb0a9
BLAKE2b-256 25b5501ad2d9653207bab0ca9067476ba99aba254291944dfdf347fd0f2e298a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page