tensorneko-util 0.3.19__tar.gz → 0.3.21__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/PKG-INFO +1 -1
  2. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/README.md +38 -10
  3. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/io/json/json_writer.py +3 -3
  4. tensorneko_util-0.3.21/src/tensorneko_util/msg/__init__.py +9 -0
  5. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/msg/gotify.py +2 -2
  6. tensorneko_util-0.3.21/src/tensorneko_util/msg/postgres.py +66 -0
  7. tensorneko_util-0.3.21/src/tensorneko_util/version.txt +1 -0
  8. tensorneko_util-0.3.19/src/tensorneko_util/visualization/watcher/web/dist/assets/index.901ba3f5.js → tensorneko_util-0.3.21/src/tensorneko_util/visualization/watcher/web/dist/assets/index.6e281472.js +39 -39
  9. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/visualization/watcher/web/dist/index.html +1 -1
  10. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util.egg-info/PKG-INFO +1 -1
  11. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util.egg-info/SOURCES.txt +2 -1
  12. tensorneko_util-0.3.19/src/tensorneko_util/msg/__init__.py +0 -3
  13. tensorneko_util-0.3.19/src/tensorneko_util/version.txt +0 -1
  14. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/setup.cfg +0 -0
  15. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/setup.py +0 -0
  16. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/setup_util.py +0 -0
  17. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/__init__.py +0 -0
  18. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/_rich.py +0 -0
  19. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/backend/__init__.py +0 -0
  20. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/backend/audio_lib.py +0 -0
  21. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/backend/blocking.py +0 -0
  22. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/backend/parallel.py +0 -0
  23. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/backend/tqdm.py +0 -0
  24. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/backend/visual_lib.py +0 -0
  25. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/debug/__init__.py +0 -0
  26. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/debug/logger.py +0 -0
  27. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/debug/parser.py +0 -0
  28. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/io/__init__.py +0 -0
  29. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/io/_default_backends.py +0 -0
  30. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/io/_path_conversion.py +0 -0
  31. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/io/audio/__init__.py +0 -0
  32. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/io/audio/audio_data.py +0 -0
  33. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/io/audio/audio_reader.py +0 -0
  34. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/io/audio/audio_writer.py +0 -0
  35. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/io/hdf5/__init__.py +0 -0
  36. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/io/hdf5/hdf5_reader.py +0 -0
  37. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/io/hdf5/hdf5_writer.py +0 -0
  38. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/io/image/__init__.py +0 -0
  39. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/io/image/image_reader.py +0 -0
  40. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/io/image/image_writer.py +0 -0
  41. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/io/json/__init__.py +0 -0
  42. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/io/json/json_data.py +0 -0
  43. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/io/json/json_reader.py +0 -0
  44. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/io/matlab/__init__.py +0 -0
  45. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/io/matlab/mat_reader.py +0 -0
  46. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/io/matlab/mat_writer.py +0 -0
  47. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/io/npy/__init__.py +0 -0
  48. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/io/npy/npy_reader.py +0 -0
  49. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/io/npy/npy_writer.py +0 -0
  50. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/io/pickle/__init__.py +0 -0
  51. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/io/pickle/pickle_reader.py +0 -0
  52. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/io/pickle/pickle_writer.py +0 -0
  53. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/io/reader.py +0 -0
  54. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/io/text/__init__.py +0 -0
  55. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/io/text/text_reader.py +0 -0
  56. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/io/text/text_writer.py +0 -0
  57. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/io/toml/__init__.py +0 -0
  58. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/io/toml/toml_reader.py +0 -0
  59. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/io/toml/toml_writer.py +0 -0
  60. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/io/video/__init__.py +0 -0
  61. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/io/video/video_data.py +0 -0
  62. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/io/video/video_reader.py +0 -0
  63. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/io/video/video_writer.py +0 -0
  64. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/io/writer.py +0 -0
  65. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/io/yaml/__init__.py +0 -0
  66. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/io/yaml/yaml_reader.py +0 -0
  67. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/io/yaml/yaml_writer.py +0 -0
  68. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/notebook/__init__.py +0 -0
  69. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/notebook/animation.py +0 -0
  70. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/notebook/display.py +0 -0
  71. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/preprocess/__init__.py +0 -0
  72. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/preprocess/crop.py +0 -0
  73. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/preprocess/face_detector/__init__.py +0 -0
  74. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/preprocess/face_detector/_utils.py +0 -0
  75. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/preprocess/face_detector/abstract_face_detector.py +0 -0
  76. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/preprocess/face_detector/anime_face_detector.py +0 -0
  77. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/preprocess/face_detector/facexzoo_face_detector.py +0 -0
  78. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/preprocess/face_detector/opencv_face_detector.py +0 -0
  79. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/preprocess/ffmpeg.py +0 -0
  80. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/preprocess/image.py +0 -0
  81. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/preprocess/video.py +0 -0
  82. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/util/__init__.py +0 -0
  83. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/util/average_meter.py +0 -0
  84. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/util/bimap.py +0 -0
  85. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/util/dispatched_misc.py +0 -0
  86. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/util/dispatcher.py +0 -0
  87. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/util/downloader.py +0 -0
  88. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/util/eventbus/__init__.py +0 -0
  89. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/util/eventbus/bus.py +0 -0
  90. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/util/eventbus/decorator.py +0 -0
  91. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/util/eventbus/event.py +0 -0
  92. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/util/fp/__init__.py +0 -0
  93. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/util/fp/args.py +0 -0
  94. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/util/fp/array/__init__.py +0 -0
  95. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/util/fp/array/abstract_seq.py +0 -0
  96. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/util/fp/array/seq.py +0 -0
  97. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/util/fp/array/stream.py +0 -0
  98. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/util/fp/func.py +0 -0
  99. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/util/fp/monad/__init__.py +0 -0
  100. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/util/fp/monad/eval.py +0 -0
  101. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/util/fp/monad/monad.py +0 -0
  102. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/util/fp/monad/option.py +0 -0
  103. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/util/fp/underscore.py +0 -0
  104. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/util/misc.py +0 -0
  105. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/util/multi_layer_indexer.py +0 -0
  106. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/util/ref.py +0 -0
  107. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/util/registry.py +0 -0
  108. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/util/server.py +0 -0
  109. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/util/singleton.py +0 -0
  110. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/util/timer.py +0 -0
  111. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/util/type.py +0 -0
  112. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/util/window_merger.py +0 -0
  113. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/visualization/__init__.py +0 -0
  114. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/visualization/color.py +0 -0
  115. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/visualization/image_browser/__init__.py +0 -0
  116. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/visualization/image_browser/server.py +0 -0
  117. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/visualization/image_browser/web/index.html +0 -0
  118. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/visualization/matplotlib.py +0 -0
  119. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/visualization/multi_plots.py +0 -0
  120. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/visualization/seaborn.py +0 -0
  121. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/visualization/tensorboard.py +0 -0
  122. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/visualization/watcher/__init__.py +0 -0
  123. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/visualization/watcher/component.py +0 -0
  124. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/visualization/watcher/server.py +0 -0
  125. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/visualization/watcher/view.py +0 -0
  126. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util/visualization/watcher/web/dist/assets/index.cf95019d.css +0 -0
  127. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util.egg-info/dependency_links.txt +0 -0
  128. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util.egg-info/requires.txt +0 -0
  129. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/src/tensorneko_util.egg-info/top_level.txt +0 -0
  130. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/test/test_library_info.py +0 -0
  131. {tensorneko_util-0.3.19 → tensorneko_util-0.3.21}/test/test_version.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tensorneko_util
