Skip to main content

PyShared

PyShared is a Python utility library providing a collection of functions and constants I've found useful across multiple projects.

It also has several common aliases I use for typehints and common imports.

Installation

To incorporate PyShared into your project, use pip for installation:

pip install pyshared
# To include development dependencies:
pip install pyshared[dev]

Feature Overview

args.py

consts.py

  • ALPHANUMERIC_CHARS: A string of alphanumeric characters.
  • ALPHANUMERIC_EXT_CHARS: Alphanumeric characters, including underscores and hyphens.

crypto.py

  • is_jwt: Simply verifies if a string looks like a JSON Web Token (JWT)

env.py

  • typed_evar: Retrieves and type-casts environment variables.

Examples: (input, default, type, expected_output)

'evname, ev, default, vartype, expected',
    # with default arg
    ('evname', '0', 0, None, 0),
    # this shouldnt ever happen but if it does, it should raise error
    (None, None, '20.1', int, ValueError),
    (None, None, None, float, ValueError),
    # assumed typing
    ('evname', '0.0', None, None, 0.0),
    ('evname', '0.', None, None, '0.'),
    ('evname', '.0', None, None, 0.0),
    ('evname', 'True', None, None, True),
    ('evname', 'tRuE', None, None, True),
    ('evname', 'false', None, None, False),
    ('evname', 'fAlSe', None, None, False),
    ('evname', '0', None, None, 0),
    ('evname', '0', True, None, False),
    ('evname', '0', False, None, False),
    ('evname', '0', None, bool, True),
    ('evname', '0', None, int, 0),
    ('evname', '0', 1.0, float, 0.0),
    ('evname', '0', None, float, 0.0),
    ('evname', 'true', None, str, 'true'),
    ('evname', 'test', True, None, ValueError),
    ('evname', 'test', None, int, ValueError),
    ('evname', 'test', 1, None, ValueError),

exceptions.py

  • NotPrintableError: Both str and repr methods raised exceptions.

python.py

  • HumanTime: A class for converting seconds to human-readable time strings.
  • UniqueList: A list that only allows unique elements.
  • default_repr: Generates a default representation for custom objects.
  • htime: A function for converting seconds to human-readable time strings.
  • ranstr: Creates random strings of specified length and character set.
  • safe_repr: Safely returns the object's repr/str or an error string without throwing exceptions if the object is not printable.
  • tmp_pythonpath: Adds a temporary directory to the Python path for the duration of a context manager.
  • truncstr: Truncates a string, preserving a portion from the start and/or end.

pytest.py

  • multiscope_fixture: Creates multiple scoped pytest fixture and ensures the fixtures are available in the module.

shell.py

Shell command execution within Python.

  • runcmd: Executes a command in the system shell.

terminal.py

Terminal utilities for improved user interaction.

  • get_terminal_width: Safely retrieves the terminal width, defaulting to 80 columns on failure.
  • print_middle: Centers text within left/right padding based on terminal width.
  • print_columns: Arranges a list of strings into guestimated $x length strings based on what is approximately optimal for the contents/terminal width.

tests.py

  • RanData: A class for generating random data for testing purposes.

Test Coverage

not quite 100% lol

---------- coverage: platform darwin, python 3.9.18-final-0 ----------
Name                     Stmts   Miss  Cover   Missing
------------------------------------------------------
pyshared/__init__.py        17      0   100%
pyshared/consts.py           3      0   100%
pyshared/crypto.py          21      0   100%
pyshared/env.py             34      3    91%   30, 42, 54
pyshared/exceptions.py       8      0   100%
pyshared/pytest.py          12      0   100%
pyshared/python.py          69      3    96%   40, 63, 139
pyshared/shell.py            9      0   100%
pyshared/terminal.py        34      0   100%
pyshared/test.py            54      0   100%
pyshared/version.py          1      0   100%
------------------------------------------------------
TOTAL                      262      6    98%

License

MIT

Contact

ccarterdev@gmail.com

Metadata

Release files for pyshared 1.6.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyshared 1.6.1
File Size Uploaded Provenance Actions
pyshared-1.6.1.tar.gz 15.1 kB Without provenance Details for pyshared-1.6.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyshared 1.6.1
File Interpreter ABI Platform Actions
pyshared-1.6.1-py3-none-any.whl Python 3 none any Details for pyshared-1.6.1-py3-none-any.whl

Total release size: 30.3 kB

Release files / pyshared-1.6.1.tar.gz

Download URL pyshared-1.6.1.tar.gz
Size 15.1 kB
Tags Source
SHA-256 checksum
How to use checksums
e95f33ff6dcf7d12f89a90f060e9964b9e3b49991c7eb629682f0742dde1ea4f
BLAKE2b-256 checksum
How to use checksums
c683b505d0a66c0edd1067c2a76ab5ad7e2e9a1107fb28f1bdf4d44d5a9e178e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.11.7

Release files / pyshared-1.6.1-py3-none-any.whl

Download URL pyshared-1.6.1-py3-none-any.whl
Size 15.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b2b5513710bb1ba7c6b6385017a2b08a4ab338d64e414f6aedd7b26d1e782bd8
BLAKE2b-256 checksum
How to use checksums
c525d4f462e5c22e7cbe56a025c1266a7c0d2fc2f0d2d397f9ea71979a67aabc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.11.7

Security for pyshared 1.6.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page