Skip to main content

A simple replication of R's file.choose() for Python.

Project description

pyfilechoose

R's file.choose(), reimplemented for Python.

PyPI version Python versions Documentation License: MIT

In R, file.choose() opens a file picker and returns the path you select. pyfilechoose gives you the same one-liner in Python, with no GUI boilerplate and no leftover Tk windows.

It uses tkinter from the standard library, so it has no third-party dependencies.

📖 Full documentation: https://Pinto-Katende-Jonathan.github.io/pyfilechoose/ (installation, usage, API reference, internals, and troubleshooting).

Installation

With pip:

pip install pyfilechoose

With uv:

# Add it to your project
uv add pyfilechoose

# ...or install it into the current environment
uv pip install pyfilechoose

# ...or run a one-off script that uses it, no install needed
uv run --with pyfilechoose your_script.py

On Linux, tkinter ships with most Python builds but may need to be installed separately, e.g. sudo apt install python3-tk.

Usage

Pick a single file

from pyfilechoose import file_choose

path = file_choose()
print(path)  # absolute path of the file you selected

With pandas (the classic R workflow)

file_choose() returns a path string, so it works with any function that takes a file path, including pd.read_csv:

import pandas as pd
from pyfilechoose import file_choose

# Just like df <- read.csv(file.choose()) in R
df = pd.read_csv(file_choose())

You can still pass the usual pandas options, and filter the picker to CSVs:

df = pd.read_csv(file_choose(filetypes=[("CSV files", "*.csv")]), sep=";")

Filter file types and set a starting directory

path = file_choose(
    title="Pick your dataset",
    filetypes=[("CSV files", "*.csv"), ("All files", "*.*")],
    initialdir="~/Documents",
)

Pick several files at once

from pyfilechoose import files_choose

paths = files_choose(filetypes=[("Images", "*.png *.jpg")])
for p in paths:
    print(p)

API

file_choose(*, title="Select a file", filetypes=None, initialdir=None) -> str

Opens a dialog and returns the absolute path of the chosen file. Raises FileNotFoundError if the user cancels.

files_choose(*, title="Select one or more files", filetypes=None, initialdir=None) -> list[str]

Same as above but allows multiple selections; returns a list of absolute paths. Raises FileNotFoundError if nothing is selected.

Argument Type Description
title str Title of the dialog window.
filetypes list[tuple[str, str]] | None (label, pattern) pairs, e.g. [("CSV", "*.csv")].
initialdir str | None Directory the dialog opens in.

Development

git clone https://github.com/Pinto-Katende-Jonathan/pyfilechoose.git
cd pyfilechoose

With uv, which creates and manages the virtualenv for you:

uv sync --extra dev   # set up the environment with dev dependencies
uv run pytest         # run the test suite

With pip:

python -m venv .venv && source .venv/bin/activate  # Windows: .venv\Scripts\activate
pip install -e ".[dev]"
pytest

License

MIT © Jonathan Katende Pinto

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

pyfilechoose-0.1.1.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

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

pyfilechoose-0.1.1-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file pyfilechoose-0.1.1.tar.gz.

File metadata

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

File hashes

Hashes for pyfilechoose-0.1.1.tar.gz
Algorithm Hash digest
SHA256 68f6c1d109be41433655d6e1923bb4922dab626333ac3afbed900a9c37dc432f
MD5 bb00a46203282f3cfdb3cf5ff7d6c21f
BLAKE2b-256 9caa4f212b8d268cda39750d57dac01cfbee9618bd6ed36f9ae6b211089e063f

See more details on using hashes here.

File details

Details for the file pyfilechoose-0.1.1-py3-none-any.whl.

File metadata

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

File hashes

Hashes for pyfilechoose-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 953f1ab61149ad46b26579f1a19c93d5070af4e41eb3161317d5e679f1ca5c29
MD5 b2f99cc7a276c2efb4915795913bc04c
BLAKE2b-256 0a9a695f945d74005eb68e76a9605ded6ff9dda3ea1f7a54e222a9e1f3acf5c5

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