Skip to main content

A Python CLI wrapping common Linux commands for local/cloud files.

Project description

cloudsh

A Python CLI that wraps common Linux commands for both local and cloud files using cloudpathlib.

Pypi Github PythonVers Building Codacy coverage

Cloud Storage Provider dependencies:

google-cloud-storage
boto3
azure-storage-blob

Installation

pip install -U cloudsh

# Install for different cloud storage providers
pip install -U cloudsh[gcs]  # Google Cloud Storage
pip install -U cloudsh[aws]  # Amazon S3
pip install -U cloudsh[azure]  # Azure Blob Storage

# Install for all cloud storage providers
pip install -U cloudsh[all]

Usage

cloudsh provides common Linux commands that work with both local and cloud files. Currently supported commands include:

  • cat: Concatenate and print files
  • cp: Copy files and directories
  • head: Output the first part of files
  • less: Display file contents with forward and backward navigation
  • ls: List directory contents
  • mkdir: Make directories
  • more: Display file contents page by page
  • mv: Move files and directories
  • rm: Remove files and directories
  • tail: Output the last part of files
  • touch: Create empty files

And two additional commands:

  • complete: Generate shell completion scripts
  • sink: Redirect output to a file

Authentication

See: https://cloudpathlib.drivendata.org/stable/authentication/ for details on how to authenticate with cloud storage providers.

The commands works on local files as the GNU/Linux commands do

$ cloudsh ls /tmp
$ cloudsh cp /tmp/file.txt /tmp/file2.txt

The commands works on cloud files

$ cloudsh ls gs://my-bucket
$ cloudsh touch gs://my-bucket/file.txt

The commands works between local and cloud files

$ cloudsh cp /tmp/file.txt gs://my-bucket/file.txt
$ cloudsh mv gs://my-bucket/file.txt /tmp/file.txt

The sink command redirects output to a file

# It is easy to redirect output to a local file
$ echo "Hello, World!" > /tmp/hello.txt
# But it is not so easy to redirect output to a cloud file, so we use `sink`
$ echo "Hello, World!" | cloudsh sink gs://my-bucket/hello.txt
# Append to a cloud file
$ echo "Hello, World!" | cloudsh sink -a gs://my-bucket/hello.txt

Drop-in Replacement for GNU/Linux Commands

Since the commands work on local files as well, you can make aliases to use cloudsh as a drop-in replacement for the GNU/Linux commands.

alias cat='cloudsh cat'
alias cp='cloudsh cp'
alias head='cloudsh head'
alias ls='cloudsh ls'
alias mkdir='cloudsh mkdir'
alias mv='cloudsh mv'
alias rm='cloudsh rm'
alias tail='cloudsh tail'
alias touch='cloudsh touch'

What if I want to use the original GNU/Linux commands?

# alias ls='cloudsh ls'
ls -- -l  # actually executes `/usr/bin/ls -l`

Shell Completion

Generating Shell Completion Scripts

cloudsh provides shell completion support, including the subcommands, options and both local and cloud paths, for bash, zsh and fish. To enable it:

# For bash
mkdir -p ~/.local/share/bash-completion
cloudsh complete --shell bash > ~/.local/share/bash-completion/cloudsh
activate-global-python-argcomplete --user
# Restart your shell
# For zsh
# Create the completions directory
mkdir -p ~/.zsh/completions

# Generate the Zsh script
cloudsh complete --shell zsh > ~/.zsh/completions/_cloudsh

# Update ~/.zshrc
echo 'fpath=(~/.zsh/completions $fpath)' >> ~/.zshrc
echo 'autoload -Uz compinit && compinit' >> ~/.zshrc

# Restart your shell
# For fish
cloudsh complete --shell fish > ~/.config/fish/completions/cloudsh.fish

Because of the latency when completing cloud paths, a message 'fetching ...' will be shown when completing cloud paths. export CLOUDSH_COMPLETE_NO_FETCHING_INDICATOR=1 to disable it.

Using a caching file for the completion to avoid latency when completing cloud paths

# Only cache the paths at depth 2 in the bucket
cloudsh complete --update-cache --depth 2 gs://my-bucket

[!NOTE] Remember to update the cache when the bucket structure changes. You can set up a cron job to update the cache periodically.

[!TIP] For the first time you are using cached cloud path completion, a warning message will be shown to remind you that you are using a cached completion. The warning will only be shown when <tmpdir>/cloudsh_caching_warned does not exist, which will be created after the first warning. To disable the warning permanently, try export CLOUDSH_COMPLETE_CACHING_WARN=1.

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

cloudsh-0.3.9a1.tar.gz (56.8 kB view details)

Uploaded Source

Built Distribution

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

cloudsh-0.3.9a1-py3-none-any.whl (42.7 kB view details)

Uploaded Python 3

File details

Details for the file cloudsh-0.3.9a1.tar.gz.

File metadata

  • Download URL: cloudsh-0.3.9a1.tar.gz
  • Upload date:
  • Size: 56.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for cloudsh-0.3.9a1.tar.gz
Algorithm Hash digest
SHA256 98c2491108a0a5c72cb82c54c6511c7c9abbcda9a1a7ffe80d19433102af8f84
MD5 eb220e70ceabf2934d0fb298e027fbde
BLAKE2b-256 620089288746c3784a7a148c43c59a0a795517ba6c044ea0a733ec34d1360cb7

See more details on using hashes here.

File details

Details for the file cloudsh-0.3.9a1-py3-none-any.whl.

File metadata

  • Download URL: cloudsh-0.3.9a1-py3-none-any.whl
  • Upload date:
  • Size: 42.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for cloudsh-0.3.9a1-py3-none-any.whl
Algorithm Hash digest
SHA256 7a9ed0fde0cd92c47f20fa5aac65c9bfc38e0a4095ada322d761b9d2dca570ea
MD5 3a492cb880399daabfa2a1796fe323ef
BLAKE2b-256 55a659ce4bf580c25eb774c7bf44376762805012863751e5a444ef18226b581f

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