Therapeutic filepath management for python data projects.
Project description
therepy
A simple r-lib/here for python, to make file path management less of a headache in project-oriented workflows.
Installation
pip install therepy
Overview
R's here library uses the .Rproj file to identify the top-level or root directory in an R project, and all file paths are defined relative to this directory.
Instead of looking for a specific file or file extension, the therepy
module has the user define the root directory somewhere ("there", if you will):
from therepy import Here
here = Here("myproj")
Once initialized, the Here
object allows you to specify file paths relative to the defined root directory (in this example, "myproj"), since it coverts them to absolute paths under the hood.
For example, if I have a dataset in a subfolder, "myproj/database/data.csv", and I want to use it in a script, "myproj/analysis/viz.py", I can specify the path like so:
# -- viz.py --
fp = here.here("database", "data.csv")
print(fp)
#> PosixPath("/home/user/Documents/myproj/database/data.csv")
df = read_csv(fp)
The relative paths are expanded into absolute paths, so the returned file path will work even if "viz.py" gets moved around.
If you do not want to use your project's folder name to initialize Here
, you can provide the name of a file that exists in your project's root or a glob style expression identifying such a file:
here = Here(".git")
here = Here("*.Rproj")
Here is built on pathlib and returns pathlib.Path instances by default (a PosixPath or WindowsPath depending on your system).
This allows you to take advantage of pathlib's great features, like:
here = Here("myproj")
fp = here.here("database/data.csv")
if fp.exists():
...
And since pathlib can resolve and join paths, you can easily define folders for reading and writing to:
here = Here("myproj")
outputs = here.here("outputs")
print(outputs)
#> PosixPath("/home/user/Documents/myproj/outputs")
...
df.to_csv(here.here(outputs, "data.csv"))
Here
will return strings if you ask it too:
here = Here("myproj")
print(here.here(as_str=True))
#> "/home/user/Documents/myproj"
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
File details
Details for the file therepy-0.0.1.tar.gz
.
File metadata
- Download URL: therepy-0.0.1.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d509bdec2bcb59a8267d1930cc96592e288367c3c1d8bcc9b2ff870137f87291 |
|
MD5 | b2bdaf75832bdd6c59094f41da97cebe |
|
BLAKE2b-256 | dcdca33b9b4b694137688b3a50da3d4bf0ab6ca8a76b46b70ee45ff72d9348e7 |
File details
Details for the file therepy-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: therepy-0.0.1-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c97ce92f9a2048fe50ac594562ed0f103c1d8005c375d5d7ee71324b0d7affb5 |
|
MD5 | 10c03fa825b2233ab368ffde4bfaa4aa |
|
BLAKE2b-256 | 0688b53812211fa93a319ea03c477eb4c9495b1d2c2620e1ccfa3048296ff3b9 |