Skip to main content

PyConsoleCMDTools

PyPI - Downloads GitHub release GitHub license

Installation

pip install consolecmdtools  # install
pip install --upgrade consolecmdtools  # update
python -m consolecmdtools  # examples

Get Started

import consolecmdtools as cct
print(cct.__version__)

Functions

>>> cct.banner("hello, world!")  # Generate banner for text
#######################
#    hello, world!    #
#######################

>>> cct.md5("blah blah blah")  # Return md5 hash for text.
'55e562bfee2bde4f9e71b8885eb5e303'

>>> cct.md5(42)  # Return md5 hash for number.
'a1d0c6e83f027327d8461063f4ac58a6'

>>> cct.md5('file.txt')  # Return md5 hash for file.
'd07aa6ddab4d6d2d2891aa9f3625a5db'

>>> cct.md5('file.txt', force_text=True)  # Force to return the md5 has for text, even the file exists.
'3d8e577bddb17db339eae0b3d9bcf180'

>>> cct.crc32("blah blah blah")  # Return crc32 hash for text.
753353432

>>> cct.crc32(42)  # Return crc32 hash for number.
841265288

>>> cct.crc32('file.txt')  # Return crc32 hash for file.
1030388931

>>> cct.crc32('file.txt', force_text=True)  # Force to return the md5 has for text, even the file exists.
3774289445

>>> cct.main_color('image.jpg')  # Get theme color of image.
(152, 156, 69)  # RGB value

>>> cct.main_color('http://image-url/image', is_url=True)  # Get theme color of web image.
(152, 156, 69)  # RGB value

>>> cct.main_color('image.jpg', scale=500)  # Cost more time to generate a preciser color. default scale is 200.
(152, 156, 69)

>>> cct.main_color('image.jpg', triplet='hex')  # Return color in hex triplet format. default mode is 'rgb'.
'#989C45'

>>> cct.clear_screen()  # Clear the console.

>>> cct.get_py_cmd()  # Get python running command for different OS.
'python3'

