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.52.tar.gz (78.6 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.52-cp314-cp314-win_amd64.whl (41.5 kB view details)

Uploaded CPython 3.14Windows x86-64

pxutil-0.0.52-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.52-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (121.1 kB view details)

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

pxutil-0.0.52-cp314-cp314-macosx_11_0_arm64.whl (41.7 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pxutil-0.0.52-cp313-cp313-win_amd64.whl (40.9 kB view details)

Uploaded CPython 3.13Windows x86-64

pxutil-0.0.52-cp313-cp313-musllinux_1_2_x86_64.whl (120.8 kB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

pxutil-0.0.52-cp312-cp312-win_amd64.whl (41.6 kB view details)

Uploaded CPython 3.12Windows x86-64

pxutil-0.0.52-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.52-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.52-cp312-cp312-macosx_11_0_arm64.whl (42.2 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pxutil-0.0.52-cp311-cp311-win_amd64.whl (41.2 kB view details)

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

pxutil-0.0.52-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.52-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.52-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.52.tar.gz.

File metadata

  • Download URL: pxutil-0.0.52.tar.gz
  • Upload date:
  • Size: 78.6 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.52.tar.gz
Algorithm Hash digest
SHA256 b6443558449c783132294348637ab0f03f8fccd305a62895224d5b215819536e
MD5 cc1bc665a04b660d4cd2d39ffce2d4c2
BLAKE2b-256 4f477325041dfbf734ef8a99235704788db554c549d2f4b42f1429ca49693041

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pxutil-0.0.52-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.52-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 27dc277c6fe0628181f99772c0149fbd6e8a166d0fcb68e7e2cc26f557b66458
MD5 fbf75fcd1b8454fbaf7e915942d6f0a3
BLAKE2b-256 7a8033edee2b000c1e047e52b7ab6681c7406e1918e488b420153febdff91e0c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pxutil-0.0.52-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 451a38b0b58d521808ba9f9a895045fa57df0937266ab8dd4d2f8ac9262760ca
MD5 f61bc3680fcba9a078fef853b70ae6a9
BLAKE2b-256 435908ab80d5aa170258b18f0858d3f7c9576ac847da758d90c737c93f78629b

See more details on using hashes here.

File details

Details for the file pxutil-0.0.52-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.52-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 2ecae0d79a544b4b519a56a225fddbb197ff861bad7f539f1168370e402ea01b
MD5 353b0a1754ce8e57da3f24029391a88e
BLAKE2b-256 869b8e282425c10725534cd5e4dc5f01d1579e4bfc66d71910ae21ae3a36e152

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pxutil-0.0.52-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 65237c8e690d6d6380a4c12677ccf9f23087f3a86ff03053517bec727311a746
MD5 798bc06e12a77f5c2c0bfdac5b16af96
BLAKE2b-256 b10fdc14e00721f62dcd3817e9e4eb9c17d621f909b4fd3149508c395bb9304b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pxutil-0.0.52-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 40.9 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.52-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 e9a55f8fdfe54e0272c22d57ef6d0d3e90296cdb36bf7ade384d017dae31e42f
MD5 8cb7be58250705127804427ebd7a1391
BLAKE2b-256 ae70e5e1f41170500334118e72bc5dc53f48496fd1787284d024f04f807ead99

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pxutil-0.0.52-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 79e68e4724a8d8e6933212f2c00dcdbb404f16719e50eb9d2e5e4a66c929feb8
MD5 2ecf439e390f94f1acfd8e2e3cff19f7
BLAKE2b-256 25560162e0a061a329bdff17c338f7d5e459936de2503ff4c1de858176725b77

See more details on using hashes here.

File details

Details for the file pxutil-0.0.52-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.52-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 3ee8533b988625e316bb60cfeb277215fa1be340467ccceab98d1d141fab5f09
MD5 fed190a7e7183a5406c4d179898e5444
BLAKE2b-256 861c0e4851b689e3ca984b218b6055a23d50fcbb6e426792c9b04a09b6b29465

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pxutil-0.0.52-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5a2d004b311fded8f398f582403defd44855454fe4adde41d3e6abaeaa77872f
MD5 756e2b051de082c38739316516a912ef
BLAKE2b-256 8d87260b59c687b548c206aba9bfee2fe18cb6827256e8761f891afc0c5d7c81

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pxutil-0.0.52-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 41.6 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.52-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 d7cd9a011dcbd7ac997bf8cb253cd48eb8b7b14407ecc93bc2efd25a2a90dbc0
MD5 a8835ecbc267a9f6540c222ab4b62e29
BLAKE2b-256 7a8cecea2fe198cc5b853225ab3ea7a65ae78f1e80650dc3b0247ca7bd4a005e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pxutil-0.0.52-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 9631a254ae964718775f58bfc83a670655780e065c215ab7e84d07eb59c049ed
MD5 22ad7d8235df395358cf89ff813c8957
BLAKE2b-256 ff5f12532e70373bba8f2ecb6b12025eeeaeaff518214178973fbe9b3c3ab9a4

See more details on using hashes here.

File details

Details for the file pxutil-0.0.52-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.52-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 8f75ba83b3264b371ffeb5bacafe59fbf9c0bed8f71beb1e98e57d4f47666697
MD5 a532c26d019a521566af8e412b3b3241
BLAKE2b-256 b01e72bb270a878c6f0c5145506ce28239d369236176aaa2d2be2567633c2088

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pxutil-0.0.52-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 557bf99d6a60e9a2e44624744d456c1f7c0af779f419d783769587addce26dfa
MD5 ff651c66f59674a9a82d9eed547c0843
BLAKE2b-256 30013df6fe5ae3966b18f6288917a4fb47bddf80c5a39bfe9b6f0106d2abad08

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pxutil-0.0.52-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 41.2 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.52-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 7140480f4b4c1f9d8ae1e2f7ca8e21de0802115c8eaf21c54768cbc2190a8965
MD5 b54cccf201a245313a91286089411045
BLAKE2b-256 6931327c2c125f064090b75b7c6be3b6b0505939256b07361ca7fbc2d243c3ef

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pxutil-0.0.52-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5829d1be383f3069ef4d815260c9ad82c9cd3e04b48236d3a11ce1cce57d5fd0
MD5 23c6fda268fd01a0314d9994e6030e59
BLAKE2b-256 0b2395848e434192577cb9c00955fcbdd757b323c5b2f513a1b97969edf1e081

See more details on using hashes here.

File details

Details for the file pxutil-0.0.52-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.52-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 3bdfcb286111fa6021a2cc1d9bda25b4cead829fab6bdc31d259337c54a40375
MD5 2dbb521115b02094784dab0039da2451
BLAKE2b-256 43753308d157a2778bdcf114af63dbc079a1482c26ab0307917ff584e1d820f2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pxutil-0.0.52-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a1dc0041d53a42a72f8a8de2d12fd3468cb94304a25f7c53d15af235b2456df8
MD5 1b74c58fc550d58f3bb28164e228e14e
BLAKE2b-256 1a341c05b8b8d27c3121de697dbfa209e6fe5fd6f477c0b23034a575851585fe

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pxutil-0.0.52-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.52-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 85cd4571069c6669239f0d39dddce8d59db27a7bf147e007bc14a6c25ec381d1
MD5 044cef0a6a2a51dedd9d32e5d2190198
BLAKE2b-256 3e3cc058143786bd9cc2792df30cd3f417b927c7d8ead280f90e7548a524a462

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pxutil-0.0.52-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 6ccadd1dcd5509e1b2d7c045f905912f159a9561c56840d719cf4cceef59bd4f
MD5 c04ad0f700ecff84fdfb0a48c807249e
BLAKE2b-256 1bb737233f5481cca5eff6ee418ff3eb6f5563d60c41ca32570ce3971333605e

See more details on using hashes here.

File details

Details for the file pxutil-0.0.52-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.52-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 c118bc70dc5a4edd0de3b24dd014a726693e7b2aab88f71a791709c5e9f44e8d
MD5 58bc58205398d146f5293343f4fe4120
BLAKE2b-256 f822d2c5c8a573205b08bb4bd6ba0f7049bc5722b3c940e866375f1371038b02

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pxutil-0.0.52-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8add8f68e83d39e27974f1c0f1c9e7e5d59fda2e0c09c04f1da9fd8a81a3a1a3
MD5 6693ba23b1cb10998c8ea696585b5d8c
BLAKE2b-256 2238ff71fe6de330e91cef5f1a6cdfe97bd46c4e3963a065df84b5ee4d3d5df1

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