Skip to main content

Some handy Python tools

Project description

pxutil

build-test-publish black-code-style

Some handy Python utilities

A sample to learn Python packaging

Install from source

cd <repo root>
pip install .

python setup.py install (deprecated and problematic)

Build distributions ( Replaced with Actions / cibuildwheel for multiple python versions and platforms)

# build for current python version
rm -rf dist/* && python setup.py sdist bdist_wheel

Build and Test - cibuildwheel locally for current platform

pip install cibuildwheel
# build with docker
cibuildwheel --platform linux . 
# cibuildwheel config in pyproject.toml

Publish to pypi ( Replaced with Actions / cibuildwheel for multiple python versions and platforms)

twine upload dist/*

Github Actions

The github action workflow has been configured to run build, test and publish to pypi with cibuildwheel which builds cython extension for multiple python versions and platforms.

The workflow is configured to run manually, not to waste resources on each commit, or automatically when a release is created.

The publish job is executed only when a release is created.

Usage - Functions

import pxutil as px

# run a command and capture stdout, stderr
r = px.bash('ls')
print(r.stdout)

# run a command like bash -x, not capture stdout, stderr
px.bashx('ls')

# shell alike grep
px.grep('ab','abc\ndef')

# normalize a path, by default no symlink resolution
px.normal_path('~/project/src/../README.rst')

px.trim_docstring('''
    ab
        cd
    ef
    '''
    )

# change work directory
with px.set_work_path("~") as p:
    os.listdir()

# import any module in a path
conf = px.import_any('~/config/config1.py')
print(conf.server_ip)

# exit program if return value is an exception
@px.exit_on_exception
def to_int(any):
    if isinstance(any, dict):
        return Exception('dict is not supported to convert to int.')
    return int(any)

# bespoke request, return decoded content or Exception if any error
# compatible with requests.request parameters
px.request()
NB: This logs requests and responses to files if log level is DEBUG, and log level and directory 
can be configured via environment variable PX_LOG_LEVEL (DEBUG) and PX_LOG_DIR.

# shorthand of px.request('POST',...)
px.post()

# set up loggers
px.setup_logger()

# read classic .env file w/o ini section headers, e.g. docker compose .env, and return a dict
# alternative to package dotnet
px.read_dotenv(file_path='.env')

Usage - CLI

px.chat -h      # chat cli based on chatGPT
px.onefile -h   # alternative to files-to-prompt, but hand crafted. See --tldr for examples.
px.runc -h      # compile and run single c file with gcc
px.ls.mod -h    # list content of a module/package: submodules, classes, functions.
px.loop -h      # run a command in loop

Test

git clone https://github.com/peterjpxie/pxutil.git
cd pxutil
pip3 install -r tests/requirements.txt

# current python version
pytest 

# or 
# multiple python versions
tox 

# or
# multiple python versions in docker
cibuildwheel --platform linux . 

Note some tests are not reliable, e.g. test_post depending on server https://httpbin.org, and moved to manual_test_xx.py to avoid CI failure. Please run them manually as follows.

pytest tests/manual_test_pxutil.py

Places to Update Supported Python Versions

setup.py        # pypi description
tox.ini         # tox test
pyproject.toml  # cibuildwheel

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

pxutil-0.0.50.tar.gz (78.5 kB view details)

Uploaded Source

Built Distributions

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

pxutil-0.0.50-cp314-cp314-win_amd64.whl (41.5 kB view details)

Uploaded CPython 3.14Windows x86-64

pxutil-0.0.50-cp314-cp314-musllinux_1_2_x86_64.whl (119.9 kB view details)

Uploaded CPython 3.14musllinux: musl 1.2+ x86-64

pxutil-0.0.50-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (121.0 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

pxutil-0.0.50-cp314-cp314-macosx_11_0_arm64.whl (41.6 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pxutil-0.0.50-cp313-cp313-win_amd64.whl (40.8 kB view details)

Uploaded CPython 3.13Windows x86-64

pxutil-0.0.50-cp313-cp313-musllinux_1_2_x86_64.whl (120.7 kB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

pxutil-0.0.50-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (121.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

pxutil-0.0.50-cp313-cp313-macosx_11_0_arm64.whl (41.4 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pxutil-0.0.50-cp312-cp312-win_amd64.whl (41.5 kB view details)

Uploaded CPython 3.12Windows x86-64

pxutil-0.0.50-cp312-cp312-musllinux_1_2_x86_64.whl (126.5 kB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

pxutil-0.0.50-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (127.8 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

pxutil-0.0.50-cp312-cp312-macosx_11_0_arm64.whl (42.1 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pxutil-0.0.50-cp311-cp311-win_amd64.whl (41.1 kB view details)

Uploaded CPython 3.11Windows x86-64

pxutil-0.0.50-cp311-cp311-musllinux_1_2_x86_64.whl (121.0 kB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

pxutil-0.0.50-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (121.4 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

pxutil-0.0.50-cp311-cp311-macosx_11_0_arm64.whl (41.9 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pxutil-0.0.50-cp310-cp310-win_amd64.whl (41.1 kB view details)

Uploaded CPython 3.10Windows x86-64

pxutil-0.0.50-cp310-cp310-musllinux_1_2_x86_64.whl (115.3 kB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

pxutil-0.0.50-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (115.7 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

pxutil-0.0.50-cp310-cp310-macosx_11_0_arm64.whl (42.0 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file pxutil-0.0.50.tar.gz.

File metadata

  • Download URL: pxutil-0.0.50.tar.gz
  • Upload date:
  • Size: 78.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pxutil-0.0.50.tar.gz
Algorithm Hash digest
SHA256 522fe22661dad3a302b00ae8394939f0876071b72f25732c46f4e279d32c29c7
MD5 459f972af544fa2d796676fb5c50ec5f
BLAKE2b-256 d9887ae7b65b200a888d6e51a0fcc5657e2e2ee68c2d8b886bde2e743f028f01

See more details on using hashes here.

File details

Details for the file pxutil-0.0.50-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: pxutil-0.0.50-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 41.5 kB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pxutil-0.0.50-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 bff0e531bb7f9958c1c7fa6fa7dca997be9f493a2cd064488eef0594ade98d3a
MD5 47ddcfc88fc3d9cc9de7a82c75d56e52
BLAKE2b-256 0d35764251f4bad5b789c391b44d5d493c0ef87d937ab042cc003bb0912b513f

See more details on using hashes here.

File details

Details for the file pxutil-0.0.50-cp314-cp314-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pxutil-0.0.50-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 8f9b546bcf4ba1c14b3f82e6a3fa00fb7c19fbd41f2128566812232b9c1f525b
MD5 d19c26650db984f7318b27b89004f087
BLAKE2b-256 da590629439020fa6ede12ef11cdbe7ef21e0fbbd59b8880e3f6e78c2a12f12a

See more details on using hashes here.

File details

Details for the file pxutil-0.0.50-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for pxutil-0.0.50-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 e02ab3c2e30dfc2b3e9d8df6109fe0530fe110972ff03027d7188a33a6143539
MD5 badf7c6d00f93cb97bbb049c610d66f0
BLAKE2b-256 03d51df0deaadfb52c50e9f0aee0646e3624959819d074bc3854ec93ef701b8a

See more details on using hashes here.

File details

Details for the file pxutil-0.0.50-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pxutil-0.0.50-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 71c399c41c84dccab4828b7f60b8933563afaef6dd6bb06bd3561b97d01a2c6c
MD5 409de624345d0895d2f329a3c7200a9a
BLAKE2b-256 cfb35277158e8416ab591354c8c7bb8f74dba0d127abd6a698f6b1901ad154b1

See more details on using hashes here.

File details

Details for the file pxutil-0.0.50-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: pxutil-0.0.50-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 40.8 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pxutil-0.0.50-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 076422f752a9facff133c66256bfc1d1071f65ee85b565ed1439375057c7d4ab
MD5 d831daf2796862dac6b405f788314175
BLAKE2b-256 fb45ab83285c7a368c738b1312632925dad3aea2c52098bd530e15fe6467c73e

See more details on using hashes here.

File details

Details for the file pxutil-0.0.50-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pxutil-0.0.50-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 ad4df4dfe53dbf64441f1b1eee8de6f4c0fd77bbce499c3dcd53f63bf98f5ea5
MD5 c921c5e8d74030c1813e25f3632246b2
BLAKE2b-256 8d548fac060c1642a1f95d148d8766376577c127ff6016e912e7c6cababd9213

See more details on using hashes here.

File details

Details for the file pxutil-0.0.50-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for pxutil-0.0.50-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 fb96e71688ee99f90667b03edde2997ee5261ebd61202939a9e4c9dfed94cd8b
MD5 d8d5b2438b32a4490a2755f24654ae6a
BLAKE2b-256 7f6fa637996c3269f6965ee9fc6632f01bfe3ad95a76187311fb44a3923d4d95

See more details on using hashes here.

File details

Details for the file pxutil-0.0.50-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pxutil-0.0.50-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 334af145320e315972f88d39af75fa1b62bfb1e5e66e1a92a214749c673f6cf1
MD5 0cc29922048b9b8bc08be224ba37df95
BLAKE2b-256 2b2a1a7519da8f1ba3e53096c672df9543c2c75beb8585b9f8bb14060c8caec1

See more details on using hashes here.

File details

Details for the file pxutil-0.0.50-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: pxutil-0.0.50-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 41.5 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pxutil-0.0.50-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 e46af79d67d016b5217ac46df9ab90f30a3cdafcf8b125ff7bbf5fcda7cbde8b
MD5 b542ab74c41abf9585eb91a4fc9becc6
BLAKE2b-256 d5f457440038337d51a84b0e1ced448f5d93940d16ca251ffe109fdadbcf7503

See more details on using hashes here.

File details

Details for the file pxutil-0.0.50-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pxutil-0.0.50-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 6d10c104166d9e8d23ef309685a1ff2c626d88787ee220cefb406e23c9206305
MD5 bb12c59cb17bdcbba95e4783ae06ebae
BLAKE2b-256 5884ee798421007931ab506c3ab1b271eb0ee484dff9223c005bb445b5a22615

See more details on using hashes here.

File details

Details for the file pxutil-0.0.50-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for pxutil-0.0.50-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 c16308cd40a264682ebfa0ad1426bc22493947e429e4b15f2a12e884e9d03da3
MD5 70b368ebf76516d32d20f813642e4ef7
BLAKE2b-256 2bf38db4b3f7d8e5934c024e5266c16a0a3bc20b8260eca1703ce87979cd82b0

See more details on using hashes here.

File details

Details for the file pxutil-0.0.50-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pxutil-0.0.50-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 568c86b610d5505b18fbc58431dd12a80acb4f55d967d857166c0c423d5b592d
MD5 d6a7bc8560f4dd7d903b4c10cafd6aae
BLAKE2b-256 d1e387a9c320d5b01ba9e4f26244879be2fe36bc497f9d033db6f3ec10fce6d9

See more details on using hashes here.

File details

Details for the file pxutil-0.0.50-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: pxutil-0.0.50-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 41.1 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pxutil-0.0.50-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 d59e3c0287ee2f0612484b1a59bbf1ad73061bf90e8cc508a67f6e6a49b9d0f4
MD5 8612d2e8f25b6b8afa0c216a7a4df9e8
BLAKE2b-256 6e7da4e87cdee13290b8fab8f5d70baaade435866dedbdf49de3cb0cc2ab2cfa

See more details on using hashes here.

File details

Details for the file pxutil-0.0.50-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pxutil-0.0.50-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5d9ca16845bd22dfef8b3569e2c28aa0e9b9e1023879a995c410b18c10f40f36
MD5 9b3783e2650ca9fefd0c9591194f76af
BLAKE2b-256 d7f29e017cedab1d34b478581f627295053e1067ab7fa3435b622b433c69e2ae

See more details on using hashes here.

File details

Details for the file pxutil-0.0.50-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for pxutil-0.0.50-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 b9f18fe8fcadd3de3a4bbe22371f6c2dd3f815d3be87875f25a10fa8b0fa25f3
MD5 588010afaf6ee7780fe6faac4e148ecf
BLAKE2b-256 6ef44c3f4a094911fabdd97164052e184923e64902855f69af87857a9f67bfab

See more details on using hashes here.

File details

Details for the file pxutil-0.0.50-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pxutil-0.0.50-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 41d30963cb93c635c75c66124367d72953b5adaff591e51eb94d2538c9ac6a3d
MD5 9868bf6be6ba8e616f8abe2801d96a24
BLAKE2b-256 4d3c312f82c5f62d17ad2775d79ae02871d240c923a81dc36e3eb10bc631f118

See more details on using hashes here.

File details

Details for the file pxutil-0.0.50-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: pxutil-0.0.50-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 41.1 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pxutil-0.0.50-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 745897e523a48d32ba36bb497c3c4d947477d6c0b3c029ef9464f2724af972d3
MD5 1be0a2c4ad2d165dbbf2880bba11d1ce
BLAKE2b-256 76f7f7c0506d3a30dd6fb19895e2385574af80f68a3be47b13140fba7e2ceaa3

See more details on using hashes here.

File details

Details for the file pxutil-0.0.50-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pxutil-0.0.50-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 481e2d8abe8cdecb4792b39be041c7d53eb914928204084eec0a2583139f7dc8
MD5 b1cb3af8c151689a3c0145cbcbe5e419
BLAKE2b-256 b201401080a2373a4377485f5718398834c9d16c92a2632b7495a9e124870a83

See more details on using hashes here.

File details

Details for the file pxutil-0.0.50-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for pxutil-0.0.50-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 196b6a6a2a757d48622923d442cd9cf734747ad5e4af28b90ab1b59ca0c7b338
MD5 ce1b3fd64f992c29dbb554ee4a16f614
BLAKE2b-256 cff0850bf817fd23eb9438b052627a6bfc476bd7b5ae5ae5bdb31a306ffd4fb0

See more details on using hashes here.

File details

Details for the file pxutil-0.0.50-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pxutil-0.0.50-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 71366f9e72426ef5a01d4795a1dd53052604ef17bab49ec8f408777cc0447989
MD5 7f669daa41419d2fcde9b778c05314d1
BLAKE2b-256 db1d889431e8a5746be3b09e06db74636cdaf462e307752998a8bc7353f91eb3

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