>>> cct.run_cmd("echo hello")  # Run console command. If the command failed, a warning message echoed. Returns bool.
*
| __RUN COMMAND__________________________
| (Command) echo hello
hello
`

>>> cct.read_cmd("echo hello")  # Run a command and return the output.
| (_command) echo hello
'hello\n'

>>> cct.read_cmd("echo hello", verbose=False)  # Run a command and return the output without verbose.
'hello\n'

>>> cct.read_cmd("notexist")  # If the command failed, a warning message echoed.
| (_command) echo hello
| (Warn) Command Failed:
'Error Messages'

>>> cct.resolve_value(42)  # If the input is not a dict, return itself.
42

>>> cct.resolve_value({"Windows": "win", "Darwin": "macOS", "*": "Linux"})  # Get the value for current platform. `*` is for default.
'Linux'

>>> cct.is_cmd_exist("ls")  # Test if a command is exist.
True

>>> cct.install_package("git")  # Install a package.
True

>>> cct.install_package(name="ping3", manager="pip3")  # Install a package using a different package manager. Options: scoop, choco, brew, port, apt, snap, pip, pip3, pipx, npm, bun.
True

>>> cct.install_package({
    "Windows": "pypy",
    "Darwin": "python",
    "Linux": "python3"
})  # Install a package using different package names for different OS.
True

>>> cct.install_package({
    "Linux": "python3",
    "*": "python"
})  # Install a package using different package names for different OS with a default one.
True

>>> cct.install_package("git", manager={
    "Windows": "choco",
    "Darwin": "port",
    "Linux": "snap",
    "*": "npm"
})  # Install a package using different package managers for different OS with a default one.

>>> cct.get_path("./file.txt")  # Get the absolute path.
Path('/path/to/file.txt')  # Path Object which is a subclass of str.

>>> cct.get_path("./file.txt").split('/')  # Path Object can be used as str.
['path', 'to', 'file.txt']

>>> cct.get_path("./file.txt").path  # Get the original path.
'./file.txt'

>>> cct.get_path("./file.txt").abs  # Get the absolute path. Same as `get_path("./file.txt")` itself.

>>> cct.get_path("./file.txt").exists  # Test if the path exists.
True

>>> cct.get_path("./file.txt").is_file  # Test if the path is a file.
True

>>> cct.get_path("./file.txt").is_dir  # Test if the path is a dir.
False

>>> cct.get_path("./file.txt").join("subfolder")  # Join the path.
Path('/path/to/subfolder')

>>> cct.get_path("/path/to/file.txt").basename  # Get the basename of the file or dir.
'file.txt'

>>> cct.get_path("/path/to/file.txt").ext  # Get the extension of the path. If the path is a dir, return ''.
'txt'

>>> cct.get_path("/path/to/file.txt").stem  # Get the name of the path without extension. If the path is a dir, return its basename.
'file'

>>> cct.get_path("/path/to/file.txt").parent  # Get the parent dir path of the file or dir.
Path('/path/to')

>>> cct.get_path("/path/to/file.txt").parent.basename  # Get the parent dir path's basename of the file or dir.
'to'

>>> cct.select_path()  # Show file dialog to get file path. Additional args pass to tkinter.filedialog.askopenfilename()
'/path/to/file'

>>> cct.select_path(multiple=True)  # Show file dialog to get multiple file paths.
['/path/to/file1', '/path/to/file2']

>>> cct.select_path(dir=True)  # Show file dialog to get dir path.
'/path/to/dir'

>>> cct.bfs_walk("/path/to/root")  # Get all paths in the root dir using Breadth-first search.
['/path/to/root', '/path/to/root/folder', '/path/to/root/folder/file1', '/path/to/root/folder/file2']

>>> cct.get_paths("/path/to/root", filter=lambda path: path.name.startswith("f"))  # Filter paths and return as list[str]
['/path/to/root/folder', '/path/to/root/folder/file1', '/path/to/root/folder/file2']

>>> cct.ls_tree(root="/path/to/root")  # Show folders and files in a tree.
📂 root\
├──📁 folder\
│   ├──📄 file1
│   ├──📄 file2

>>> cct.ls_tree(root="/path/to/root", show_icon=False, ascii=True)  # Show without icons, using ASCII chars.
root/
|-- folder/
|  |-- file1
|  |-- file2

>>> cct.ls_tree(root="/path/to/root", to_visible=lambda path: path.is_dir())  # Show only folders.
📂 root\
├──📁 folder\

>>> cct.ls_tree(root="/path/to/root", to_highlight=lambda path: path.name == "file1")  # Highlight certain file.
📂 root\
├──📁 folder\
│   ├──📄 file1  # highlighted
│   ├──📄 file2

>>> cct.ls_tree(root="/path/to/root", add_suffix=lambda path: "(current)" if pathe.name == "file1" else "")  # Add suffix to path name.
📂 root\
├──📁 folder\
│   ├──📄 file1 (current)
│   ├──📄 file2

>>> cct.show_in_file_manager("/path/to/file")  # Show file in Explorer/Finder/File Manager.

>>> cct.show_in_file_manager("/path/to/file", ask=True)  # Ask before show.

>>> cct.diff("str1", "str2")  # Compare 2 strings, return the list of diffs.
[  # you can use `"\n".join(diff)` to print the diff.
    "-str1",
    "+str2"
]

>>> cct.diff("str1", "str2", meta=True)  # show meta data in the first 3 lines.
[
    "--- <class 'str'>",
    "+++ <class 'str'>",
    "@@ -1 +1 @@",
    "-str1",
    "+str2"
]


>>> cct.diff(["a", "b"], ["a", "b", "c"])  # Compare 2 lists and print diffs.
[
    "+c"
]

>>> cct.diff(["a", "b"], ["a", "b", "c"], context=2)  # Show diffs with 2 extra context lines.
[
    " a",  # context line
    " b",  # context line
    "+c"  # diff
]

>>> cct.diff("/path/to/file1", "/path/to/file2")  # Compare between 2 files.

>>> cct.diff("/path/to/file1", "str")  # Compare between file and str/list.

>>> cct.diff('str', 'str')  # If no diff, return [].
[]

>>> cct.update_file('file', 'http://file-url')  # Update file if the file is not as same as url content.
False  # if already up-to-date.

>>> cct.read_file('file')  # Read file using different encoding automatically.
"file content"

>>> cct.move_file("/path/to/src", "/path/to/dst")  # Move file from src to dst, overwrite if dst already exists.

>>> cct.move_file("/path/to/src", "/path/to/dst", copy=True)  # Copy file from src to dst.

>>> cct.move_file("/path/to/src", "/path/to/dst", backup=True)  # Backup dst file before move or copy.

>>> cct.move_file("/path/to/src", "/path/to/dst", ensure=True)  # Ensure the dst dir exists before move or copy.

>>> cct.move_file("/path/to/src", "/path/to/dst", msgout=print)  # Use `print` to handle output logs.

>>> cct.copy_file("/path/to/src", "/path/to/dst")  # Copy file from src to dst. Same as `move_file(src, dst, copy=True)`.

>>> cct.ajax('http://ajax-url')  # Start a AJAX request.
{'result': 'data'}  # As python dict.

>>> cct.ajax('http://ajax-url', {'data': 'value'})  # AJAX request with param.
{'result': 'data'}

>>> cct.ajax('http://ajax-url', method='post')  # AJAX request using post. default is 'get'.
{'result': 'data'}

>>> if not cct.is_admin():  # Check does the script has admin privileges.
...     cct.runas_admin(__file__)  # run the script with admin privileges.
... else:
...     # your code here

Metadata

Release files for consolecmdtools 6.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for consolecmdtools 6.8.0
File Size Uploaded
consolecmdtools-6.8.0.tar.gz 21.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for consolecmdtools 6.8.0
File Interpreter ABI Platform
consolecmdtools-6.8.0-py3-none-any.whl Python 3 none any Details

Total release size: 36.5 kB

Release files / consolecmdtools-6.8.0.tar.gz

Download URL consolecmdtools-6.8.0.tar.gz
Size 21.2 kB
Tags Source
SHA-256 checksum
How to use checksums
10f7a146bb75f1bd42b6a238c9acca04d8cb137d3f0be79929f76d12f06c3675
BLAKE2b-256 checksum
How to use checksums
16866589b37165861dba081e0ea0caaf67bb5b797fde3e1443185fcffdfd0c8c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Release files / consolecmdtools-6.8.0-py3-none-any.whl

Download URL consolecmdtools-6.8.0-py3-none-any.whl
Size 15.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
46cd797cf7dae1c22828601e309ffcd77f46aa6543501ef5de8150b769cf4a81
BLAKE2b-256 checksum
How to use checksums
a932d4cab6dc056251175ef34d8cd7911c9e36e34f9db7492dd659208241d234
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Release history Release notifications | RSS feed

6.8.1

2 release files

This release

6.8.0 This release

2 release files

6.7.0

2 release files

6.6.3

2 release files

6.6.2

2 release files

6.6.1

2 release files

6.5.2

2 release files

6.5.1

2 release files

6.5.0

2 release files

6.4.2

2 release files

6.4.0

2 release files

6.3.5

2 release files

6.3.4

2 release files

6.3.3

2 release files

6.3.2

2 release files

6.3.0

2 release files

6.2.0

2 release files

6.1.1

2 release files

6.1.0

2 release files

6.0.3

2 release files

6.0.2

2 release files

6.0.1

2 release files

5.0.0

2 release files

4.1.2

2 release files

4.1.0

2 release files

4.0.1

2 release files

4.0.0

2 release files

3.5.2

2 release files

3.5.1

2 release files

3.4.1

2 release files

3.3.0

2 release files

3.2.5

2 release files

3.2.1

2 release files

3.2.0

2 release files

3.1.0

2 release files

3.0.0

2 release files

2.1.1

2 release files

2.0.1

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page