3
- Version: 0.3.19
3
+ Version: 0.3.21
4
4
  Summary: The Utils for Library TensorNeko.
5
5
  Home-page: https://github.com/ControlNet/tensorneko
6
6
  Author: ControlNet
@@ -12,7 +12,7 @@
12
12
  <div align="center">
13
13
  <a href="https://www.python.org/"><img src="https://img.shields.io/pypi/pyversions/tensorneko?style=flat-square"></a>
14
14
  <a href="https://pytorch.org/"><img src="https://img.shields.io/badge/PyTorch-%3E%3D1.9.0-EE4C2C?style=flat-square&logo=pytorch"></a>
15
- <a href="https://www.pytorchlightning.ai/"><img src="https://img.shields.io/badge/Lightning-2.0.*%20|%202.1.*%20|%202.2.*-792EE5?style=flat-square&logo=lightning"></a>
15
+ <a href="https://www.pytorchlightning.ai/"><img src="https://img.shields.io/badge/Lightning-2.*-792EE5?style=flat-square&logo=lightning"></a>
16
16
  </div>
17
17
 
18
18
  <div align="center">
@@ -49,7 +49,7 @@ pipx install tensorneko_tool # or `pip install tensorneko_tool`
49
49
 
50
50
  Then you can use the CLI tools `tensorneko` in the terminal.
51
51
 
52
- ## Neko Layers, Modules and Architectures
52
+ ## Layers, Modules and Architectures
53
53
 
54
54
  Build an MLP with linear layers. The activation and normalization will be placed in the hidden layers.
55
55
 
@@ -138,7 +138,7 @@ print(f(torch.rand(16)).shape)
138
138
  # torch.Size([1])
