Skip to main content

Automatically assign an increasing sequence number to file names.

Project description


Automatically assign an increasing sequence number to file names.


$ python -m pip install numfile

Use Cases

Write data to numbered snapshot files in a given directory:

$ python -q
>>> from numfile import open_next
>>> for version in ("first", "second", "third"):
...     with open_next("/tmp/snapshot.txt") as file:
...         print(f"The {version} version.", file=file)

$ ls -d /tmp/* | grep snapshot

Append messages to the latest log file:

$ ls -tr | grep app-error

$ python -q
>>> from numfile import open_latest
>>> with open_latest("app-error.log") as file: 
...     print("Oops... Something went wrong!", file=file)
...     print(

$ tail -n1 app-error-3.log
Oops... Something went wrong!

Consolidate similar files in chronological order:

$ python -q
>>> from numfile import open_all
>>> for file in open_all("/tmp/snapshot.txt"): 
...     print(,, end="")
/tmp/snapshot-1.txt The first version.
/tmp/snapshot-2.txt The second version.
/tmp/snapshot-3.txt The third version.


$ git clone
$ cd numfile
$ pyenv local 3.9.0
$ python -m venv .venv --prompt=numfile
$ source .venv/bin/activate
$ pip install -U pip flit
$ flit install --deps=all --symlink
$ python -m pytest



Make sure there are no uncommitted or untracked files, and then bump the version:

$ bump2version minor
$ git status
$ git commit -am "Bumped version"

Build a new binary package:

$ rm -rf dist
$ flit build

Publish the binaries to the official PyPI server:

$ flit publish

To use the Test PyPI server, create a file ~/.pypirc with your username:

index-servers =

repository =
username = your-username

repository =
username = your-username

Then, supply the test server using the --repository flag:

$ flit publish --repository testpypi

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

numfile-0.1.0.tar.gz (8.0 kB view hashes)

Uploaded source

Built Distribution

numfile-0.1.0-py3-none-any.whl (4.1 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page