ysskrishna logoysskrishna

Unused Path

Stop overwriting downloads and exports. Get the next free filename, browser style.

Built with
PyPI Packages
File & Path Utilities
Python
uv
PyPI
GitHub Actions
Pytest
Details
FreeMIT licenseCreated February 10, 2026Updated November 12, 2026
Share this product

You picked a sensible filename. The folder already has it.

You export a report, pull down the same attachment again, or spin up another backup folder. The name you want is taken. You either overwrite something you needed, or you hand-roll a loop that checks exists, bumps a counter, and hopes nothing else writes in the same millisecond.

Unused Path is the small Python helper that picks the next unused path for you.

Like the browser naming your second download, without the while loop.

What you get

  • The next free name, not a overwrite. When the path you want is taken, you get a sibling with an incrementing numeric suffix in the familiar parenthesis style.
  • Folders, not only files. The same idea works when you need a fresh directory name for backups or batch exports.
  • Your own numbering style when you need it. Plug in a formatter for underscore versions, zero-padded versions, or any pattern you define.
  • A calmer concurrent story. Optional atomic creation can claim an empty file or directory while several workers race for a name.
  • No extra packages to install. The library ships with zero third-party dependencies.
  • Free and open source. MIT licensed, on PyPI and GitHub.

Picture your Tuesday export

You run a nightly job that drops a CSV next to yesterday's file. The first night it uses the plain name. The next night the folder already holds that file, so the job asks for an unused path and writes report (1).csv instead of stomping the old one. Same script, no manual rename dance.

Ready to try it?

Frequently asked questions

How do I save a file in Python without overwriting one that already exists?

Ask for an unused filename with the path you want. If that name is free, you get it back unchanged. If something already sits there, the library continues the numbered sequence beside it, similar to how browsers label duplicate downloads.

Can it pick a unique folder name too, not just files?

Yes. There is a matching helper for directory paths. It uses the same auto-incrementing suffix idea when a folder with that name already exists.

How do I avoid races when several workers grab a name at once?

Pass the optional create flag when you want the library to atomically create the empty file or directory as it claims the name. That is aimed at multi-threaded or multi-process jobs where a simple exists check is not enough.

Can I change how the number is formatted?

Yes. You can supply a custom formatter so names look like underscore versions, zero-padded version tags, or any pattern your formatter returns.

Why not just write a short pathlib loop myself?

You can, and many teams do once. The library centralizes the suffix rules, gap handling when numbered siblings already exist, optional atomic creation, and formatter hooks so you do not copy-paste the same loop into every script.

Does it add dependencies to my project?

No. The package is documented as having zero external dependencies.

Is it free?

Yes. It is open source under the MIT license.

Do I need to be a developer?

You need a Python project on version 3.8 or newer where you write files or create directories on a local filesystem. Install and API details live on the GitHub and PyPI pages.

Continue exploring

ProductPyPIVideo Extensions

Video Extensions

A fast, honest first filter when a filename might be video.
File & Path Utilities
PyPI Packages
+5
ProductPyPIText Extensions

Text Extensions

Know which paths look like text before you open them. One shared list, no list upkeep.
File & Path Utilities
PyPI Packages
+5
ProductPyPIBinary Extensions

Binary Extensions

Know which paths look binary in Python, from a curated list of 250+ extensions with no extra dependencies.
File & Path Utilities
PyPI Packages
+5
ProductPyPIStrip BOM

Strip BOM

Invisible UTF-8 marks should not break your parsers, CSV headers, or string checks.
Text & Data Conversion
File & Path Utilities
+6
ProductPyPISocial Links

Social Links

Users paste messy profile links. One Python library turns them into clean, comparable URLs.
PyPI Packages
Python
+4
ProductPyPINested Utils

Nested Utils

Deep JSON and config paths, one string, no guard maze.
PyPI Packages
Python
+4