Skip to main content

Boxine - bx_py_utils

Various Python utility functions

Quickstart

pip install bx_py_utils

Existing stuff

Here only a simple list about existing utilities. Please take a look into the sources and tests for deeper informations.

bx_py_utils.anonymize

  • anonymize() - Anonymize the given string with special handling for eMail addresses.

bx_py_utils.auto_doc

  • assert_readme() - Check and update README file with generate_modules_doc()
  • generate_modules_doc() - Generate a list of function/class information via pdoc.

bx_py_utils.aws.client_side_cert_manager

  • ClientSideCertManager() - Helper to manage client-side TLS certificate via AWS Secrets Manager by

bx_py_utils.aws.secret_manager

  • SecretsManager() - Access AWS Secrets Manager values

bx_py_utils.compat

  • removeprefix() - Backport of removeprefix from PEP-616 (Python 3.9+)
  • removesuffix() - Backport of removesuffix from PEP-616 (Python 3.9+)

bx_py_utils.dict_utils

  • dict_get() - nested dict get()
  • pluck() - Extract values from a dict, if they are present

bx_py_utils.environ

  • cgroup_memory_usage() - Returns the memory usage of the cgroup the Python interpreter is running in.

bx_py_utils.error_handling

  • print_exc_plus() - Print traceback information with a listing of all the local variables in each frame.

bx_py_utils.graphql_introspection

  • introspection_query() - Generate GraphQL introspection query with variable nested depth.

bx_py_utils.hash_utils

  • url_safe_encode() - Encode bytes into a URL safe string.
  • url_safe_hash() - Generate a URL safe hash with max_size from given string/bytes.

bx_py_utils.humanize.pformat

  • pformat() - Format given object: Try JSON fist and fallback to pformat()

bx_py_utils.humanize.time

  • human_timedelta() - Converts a time duration into a friendly text representation.

bx_py_utils.iteration

  • chunk_iterable() - Returns a generator that yields slices of iterable of the given chunk_size.

bx_py_utils.path

  • assert_is_dir() - Check if given path is a directory
  • assert_is_file() - Check if given path is a file

bx_py_utils.processify

  • processify() - Decorator to run a function as a process.

bx_py_utils.stack_info

  • FrameNotFound() - Base class for lookup errors.
  • last_frame_outside_path() - Returns the stack frame that is the direct successor of given "file_path".

bx_py_utils.test_utils.assertion

  • assert_equal() - Check if the two objects are the same. Display a nice diff, using pformat()
  • assert_text_equal() - Check if the two text strings are the same. Display a error message with a diff.
  • pformat_ndiff() - Generate a ndiff from two objects, using pformat()
  • pformat_unified_diff() - Generate a unified diff from two objects, using pformat()
  • text_ndiff() - Generate a ndiff between two text strings.
  • text_unified_diff() - Generate a unified diff between two text strings.

bx_py_utils.test_utils.datetime

  • parse_dt() - Helper for easy generate a datetime instance via string.

bx_py_utils.test_utils.filesystem_utils

  • FileWatcher() - Helper to record which new files have been created.

bx_py_utils.test_utils.mock_aws_secret_manager

  • SecretsManagerMock() - Mock for bx_py_utils.aws.secret_manager.SecretsManager()

bx_py_utils.test_utils.mock_boto3session

  • MockedBoto3Session() - Mock for boto3.session.Session()

bx_py_utils.test_utils.requests_mock_assertion

  • assert_json_requests_mock() - Check the requests history.

bx_py_utils.test_utils.snapshot

Assert complex output via auto updated snapshot files with nice diff error messages.

  • assert_py_snapshot() - Assert complex python objects vio PrettyPrinter() snapshot file.
  • assert_snapshot() - Assert given data serialized to JSON snapshot file.
  • assert_text_snapshot() - Assert "text" string via snapshot file

bx_py_utils.test_utils.time

  • MockTimeMonotonicGenerator() - Helper to mock time.monotonic() in tests.

Backwards-incompatible changes

v36 -> v37 - Outsourcing Django stuff

We split bx_py_utils and moved all Django related utilities into the separated project:

So, bx_py_utils is better usable in non-Django projects, because Django will not installed as decency of "bx_py_utils"

