A smart python utility that generates unique incremental names, preventing naming collisions by automatically appending incremental suffixes.
Project description
Namecrement (Python)
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
- JavaScript: Namecrement
- PHP: Namecrement-php
📦 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_numberisNoneandbase_nameis unused → returnsbase_name. - Otherwise returns
base_namewith 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
44314db1ee89112a718249cde1d67ed9bc1cf061cf32607b54f4ede68b4e14ba
|
|
| MD5 |
34c6dc54e4a08126fea471d1d1c2538b
|
|
| BLAKE2b-256 |
112a8cecf14aa38969d1b5192583b6ffa8d02c44e2ca9913a3da314556c4e287
|
Provenance
The following attestation bundles were made for namecrement-0.1.0.tar.gz:
Publisher:
release.yml on HichemTab-tech/Namecrement-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
namecrement-0.1.0.tar.gz -
Subject digest:
44314db1ee89112a718249cde1d67ed9bc1cf061cf32607b54f4ede68b4e14ba - Sigstore transparency entry: 461620769
- Sigstore integration time:
-
Permalink:
HichemTab-tech/Namecrement-py@7a31ea72ea76c1b84a022ec3090dcfe0997ddea0 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/HichemTab-tech
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7a31ea72ea76c1b84a022ec3090dcfe0997ddea0 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
95dff8ebedd6eae9bc3d54aac837376c7a54e7d1ae5618e7cf94c199e8099242
|
|
| MD5 |
c4a1932c637943b7956a46c8735ee80e
|
|
| BLAKE2b-256 |
6b708dbc2660ec13d4c18b3f2ca11a928287d9e14dc37ad4ab58e73c51408fa7
|
Provenance
The following attestation bundles were made for namecrement-0.1.0-py3-none-any.whl:
Publisher:
release.yml on HichemTab-tech/Namecrement-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
namecrement-0.1.0-py3-none-any.whl -
Subject digest:
95dff8ebedd6eae9bc3d54aac837376c7a54e7d1ae5618e7cf94c199e8099242 - Sigstore transparency entry: 461620788
- Sigstore integration time:
-
Permalink:
HichemTab-tech/Namecrement-py@7a31ea72ea76c1b84a022ec3090dcfe0997ddea0 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/HichemTab-tech
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7a31ea72ea76c1b84a022ec3090dcfe0997ddea0 -
Trigger Event:
push
-
Statement type: