Skip to main content

A smart python utility that generates unique incremental names, preventing naming collisions by automatically appending incremental suffixes.

Project description

Namecrement (Python)

Tests License PyPI Version

Smart and simple unique name generator. If a name already exists, Namecrement automatically increments it, like "file""file (1)", "file (2)", and so on.


✨ Features

  • Automatically avoids naming collisions
  • Smart incremental naming ((1), (2), etc.)
  • Lightweight and dependency-free (single function)
  • Works for filenames, labels, identifiers, and more

📦 Also Available


📦 Installation

pip install namecrement

or (with uv):

uv add namecrement

🚀 Usage

from namecrement import namecrement

# Example list of existing names
existing = ["file", "file (1)", "file (2)"]

# Generate a unique name
new_name = namecrement("file", existing)

print(new_name)  # -> "file (3)"

🧠 Advanced Usage

from namecrement import namecrement

namecrement("file", ["file", "file -1-", "file -2-"], " -%N%-")
# -> "file -3-"

You can customize how numbers are added by using the %N% placeholder in a suffix_format:

Format Example Output
" (%N%)" file (1)
"-%N%" file-1
"_v%N%" file_v1
"<%N%>" file<1>

✅ Format Guard

suffix_format must include the %N% placeholder, otherwise the function raises a ValueError. This ensures every generated name contains the incremented number in your format.

namecrement("log", ["log", "log_1"], "_%N%_")
# -> "log_2"

📚 API

namecrement(base_name: str, existing_names: Iterable[str], suffix_format: str = " (%N%)", starting_number: int | None = None) -> str

Parameter Type Description
base_name str The proposed name
existing_names Iterable[str] The list of names to check against
suffix_format str The format for the incremented name (default: " (%N%)")
starting_number int | None Optional starting number override (default: None)

Returns a unique name based on the proposed one.

  • If starting_number is None and base_name is unused → returns base_name.
  • Otherwise returns base_name with the first available %N%.

🛠️ Examples

from namecrement import namecrement

namecrement("report", ["report", "report (1)"])
# -> "report (2)"

namecrement("image", ["photo", "image", "image (1)", "image (2)"])
# -> "image (3)"

namecrement("new", [])
# -> "new"

namecrement("document", ["document", "document -1-", "document (2)"], " -%N%-")
# -> "document -2-"

namecrement("file", [], " (%N%)", 5)
# -> "file (5)"

📄 License

MIT License © 2025 Hichem Taboukouyout

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

namecrement-0.1.0.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

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

namecrement-0.1.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file namecrement-0.1.0.tar.gz.

File metadata

  • Download URL: namecrement-0.1.0.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for namecrement-0.1.0.tar.gz
Algorithm Hash digest
SHA256 44314db1ee89112a718249cde1d67ed9bc1cf061cf32607b54f4ede68b4e14ba
MD5 34c6dc54e4a08126fea471d1d1c2538b
BLAKE2b-256 112a8cecf14aa38969d1b5192583b6ffa8d02c44e2ca9913a3da314556c4e287

See more details on using hashes here.

Provenance

The following attestation bundles were made for namecrement-0.1.0.tar.gz:

Publisher: release.yml on HichemTab-tech/Namecrement-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file namecrement-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: namecrement-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for namecrement-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 95dff8ebedd6eae9bc3d54aac837376c7a54e7d1ae5618e7cf94c199e8099242
MD5 c4a1932c637943b7956a46c8735ee80e
BLAKE2b-256 6b708dbc2660ec13d4c18b3f2ca11a928287d9e14dc37ad4ab58e73c51408fa7

See more details on using hashes here.

Provenance

The following attestation bundles were made for namecrement-0.1.0-py3-none-any.whl:

Publisher: release.yml on HichemTab-tech/Namecrement-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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