Skip to main content

Easily pick a place to store data for your python package.

Project description

PyStow

Build status PyPI - Python Version License Documentation Status DOI

👜 Easily pick a place to store data for your python code.

🚀 Getting Started

Get a directory for your application.

import pystow

# Get a directory (as a pathlib.Path) for ~/.data/pykeen
pykeen_directory = pystow.join('pykeen')

# Get a subdirectory (as a pathlib.Path) for ~/.data/pykeen/experiments
pykeen_experiments_directory = pystow.join('pykeen', 'experiments')

# You can go as deep as you want
pykeen_deep_directory = pystow.join('pykeen', 'experiments', 'a', 'b', 'c')

Get a file path for your application by adding the name keyword argument. This is made explicit so PyStow knows which parent directories to automatically create.

import pystow

# Get a directory (as a pathlib.Path) for ~/.data/indra/database.tsv
indra_database_path = pystow.join('indra', 'database', name='database.tsv')

Ensure a file from the internet is available in your application's directory:

import pystow

url = 'https://raw.githubusercontent.com/pykeen/pykeen/master/src/pykeen/datasets/nations/test.txt'
path = pystow.ensure('pykeen', 'datasets', 'nations', url=url)

Ensure a tabular data file from the internet and load it for usage (requires pip install pandas):

import pystow
import pandas as pd

url = 'https://raw.githubusercontent.com/pykeen/pykeen/master/src/pykeen/datasets/nations/test.txt'
df: pd.DataFrame = pystow.ensure_csv('pykeen', 'datasets', 'nations', url=url)

Ensure a RDF file from the internet and load it for usage (requires pip install rdflib)

import pystow
import rdflib

url = 'https://ftp.expasy.org/databases/rhea/rdf/rhea.rdf.gz'
rdf_graph: rdflib.Graph = pystow.ensure_rdf('rhea', url=url)

Also see pystow.ensure_excel(), pystow.ensure_rdf(), pystow.ensure_zip_df(), and pystow.ensure_tar_df().

⚙️️ Configuration

By default, data is stored in the $HOME/.data directory. By default, the <app> app will create the $HOME/.data/<app> folder.

If you want to use an alternate folder name to .data inside the home directory, you can set the PYSTOW_NAME environment variable. For example, if you set PYSTOW_NAME=mydata, then the following code for the pykeen app will create the $HOME/mydata/pykeen/ directory:

import os
import pystow

# Only for demonstration purposes. You should set environment
# variables either with your .bashrc or in the command line REPL.
os.environ['PYSTOW_NAME'] = 'mydata'

# Get a directory (as a pathlib.Path) for ~/mydata/pykeen
pykeen_directory = pystow.join('pykeen')

If you want to specify a completely custom directory that isn't relative to your home directory, you can set the PYSTOW_HOME environment variable. For example, if you set PYSTOW_HOME=/usr/local/, then the following code for the pykeen app will create the /usr/local/pykeen/ directory:

import os
import pystow

# Only for demonstration purposes. You should set environment
# variables either with your .bashrc or in the command line REPL.
os.environ['PYSTOW_HOME'] = '/usr/local/'

# Get a directory (as a pathlib.Path) for /usr/local/pykeen
pykeen_directory = pystow.join('pykeen')

Note: if you set PYSTOW_HOME, then PYSTOW_NAME is disregarded.

🚀 Installation

The most recent release can be installed from PyPI with:

$ pip install pystow

The most recent code and data can be installed directly from GitHub with:

$ pip install git+https://github.com/cthoyt/pystow.git

To install in development mode, use the following:

$ git clone git+https://github.com/cthoyt/pystow.git
$ cd pystow
$ pip install -e .

⚖️ License

The code in this package is licensed under the MIT License.

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

pystow-0.1.10.tar.gz (23.7 kB view details)

Uploaded Source

Built Distribution

pystow-0.1.10-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

Details for the file pystow-0.1.10.tar.gz.

File metadata

  • Download URL: pystow-0.1.10.tar.gz
  • Upload date:
  • Size: 23.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.5

File hashes

Hashes for pystow-0.1.10.tar.gz
Algorithm Hash digest
SHA256 4ea472eeddb2a38d1446e87e0d0ee697cf8e8bfbc93acb4f0ee3bfbeb3fec0a1
MD5 ea95fc0d7827af601068165fac452222
BLAKE2b-256 d49d7e00d109fea9d9dd30aa1fbdb1a2ae797c6fee9dbd73ce4fb3b0806e78a8

See more details on using hashes here.

Provenance

File details

Details for the file pystow-0.1.10-py3-none-any.whl.

File metadata

  • Download URL: pystow-0.1.10-py3-none-any.whl
  • Upload date:
  • Size: 18.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.5

File hashes

Hashes for pystow-0.1.10-py3-none-any.whl
Algorithm Hash digest
SHA256 e5e6597092b9960e58337ddaaab8e6b81590d2bda83b664842514ffd5ccca6be
MD5 b3cf8091c012ff28c0a4ab2249c640fd
BLAKE2b-256 696da840bce8390faa8e5d6ff0a899cff6156370d3b327824d8699069616d341

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page