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

# install from pypi
pip install pxutil

# install from source in edit mode
cd <repo root>
pip install -e .

Usage - CLI

px.chat -h      # chat cli based on X.AI and OpenAI APIs
px.onefile -h   # alternative to files-to-prompt, but hand crafted. See --tldr for examples.
px.token.counter -h # count LLM tokens of a give text file
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

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')

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 on PR, manually or when a release is created.

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

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

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/*

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.51.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.51-cp314-cp314-win_amd64.whl (41.5 kB view details)

Uploaded CPython 3.14Windows x86-64

pxutil-0.0.51-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.51-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.51-cp314-cp314-macosx_11_0_arm64.whl (41.6 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

pxutil-0.0.51-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.51-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.51-cp313-cp313-macosx_11_0_arm64.whl (41.4 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

pxutil-0.0.51-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.51-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.51-cp312-cp312-macosx_11_0_arm64.whl (42.1 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

pxutil-0.0.51-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.51-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.51-cp311-cp311-macosx_11_0_arm64.whl (41.9 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

pxutil-0.0.51-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.51-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.51-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.51.tar.gz.

File metadata

  • Download URL: pxutil-0.0.51.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.51.tar.gz
Algorithm Hash digest
SHA256 9bc19c8f8421a75f06b12fa750fa4bf953db5f6917f4926bee0809e5beb4a236
MD5 686f84394829bf7c3e354a4873bc9d6b
BLAKE2b-256 6e191bdcce8daa9ebf498e89c4c1fab0130a4881488b130aac7843e111f44f35

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pxutil-0.0.51-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.51-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 99f83913643105faf8f310ddfc5ddb46a4d3c912b24d0dd7e9420f473ceca041
MD5 132cb28577bc660fbbe05c20e4d40374
BLAKE2b-256 7fb19322b7487133edda5395f614cedcf221526eca0485df4771143a391f1606

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pxutil-0.0.51-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 30b33e2c52f9ee14e3b39fd74713fcf6ec7b97871bec217c1ece839a23bf2771
MD5 1e248e93b2d47eebbc510b4319be08bd
BLAKE2b-256 d32bbe805720c712f118e97de62038a3abd858f2ae2b81e1294522150840e1fb

See more details on using hashes here.

File details

Details for the file pxutil-0.0.51-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.51-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 c9915e846d808a8c298aa1805c8e98f2a36f30f9493828d345ec78c0620cbc6c
MD5 f6eb4e4c176e77d28529f2cb4d317aa1
BLAKE2b-256 4d99ac238b02e5186d85055704ae8f022bcc9ec20e58adaf8520b944ef56fbc4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pxutil-0.0.51-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 29e6b4ab4e912370d5544a0227959c09f89ae12c0812801e08839b6cc804daf1
MD5 bd43e00f7f70f67bcdec67eaff8c3bda
BLAKE2b-256 81d13cb974c5b6b81b5d5fa0fae8a400c1e70a5de38c52cc4428043c7eb864d5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pxutil-0.0.51-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.51-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 0b37b4b688762400ac2a7410d49d9bd37685bca427484690be35f1ae5b33a948
MD5 8d81129596c449c77b0b457a800c21b5
BLAKE2b-256 732a35122cf20a257de2a93ecaaf891c88c9028429fdb94747047e8d19e2f26d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pxutil-0.0.51-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 18e3392e1727c75e86e589991501dd46595d1977f14e5de5bd5057fb44ee9698
MD5 0658485c7c2239fb6e506aac712954b8
BLAKE2b-256 94f3ee56dd172ae15c5a6dc044be4d4bd0ccdb0b35a3aa8a83dde3cbac5a3913

See more details on using hashes here.

File details

Details for the file pxutil-0.0.51-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.51-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 ca41197a0d42bc258f93eea1c4855663c4619bf87c8608e0865e724297a435a6
MD5 f0bdbbd26e9e6aac5b7355d525749c9e
BLAKE2b-256 655b2f044bb06d8766b06364b26d217c752d2b51e2e827ab315ddf893b6aaba6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pxutil-0.0.51-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7b86805acfdb5e328bfd1b87768266161f1dd4634ea19d4fc3097403e9cd08fe
MD5 bdc5ef875c9c9e9eea0cfdacf221d566
BLAKE2b-256 d25a55867f5bc9b31cbc1bc0ed088044e8ad52283344b9571510cb10cd0e313b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pxutil-0.0.51-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.51-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 dfa579071752e5d334d76ca7684e12f18122ecabd497a4b679e5bbd6d124d931
MD5 7bce9850df99eede449839fbe5a9a3f4
BLAKE2b-256 f0a4e940376f1fd04b8167a2065a42e362760d4d3dbb43b846cbaebc57026009

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pxutil-0.0.51-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 a3082d4e8e0bf9a163b7ccb7fac1119ef4f43277f9b48285d48b2c59299c3288
MD5 d751b773b3238fe8eb3910044a8f83a8
BLAKE2b-256 82a21c217c8db48d9bb51bb0b1386262b8a84462ce9d7141eebe46e808589de3

See more details on using hashes here.

File details

Details for the file pxutil-0.0.51-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.51-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 56b71f00463cd82a2cc7c0c3be43d1f30483391434f30a54e6cd30412bf9412f
MD5 21b865b553b6ec232878b2f4717fcd48
BLAKE2b-256 8922e9886abd3f78e384dbec873d383ff9029240f3e01da25c653768d74a3238

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pxutil-0.0.51-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c9e4d68a4fcdcea30a79c9172e2d9c9a7bae617111fd674b7418f70bf3d8117b
MD5 3f45dced1240ab03cf0cfe9137477230
BLAKE2b-256 87a7acd7f01f415185441a26f989a6a25475e8df978b064d16627e5b84389a5e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pxutil-0.0.51-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.51-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 7171e9e58ca8ce923c2c270f640b3c7fb80576bcba8c456cc2096ed0dd125dc4
MD5 1e505019bd64e769e299a8c8b46cd559
BLAKE2b-256 c1f05f3095e34fb9ed047393fbf2e123e545910d25234b25f274ad3e7aa0019e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pxutil-0.0.51-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 79b2a152db948ba38f70018018491c0e1ebae2c10fd00ce53a23c345bb1b4963
MD5 10d46ccb4b9fb3a5b1be82436b74b882
BLAKE2b-256 b30c50387802bcd685038a362f1d8fca00b5207f8c273d5a3d8d65351c13d4eb

See more details on using hashes here.

File details

Details for the file pxutil-0.0.51-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.51-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 979098a186fd6eef9ef37aa6b5ac6b8f393f6900316731c6eaec7b7914b9e6b3
MD5 abafee26d5a7f7971fe1f2b0c5a6a5c9
BLAKE2b-256 431de0bd69e0c65541e123fc4fb92d2e3049079e14f2b5a2a2872218963738a2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pxutil-0.0.51-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 50e2a07613f7b92e2f0766c8c7594fa2fe677f2bdbe51f11fedf091832105641
MD5 b4292cc25abfa70845c34ed460c33c77
BLAKE2b-256 0f22481de8cbd3458d5f1dcfe63ee9301108403f0cef7d9ad282afbf97256ad5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pxutil-0.0.51-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.51-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 af9e2bafd1b32c4c475abf4faeec8f3a5632583f39d8f5c7c61c3f15f7b8a7f1
MD5 c521d86dba0d15632e985379a73f9104
BLAKE2b-256 32afff2a9d15e63aaf0fb50f34613a042e5a1066b22335c78dc47f998984aca2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pxutil-0.0.51-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 ed96e863a1481ec34e27bf2b03af3d307cb0b016857f1aff31255a598a9a2e23
MD5 b92545348de6d847fdada8d555efd2b3
BLAKE2b-256 f3bb9e4cd290ecc02f93e5aa8f1c93b7dc2a18ee38045207c670a50282717687

See more details on using hashes here.

File details

Details for the file pxutil-0.0.51-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.51-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 e694bae99f719bd04e93bb29bd89d8c434647a75d2564827c5fffdd4a1d8165b
MD5 97384a5dd5cc373cf9bfafc7058aa3f2
BLAKE2b-256 f7ff69a560cecbcc4e7e23c8e6e35168668d9ec30ebb884ecb60a41b7ed7f928

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pxutil-0.0.51-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1c4a190b628bcce228e1525d30ac2f083f0f2809e680882025fa01f1350e2742
MD5 a6d95e5f423a3218b85cba8a1eaa1c44
BLAKE2b-256 37f6a96a3f251f791eeb432d40e10a240dd2b9eee45bb0d8db99f5c96a9cfb08

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