139
139
  ```
140
140
 
141
- ## Neko IO
141
+ ## IO
142
142
 
143
143
  Easily load and save different modal data.
144
144
 
@@ -188,7 +188,7 @@ neko.io.write.json("path/to/json.json", json_obj)
188
188
  Besides, the read/write for `mat` and `pickle` files is also supported.
189
189
 
190
190
 
191
- ## Neko preprocessing
191
+ ## Preprocessing
192
192
 
193
193
  ```python
194
194
  import tensorneko as neko
@@ -215,7 +215,7 @@ if `ffmpeg` is available, you can use below ffmpeg wrappers.
215
215
  - `resample_video_fps`
216
216
  - `mp32wav`
217
217
 
218
- ## Neko Visualization
218
+ ## Visualization
219
219
 
220
220
  ### Variable Web Watcher
221
221
  Start a web server to watch the variable status when the program (e.g. training, inference, data preprocessing) is running.
@@ -366,14 +366,14 @@ trainer = neko.NekoTrainer(log_every_n_steps=100, gpus=1, logger=model.name, pre
366
366
  trainer.fit(model, dm)
367
367
  ```
368
368
 
369
- ## Neko Callbacks
369
+ ## Callbacks
370
370
 
371
371
  Some simple but useful pytorch-lightning callbacks are provided.
372
372
 
373
373
  - `DisplayMetricsCallback`
374
374
  - `EarlyStoppingLR`: Early stop training when learning rate reaches threshold.
375
375
 
376
- ## Neko Notebook Helpers
376
+ ## Notebook Helpers
377
377
  Here are some helper functions to better interact with Jupyter Notebook.
378
378
  ```python
379
379
  import tensorneko as neko
@@ -385,7 +385,7 @@ neko.notebook.display.audio("path/to/audio.wav")
385
385
  neko.notebook.display.code("path/to/code.java")
386
386
  ```
387
387
 
388
- ## Neko Debug Tools
388
+ ## Debug Tools
389
389
 
390
390
  Get the default values from `ArgumentParser` args. It's convenient to use this in the notebook.
391
391
  ```python
@@ -401,7 +401,7 @@ print(args.integers) # [1, 2, 3]
401
401
  print(args.accumulate) # <function sum at ...>
402
402
  ```
403
403
 
404
- ## Neko Evaluation
404
+ ## Evaluation
405
405
 
406
406
  Some metrics function for evaluation are provided.
407
407
 
@@ -412,8 +412,36 @@ Some metrics function for evaluation are provided.
412
412
  - `ssim_video`
413
413
  - `ssim_image`
414
414
 
415
+ ## Message (Access to other services)
415
416
 
416
- ## Neko Utilities
417
+ ### Gotify
418
+
419
+ Send a message to the Gotify server.
420
+
421
+ The title, URL and APP_TOKEN is the environment variable `GOTIFY_TITLE`, `GOTIFY_URL` and `GOTIFY_TOKEN`, or overwritten
422
+ in the function arguments.
423
+
424
+ ```python
425
+ from tensorneko.msg import gotify
426
+ gotify.push("This is a test message", "<URL>", "<APP_TOKEN>")
427
+ # then the message will be sent to the Gotify server.
428
+ # title = "<HOST_NAME>", message = "This is a test message", priority = 0
429
+ ```
430
+
431
+ ### Postgres
432
+
433
+ Require the `psycopg` package. Provide one single function to execute one SQL query with a temp connection.
434
+
435
+ The database URL is the environment variable `DB_URL`, or overwritten in the function arguments.
436
+ ```python
437
+ from tensorneko.msg import postgres
438
+ result = postgres.execute("<SQL>", "<DB_URL>")
439
+ # also async version is provided
440
+ result = await postgres.execute_async("<SQL>", "<DB_URL>")
441
+ ```
442
+
443
+
444
+ ## Utilities
417
445
 
418
446
  ### Misc functions
419
447
 
@@ -9,7 +9,7 @@ from .._path_conversion import _path2str
9
9
  class JsonWriter:
10
10
 
11
11
  @staticmethod
12
- def _write_json(path: str, obj: Union[dict, list], encoding: str = "UTF-8", indent: int = 4,
12
+ def _write_json(path: str, obj: Union[dict, list], encoding: str = "UTF-8", indent: int = 2,
13
13
  ensure_ascii: bool = False, fast: bool = True
14
14
  ) -> None:
15
15
  if not fast:
@@ -28,7 +28,7 @@ class JsonWriter:
28
28
  file.write(orjson.dumps(obj, option=option))
29
29
 
30
30
  @classmethod
31
- def to(cls, path: Union[str, Path], obj: Union[dict, list, object], encoding: str = "UTF-8", indent: int = 4,
31
+ def to(cls, path: Union[str, Path], obj: Union[dict, list, object], encoding: str = "UTF-8", indent: int = 2,
32
32
  ensure_ascii: bool = False, fast: bool = True
33
33
  ) -> None:
34
34
  """
@@ -68,7 +68,7 @@ class JsonWriter:
68
68
  else:
69
69
  raise TypeError("Not implemented type. Only support dict, list, json_data.")
70
70
 
71
- def __new__(cls, path: Union[str, Path], obj: Union[dict, list, object], encoding: str = "UTF-8", indent: int = 4,
71
+ def __new__(cls, path: Union[str, Path], obj: Union[dict, list, object], encoding: str = "UTF-8", indent: int = 2,
72
72
  ensure_ascii: bool = False, fast: bool = True
73
73
  ) -> None:
74
74
  """Alias of :meth:`~tensorneko.io.json.json_writer.JsonWriter.to`."""
@@ -0,0 +1,9 @@
1
+ from . import gotify
2
+
3
+ __all__ = ["gotify"]
4
+
5
+ try:
6
+ from . import postgres
7
+ __all__.append("postgres")
8
+ except ImportError:
9
+ pass
@@ -6,7 +6,7 @@ from typing import Optional
6
6
  from urllib.error import HTTPError
7
7
 
8
8
 
9
- def push_gotify(message: str, url: Optional[str] = None, token: Optional[str] = None, title: Optional[str] = None,
9
+ def push(message: str, url: Optional[str] = None, token: Optional[str] = None, title: Optional[str] = None,
10
10
  priority: int = 0
11
11
  ):
12
12
  """
@@ -21,7 +21,7 @@ def push_gotify(message: str, url: Optional[str] = None, token: Optional[str] =
21
21
 
22
22
  Examples::
23
23
 
24
- push_gotify("This is a test message", "<URL>", "<APP_TOKEN>")
24
+ push("This is a test message", "<URL>", "<APP_TOKEN>")
25
25
  # then the message will be sent to the Gotify server.
26
26
  # title = "<HOST_NAME>", message = "This is a test message", priority = 0
27
27
 
@@ -0,0 +1,66 @@
1
+ import os
2
+ from typing import Any, List, Optional, Tuple
3
+
4
+ import psycopg
5
+
6
+
7
+ def execute(sql: str, db_url: Optional[str] = None) -> Optional[List[Tuple[Any, ...]]]:
8
+ """
9
+ Execute a PostgreSQL database SQL query.
10
+
11
+ Args:
12
+ sql (``str``): The SQL query to be executed.
13
+ db_url (``str``, optional): The URL of the PostgreSQL database. The default value is environment variable DB_URL.
14
+
15
+ Returns:
16
+ ``list[tuple] | None``: The result of the query. If the query is not a SELECT query, then it will return None.
17
+
18
+ Examples::
19
+
20
+ result = execute("SELECT * FROM table_name", "postgresql://user:password@localhost:5432/db_name")
21
+ # then the result will be a list of tuples.
22
+
23
+ execute("INSERT INTO table_name (column1, column2) VALUES (value1, value2)", "postgresql://user:password@localhost:5432/db_name")
24
+ # then the execute will be executed and committed.
25
+ """
26
+ db_url = db_url or os.environ.get("DB_URL")
27
+
28
+ with psycopg.Connection.connect(db_url) as conn:
29
+ with conn.cursor() as cur:
30
+ cur.execute(sql)
31
+ conn.commit()
32
+ if cur.description:
33
+ return cur.fetchall()
34
+ return None
35
+
36
+
37
+ async def execute_async(sql: str, db_url: Optional[str] = None) -> Optional[List[Tuple[Any, ...]]]:
38
+ """
39
+ Execute a PostgreSQL database SQL query with async.
40
+
41
+ Args:
42
+ sql (``str``): The SQL query to be executed.
43
+ db_url (``str``, optional): The URL of the PostgreSQL database. The default value is environment variable DB_URL.
44
+
45
+ Returns:
46
+ ``list[tuple] | None``: The result of the query. If the query is not a SELECT query, then it will return None.
47
+
48
+ Examples::
49
+
50
+ result = await execute_async("SELECT * FROM table_name", "postgresql://user:password@localhost:5432/db_name")
51
+ # then the result will be a list of tuples.
52
+
53
+ await execute_async("INSERT INTO table_name (column1, column2) VALUES (value1, value2)")
54
+ # then the execute will be executed
55
+ """
56
+ db_url = db_url or os.environ.get("DB_URL")
57
+
58
+ if db_url is None:
59
+ raise ValueError("DB_URL environment variable is not set.")
60
+
61
+ async with await psycopg.AsyncConnection.connect(db_url, autocommit=True) as conn:
62
+ async with conn.cursor() as cur:
63
+ await cur.execute(sql)
64
+ if cur.description:
65
+ return await cur.fetchall()
66
+ return None