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.49.tar.gz (78.4 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.49-cp314-cp314-win_amd64.whl (41.4 kB view details)

Uploaded CPython 3.14Windows x86-64

pxutil-0.0.49-cp314-cp314-musllinux_1_2_x86_64.whl (119.8 kB view details)

Uploaded CPython 3.14musllinux: musl 1.2+ x86-64

pxutil-0.0.49-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (120.9 kB view details)

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

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

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

pxutil-0.0.49-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.49-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (121.7 kB view details)

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

pxutil-0.0.49-cp313-cp313-macosx_11_0_arm64.whl (41.3 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

pxutil-0.0.49-cp312-cp312-musllinux_1_2_x86_64.whl (126.4 kB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

pxutil-0.0.49-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (127.7 kB view details)

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

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

pxutil-0.0.49-cp311-cp311-musllinux_1_2_x86_64.whl (120.9 kB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

pxutil-0.0.49-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (121.3 kB view details)

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

pxutil-0.0.49-cp311-cp311-macosx_11_0_arm64.whl (41.8 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pxutil-0.0.49-cp310-cp310-win_amd64.whl (41.0 kB view details)

Uploaded CPython 3.10Windows x86-64

pxutil-0.0.49-cp310-cp310-musllinux_1_2_x86_64.whl (115.2 kB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

pxutil-0.0.49-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (115.6 kB view details)

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

pxutil-0.0.49-cp310-cp310-macosx_11_0_arm64.whl (41.9 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: pxutil-0.0.49.tar.gz
  • Upload date:
  • Size: 78.4 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.49.tar.gz
Algorithm Hash digest
SHA256 608b2e5f4a3d54af6bf76061eaf64bae173a787adfbf08556974e367f1c02fc5
MD5 e62cdc76e3f6bbd6ea7838bba730f9bc
BLAKE2b-256 5257160c1704bb4e7b9d90ae3d82eab684cba302b11ba9c9e70b75effb8d736f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pxutil-0.0.49-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 41.4 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.49-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 6061bff1fa0b9cc9242849a247edf04aa42386306636d22fc69317fcd19c3858
MD5 4759d983c2db9fbf9fae643ccf1ef683
BLAKE2b-256 f0435ad5547bfaab6adc12bf2e58855f1ed063dc5c3249482ff072caefe2e115

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pxutil-0.0.49-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d325d397b028e546e5148f7b80f50df0b07c38a48d0ce997bc63c1f64f912842
MD5 84454d58fd0bc3fb5289a8aad58ece71
BLAKE2b-256 36698be066a02934f5205d5e3a95ed04251eeb6758f1443af23c26f572c69cd8

See more details on using hashes here.

File details

Details for the file pxutil-0.0.49-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.49-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 2b83e846447034d32c9e51b5f3a0d0e18913e1c896d6dd4da77b2eddd29184d6
MD5 3f48cc187b38ebe406fe1cc5b3de5a0a
BLAKE2b-256 3e832d3e9196afb8b4ba932ade62fc9aa25c58e858959ac9b92afd963a6fc2d6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pxutil-0.0.49-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b81b71a5bfd41c6c558ed24fee1744a56d1977cd77835362152035173ce01895
MD5 424995797926485db4d13755bbde86dc
BLAKE2b-256 a16b8fa18914775c9d4bc74caee4a1575690ec9aee223e22229caa158af034b6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pxutil-0.0.49-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.49-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 f8c4b005d6d1d8603bd287249ad3a352ac2d4307838a4e8bff29446c2cc78e32
MD5 f4571e8a68ade6b81aa6699ea8d87beb
BLAKE2b-256 70466e14a3a4b9ae2303a9e84561f645dc175a748ec96ff34cefce85e2837759

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pxutil-0.0.49-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 a58674391f3d8ecfab202d7aaaa756c7b2a150a95788f23b4f1f961047cc361c
MD5 0103565e0e09040885a10130a17deae7
BLAKE2b-256 a7726726a09eec9dc94fca12155ba2c59f419ebeda7452e6f2f8fd3642e296e2

See more details on using hashes here.

File details

Details for the file pxutil-0.0.49-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.49-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 ee8f64ab865ecb4bcdccb09ffaa32e69186355dd310a05238f3cfe0711b9504b
MD5 32c6eea01994747b5284abd5350c8ec5
BLAKE2b-256 08c05a504b53e14230c33c8314d209033830f384af3a9103d9199ac0e73b7aad

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pxutil-0.0.49-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3866ad248bb0c499a295981f67ed5168bbd9aa3ed0533cbb9618166cee94ff5a
MD5 76b5061659f76e1392563ec42193d78f
BLAKE2b-256 bafe544002e3e474dfd0b600c94bbf9f3c2563a85b598be74dfbe6908e37220d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pxutil-0.0.49-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.49-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 ebbfb108427d4517ea9a5d58ddf2a71d187b711847947069957ab43e1125ee3e
MD5 73cc87077e14f9db696d9ecf14d1c4ea
BLAKE2b-256 53fa87eff1c0a2464e544adbecd2a5f6346ce91ed09d38ad1be802e59f65d3ac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pxutil-0.0.49-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 e64e8557598ee66a28b1c843b52ad05cae153cddcbf407c9c2efe985f63a55fe
MD5 7d0485569db1d375aa48d2da350fd2a8
BLAKE2b-256 ebd47e416e8c8ed6068e5b19cdb3d46a67905669c7bdb62d1a249f9d4ce4b15d

See more details on using hashes here.

File details

Details for the file pxutil-0.0.49-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.49-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 140ea5dab231ea6df47334cc4447f5d1b3b780d46e3fa4cf26d28c922e51d731
MD5 4aa5add7bee6dff19ff86a0f9f236a8b
BLAKE2b-256 3c5683486e8519ee6f1f70a0244dcf71dfffb7174c99f3f1b08b0437e09c006c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pxutil-0.0.49-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 948b82fb33fec815c494fdc86dd76688be9b7cb9203f231aeacd79bdf4edfc96
MD5 efc4b69bf3a72a66a5f1589e4d513ffa
BLAKE2b-256 f4ea4013d054c20c11265fb19f82f59d6cd99643444609092b77095687c70820

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pxutil-0.0.49-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.49-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 05d570875b1be44b0416609354958fc266b14da2342f6dab440f3a91f4a88617
MD5 46d30b5d6c80eeda5df537ce9f09d958
BLAKE2b-256 c7d7558491603e9b957aa695ce7d03cc187f4493cf0132d97161f2c0232e9f9d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pxutil-0.0.49-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 a938ab0ba0a3dee0a4a721d67f26bad3b4a1bf40391588acb898a7266cb2cd8d
MD5 1f9a1299cb7d320c41b8c509e2c44ce8
BLAKE2b-256 44c699111e16c1c086b1aa50d094650373a90fcbbcd7e6bd296fbd44e2e667f9

See more details on using hashes here.

File details

Details for the file pxutil-0.0.49-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.49-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 a5de37593dcfe6afdeb9655817f43e3e11aeb80e5af724c1f40eeed444307bb7
MD5 445733870b1a6527d0faf8bba0d5ce94
BLAKE2b-256 e0edce2cc57785a08b277f5cf2937acf52731b4360facf6a55ccbb7770d2dca3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pxutil-0.0.49-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 da041c8f7ff9dd759f44206509c1ccc7282ac1e12b43410c379ba94f5a6d6d89
MD5 bafdeefd7cc15b9e23017ef7323e3108
BLAKE2b-256 5080a5ed5d8491a493218868cf29709ebb3c036f89a6eab6d5466a8811e60d3d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pxutil-0.0.49-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 41.0 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.49-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 6102d3aba585655e10f98c60f253858c689d6c9390910b7af93d47b1a375284e
MD5 e24854e2cc4e0c4eaec9de54d9d1ee07
BLAKE2b-256 0492a64e9cc8dcef79a5504c2b7b879feeffe4e513a4dfa3aba56e4324d857c2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pxutil-0.0.49-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 ed45406b96de65311049d4953a5bc4b6c5b3703fa8f6b59b50f4b8a21be007ac
MD5 37af2a9c1256c5f4e549aa0f24310831
BLAKE2b-256 e9956eec95a877d7854f60e75af0d1e888af5e96d223cdcf50e885333fcfafb4

See more details on using hashes here.

File details

Details for the file pxutil-0.0.49-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.49-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 f490429180bcf469d68f50ab846f6cdd586ff777efa648684f07b9e5b4d12f39
MD5 35d82471e9ede23f3d051417fae575a7
BLAKE2b-256 9a7b73e0e33ada20870a997cebe9e2f2d8515d091df1461b7e477c0a23dd7b1c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pxutil-0.0.49-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e5c4f2c0134fb9e94ee44f18e1efa5e31a582df8771e6acea2dcd7550f43d3f7
MD5 112bbf03fa94e3e98a629af10a3b0567
BLAKE2b-256 0e27361b07805b2f39c11ee0901afb3e4f1dd8d1e2e9933f90c0c720d9a0ca55

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