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.48.tar.gz (78.0 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.48-cp314-cp314-win_amd64.whl (41.2 kB view details)

Uploaded CPython 3.14Windows x86-64

pxutil-0.0.48-cp314-cp314-musllinux_1_2_x86_64.whl (119.6 kB view details)

Uploaded CPython 3.14musllinux: musl 1.2+ x86-64

pxutil-0.0.48-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (120.7 kB view details)

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

pxutil-0.0.48-cp314-cp314-macosx_11_0_arm64.whl (41.3 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pxutil-0.0.48-cp313-cp313-win_amd64.whl (40.5 kB view details)

Uploaded CPython 3.13Windows x86-64

pxutil-0.0.48-cp313-cp313-musllinux_1_2_x86_64.whl (120.5 kB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

pxutil-0.0.48-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (121.5 kB view details)

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

pxutil-0.0.48-cp313-cp313-macosx_11_0_arm64.whl (41.1 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pxutil-0.0.48-cp312-cp312-win_amd64.whl (41.2 kB view details)

Uploaded CPython 3.12Windows x86-64

pxutil-0.0.48-cp312-cp312-musllinux_1_2_x86_64.whl (126.2 kB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

pxutil-0.0.48-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (127.5 kB view details)

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

pxutil-0.0.48-cp312-cp312-macosx_11_0_arm64.whl (41.8 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pxutil-0.0.48-cp311-cp311-win_amd64.whl (40.8 kB view details)

Uploaded CPython 3.11Windows x86-64

pxutil-0.0.48-cp311-cp311-musllinux_1_2_x86_64.whl (120.7 kB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

pxutil-0.0.48-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (121.1 kB view details)

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

pxutil-0.0.48-cp311-cp311-macosx_11_0_arm64.whl (41.6 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pxutil-0.0.48-cp310-cp310-win_amd64.whl (40.8 kB view details)

Uploaded CPython 3.10Windows x86-64

pxutil-0.0.48-cp310-cp310-musllinux_1_2_x86_64.whl (115.0 kB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

pxutil-0.0.48-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (115.4 kB view details)

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

pxutil-0.0.48-cp310-cp310-macosx_11_0_arm64.whl (41.7 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: pxutil-0.0.48.tar.gz
  • Upload date:
  • Size: 78.0 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.48.tar.gz
Algorithm Hash digest
SHA256 54b317d8710555597e2fab115ee659696e6c8dbba8b1038cbf8b80d8b1cea916
MD5 3837f6d95c3c1c238cefddb9b5181788
BLAKE2b-256 c4b109f81c448ff1e3a591321dc1755dd37b0db3fcfb4b13f0e81fd1195e9036

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pxutil-0.0.48-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 41.2 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.48-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 cbf03fe4e585581494245f2b9d7030f0ee303e39bcc6e24c3d5ee95087490136
MD5 3af345ae0a72a7580452d8d62fa4971c
BLAKE2b-256 f2cf1d6c3262d6cd860ff799a6b8526158aba17232978789e2af05cd38730142

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pxutil-0.0.48-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 62d0f09fa5be0363de995917f835a28ba4a63348f2293e27ae2627cdb29dc64e
MD5 6f6e9affbb5282f59ccff6da97f0404d
BLAKE2b-256 b02f447e85652c263e92a5aa0dd3be5665a14c67d01973d304f15aee8aa5b352

See more details on using hashes here.

File details

Details for the file pxutil-0.0.48-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.48-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 23a3df631ffded1b013bbd015a86744d5d60551e06c6d64139800bc4d889ab05
MD5 1d2f005f620aa0fc7d34c3f7669bc892
BLAKE2b-256 1f457d7a495b027e9405c030de0f5df9803b792350e2da94f5ecb965ab761e61

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pxutil-0.0.48-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4533a2030c7539e68dd91e3c0340d7ecefb0d9e57007cae6ed1e0d871ccca247
MD5 a57e81cb4a983c32e1260d7e5d8b8744
BLAKE2b-256 31385c09924094e06002e2ad3ee5277c76ea43296ac8eedb952e0fe77894f119

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pxutil-0.0.48-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 40.5 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.48-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 0350ac5cf9d52303c20990cdb3c8ed81e2ede4781e02ad72bfc1b9ef8b66ae75
MD5 3fb7b87f03d6f043a92486118e1454eb
BLAKE2b-256 2e8e991ababa2ceae4f2affe2f88374a8552c38d77348f5e801c11d1734dd898

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pxutil-0.0.48-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d4f44fb0754d0c0b9d0e7332928970d71a270a57dc787529fe31597fa78e65e3
MD5 c16da1eb3665bd9b46bfb4a6be23144b
BLAKE2b-256 30b8557ff45da622ce7dbb5ca709c24c9dfaa24fbbb018456da0c9570dc71af7

See more details on using hashes here.

File details

Details for the file pxutil-0.0.48-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.48-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 0d6457b3a3027f30865bae588525d75abf79ae60c5f6e254867b6d4f7f51dca3
MD5 cd9f1c3b658918054d4c76f145208a94
BLAKE2b-256 dcf518bcbaac6f494c82fd765c8b78b3532edebe2d94d5a4b21e12916eabbc85

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pxutil-0.0.48-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 35fabac934cc6d68167dc9cda6b33191a3027c3ca72c06eda3db6498cfc2a870
MD5 c60b78fd8ba07f23fd1d3231047e171c
BLAKE2b-256 b6e93617a4aff583e40040dc7f3a8060dc43af4f849e6cac2a29465057fcaaab

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pxutil-0.0.48-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 41.2 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.48-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 e7466aa97e430ffabf930d744e89d99d49ea044014072352f873bae97521a71c
MD5 8552f0d86f59ffe4e167463a4c40a0db
BLAKE2b-256 a61c5c7be349b99af94d534d8664212fd2d5bd3334bd8e8d3a88de58f0e3181e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pxutil-0.0.48-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 586d057557612c1e9dd8515242fed01a4754c0fe6a5b971377eee22cd89d8164
MD5 871cddabde85e36fb7a91eb42c3f314f
BLAKE2b-256 1b80c1359f42c9c8fc6bee117cb2b6d1f6c7ec4e5ba57c748aea0af00291f037

See more details on using hashes here.

File details

Details for the file pxutil-0.0.48-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.48-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 bb62750ea5ff97e721c41aac7cebf8c70315d2e929bff5637638a0ab1cc83916
MD5 25d83178ec9a5b5d7ce7519b1994e9c2
BLAKE2b-256 1216e359de9d9154535c5f6ee81ea087d15ffdaf63e2b862fcdec85168faf194

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pxutil-0.0.48-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 80ad56b86b948d56eb4c8099c84dd7172a93761a02e004c340ad2beb2d02b906
MD5 4cae9ab1f28b0ee07a094662df379be9
BLAKE2b-256 f641a879486c69feca46cb3a22fe7b185e53f697cbb7a4a374f5677ca19f1e18

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pxutil-0.0.48-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 40.8 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.48-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 46f9d1ce92dd08fb60321bf71a6e90fba4fcdd0a9803c9d2e648edfb802bba28
MD5 bf991fa601c46e64666dea8200a3e82d
BLAKE2b-256 6f1a9f5188aa2490a554e4e0bd7e7422a9cb08019cfba6b61d72c07af709e176

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pxutil-0.0.48-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 0f1eb5d55d2d5724433213b98d1acc85f09d561f8ae280a34ce3995502b3febf
MD5 9169c42be14b8436ec5d7d94a7b577ff
BLAKE2b-256 06d523c5728c92b4369b645e3b53016bc6d68ca30d148d7d537703e5cdeb628d

See more details on using hashes here.

File details

Details for the file pxutil-0.0.48-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.48-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 f76cdafcb301c7d7c9cd7155ae750b9435947ffa35bb8cfffbbe561f0f70b463
MD5 85cecb679e5a2d77e15d2b0e6661aabc
BLAKE2b-256 b7e3f24b1263efba9ee97c3ef60c5aa1e95d23496eca755a18636f22a44a5b5a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pxutil-0.0.48-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 abaf04eb3fe38e65a3a0fa80ca1234eabd994d7ed78e9c007e887a7cbe51d52c
MD5 a23714c469c514fc7bc62a1c4b6abffd
BLAKE2b-256 bbbef2b3414a6711a3c398213f0bb8faf25d37076d9aed578bc07b1f84fc9d06

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pxutil-0.0.48-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 40.8 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.48-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 58baf056c0021c355b755c2587e9a6371a37d0470529eb4d5a2802497700f250
MD5 98cf2058c1604e2a9155aaf8081c9c6b
BLAKE2b-256 1cbeda94b1ef938042a39a2a42cd1fb31164fc6812122f7d4fdb632cb9181acf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pxutil-0.0.48-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 b7c661cd68b1a7020afe796d77ccc8e63f0e37f977b9d2131db97f11f85be05f
MD5 ddb0ed937709020dc3adb3599f959721
BLAKE2b-256 a6a0143b11e546e90d3a1987e61cb82cbb50654e8033aa9be16659e36d247d6e

See more details on using hashes here.

File details

Details for the file pxutil-0.0.48-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.48-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 a0904e8bf789bb013521dd328db4ba55fdcf61dfb2712910532648c57bbe9827
MD5 f39a0496b3fbc31e56abd2e612e2ee00
BLAKE2b-256 cb847d61d2ad7209361481e255021db371772e79a124060af9082eed01334dbb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pxutil-0.0.48-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7992a15673d6565e7fd714455d3c24bf233d133436ce1756240d880b29b16dd8
MD5 da5fbad38343216b0e43e1bd73094438
BLAKE2b-256 ef5fb9a73e87a3e3466471848bbffb0ff9f5517817f3c29208109eec2a484072

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