developing

To start developing e.g.:

~$ git clone https://github.com/boxine/bx_py_utils.git
~$ cd bx_py_utils
~/bx_py_utils$ make
help                 List all commands
install-poetry       install or update poetry
install              install via poetry
update               Update the dependencies as according to the pyproject.toml file
lint                 Run code formatters and linter
fix-code-style       Fix code formatting
tox-listenvs         List all tox test environments
tox                  Run pytest via tox with all environments
tox-py36             Run pytest via tox with *python v3.6*
tox-py37             Run pytest via tox with *python v3.7*
tox-py38             Run pytest via tox with *python v3.8*
tox-py39             Run pytest via tox with *python v3.9*
pytest               Run pytest
pytest-ci            Run pytest with CI settings
publish              Release new version to PyPi
clean                Remove created files from the test project

License

MIT. Patches welcome!

Metadata

Release files for bx-py-utils 38

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

Source distribution (sdist)

Source distribution for bx-py-utils 38
File Size Uploaded
bx_py_utils-38.tar.gz 18.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bx-py-utils 38
File Interpreter ABI Platform
bx_py_utils-38-py3-none-any.whl Python 3 none any Details

Total release size: 40.7 kB

Release files / bx_py_utils-38.tar.gz

Download URL bx_py_utils-38.tar.gz
Size 18.5 kB
Tags Source
SHA-256 checksum
How to use checksums
a2e492ef0d6fc8441bf2a84825f13d197305aa09ce797833f2a23b6d5ab83981
BLAKE2b-256 checksum
How to use checksums
1fbb49e99741924c847d5b0e7ba8885329b38ceaea2682d0b06fecea2291a371
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.3.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.5

Release files / bx_py_utils-38-py3-none-any.whl

Download URL bx_py_utils-38-py3-none-any.whl
Size 22.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5cd6d1d1758c5cc96d17b3f42ea289c59d2d94740bc2a33d7dae88bde6022b99
BLAKE2b-256 checksum
How to use checksums
fe61eb7aa6b9f2ce7ee92af0d064d46165b36b38b4d63f37a4242d823210e565
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.3.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.5

Release history Release notifications | RSS feed

121

2 release files

120

2 release files

119

2 release files

118

2 release files

116

2 release files

115

2 release files

114

2 release files

113

2 release files

111

2 release files

110

2 release files

109

2 release files

108

2 release files

106

2 release files

105

2 release files

104

2 release files

103

2 release files

102

2 release files

101

2 release files

100

2 release files

99

2 release files

98

2 release files

97

2 release files

96

2 release files

95

2 release files

94

2 release files

93

2 release files

92

2 release files

91

2 release files

90

2 release files

89

2 release files

88

2 release files

87

2 release files

86

2 release files

85

2 release files

84

2 release files

83

2 release files

82

2 release files

81

2 release files

80

2 release files

79

2 release files

78

2 release files

76

2 release files

75

2 release files

74

2 release files

73

2 release files

72

2 release files

71

2 release files

70

2 release files

69

2 release files

68

2 release files

67

2 release files

66

2 release files

65

2 release files

64

2 release files

63

2 release files

62

2 release files

61

2 release files

60

2 release files

59

2 release files

58

2 release files

57

2 release files

56

2 release files

55

2 release files

54

2 release files

53

2 release files

52

2 release files

51

2 release files

50

2 release files

49

2 release files

47

2 release files

46

2 release files

45

2 release files

44

2 release files

43

2 release files

42

2 release files

41

2 release files

40

2 release files

39

2 release files

This release

38 This release

2 release files

37

2 release files

36

2 release files

35

2 release files

34

2 release files

33

2 release files

32

2 release files

31

2 release files

30

2 release files

29

2 release files

28

2 release files

27

2 release files

26

2 release files

25

2 release files

24

2 release files

23

2 release files

22

2 release files

21

2 release files

20

2 release files

19

2 release files

18

2 release files

17

2 release files

16

2 release files

15

2 release files

14

2 release files

13

2 release files

12

2 release files

11

2 release files

10

2 release files

9

2 release files

8

2 release files

7

2 release files

5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

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