YoungLion 0.0.1__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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Cavanshipro
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,588 @@
1
+ Metadata-Version: 2.1
2
+ Name: YoungLion
3
+ Version: 0.0.1
4
+ Summary: It is a library whose main purpose is to make the work of YoungLion developers easier.
5
+ Author: Cavanşir Qurbanzadə
6
+ Author-email: cavanshirpro@gmail.com
7
+ License: MIT
8
+ Keywords: YoungLion,Young Lion,Cavanshirpro
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3.7
13
+ Classifier: Programming Language :: Python :: 3.8
14
+ Classifier: Programming Language :: Python :: 3.9
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Requires-Python: >=3.7
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Requires-Dist: yaml
21
+ Requires-Dist: PyPDF2
22
+ Requires-Dist: reportlab
23
+ Requires-Dist: requests
24
+ Requires-Dist: pytesseract
25
+ Requires-Dist: Pillow
26
+ Requires-Dist: moviepy
27
+ Requires-Dist: matplotlib
28
+ Requires-Dist: numpy
29
+ Requires-Dist: librosa
30
+ Requires-Dist: soundfile
31
+ Requires-Dist: plotly
32
+ Requires-Dist: tqdm
33
+ Requires-Dist: ffmpeg-python
34
+
35
+ # Young Lion Python Library
36
+
37
+ The **Young Lion Python Library** is designed to simplify the work of developers, especially *Young Lion Developers*. This library provides a wide range of functionalities for handling various file formats, managing directories, and executing file-related operations efficiently.
38
+
39
+ This library is under development and will be expanded with more features in the future.
40
+
41
+ ---
42
+
43
+ ## Modules
44
+
45
+ ### `function`
46
+ The `function` module contains a versatile `File` class that provides advanced file manipulation capabilities. The class supports operations for file formats such as JSON, TXT, CSV, PDF, XML, YAML, INI, Markdown, HTML, and more.
47
+ ### `VISTA`
48
+ `VISTA` stands for (Visual Information System and Technological Analysis). This module contains the functions required to create Visual, Video, Audio and Analytical tables.
49
+ ---
50
+ # YoungLion function
51
+ ## File Class
52
+
53
+ The `File` class includes methods for handling various file types and operations with robust error handling, flexible path management, and default value support. Below is a breakdown of the supported features:
54
+
55
+ ### Supported File Formats
56
+ - `.json`, `.txt`, `.log`, `.pdf`, `.xml`, `.csv`
57
+ - `.yml`, `.yaml`, `.ini`, `.properties`, `.md`, `.rtf`
58
+ - `.html`, `.css`, `.js`
59
+
60
+ ### Key Functionalities
61
+ #### Initialization
62
+ - **`__init__(filefolder: Optional[str])`**
63
+ - Initializes the `File` object with an optional root directory for default path handling.
64
+
65
+ #### JSON File Operations
66
+ - **`json_read(path: str, default: Optional[dict]) -> dict`**
67
+ - Reads JSON data into a dictionary. Creates a file if missing.
68
+ - **`json_write(path: str, data: dict)`**
69
+ - Writes a dictionary to a JSON file.
70
+
71
+ #### TXT File Operations
72
+ - **`txt_read_str(path: str) -> str`**
73
+ - Reads a text file as a single string.
74
+ - **`txt_write_str(path: str, content: str)`**
75
+ - Writes string content to a text file.
76
+
77
+ #### CSV File Operations
78
+ - **`csv_read(path: str, delimiter: str = ',', quotechar: str = '"') -> List[Dict[str, str]]`**
79
+ - Reads a CSV file into a list of dictionaries.
80
+ - **`csv_write(path: str, data: List[Dict[str, str]], fieldnames: Optional[List[str]])`**
81
+ - Writes a list of dictionaries to a CSV file.
82
+
83
+ #### PDF File Operations
84
+ - **`pdf_read(path: str) -> str`**
85
+ - Reads text from a PDF file.
86
+ - **`pdf_write(path: str, content: str)`**
87
+ - Writes text content to a PDF file.
88
+
89
+ #### XML File Operations
90
+ - **`xml_read(path: str) -> Optional[Dict[str, Any]]`**
91
+ - Reads an XML file and parses it into a dictionary.
92
+ - **`xml_write(path: str, data: Dict[str, Any])`**
93
+ - Writes a dictionary to an XML file.
94
+
95
+ #### YAML and INI Operations
96
+ - **`yaml_read(path: str, default: Optional[dict]) -> dict`**
97
+ - Reads YAML content into a dictionary.
98
+ - **`ini_read(path: str, default: Optional[Dict[str, Dict[str, str]]]) -> Dict[str, Dict[str, str]]`**
99
+ - Reads INI files into a dictionary structure.
100
+
101
+ #### Markdown Operations
102
+ - **`md_read(path: str) -> str`**
103
+ - Reads a Markdown file.
104
+ - **`md_write(path: str, content: str, append: bool)`**
105
+ - Writes or appends content to a Markdown file.
106
+
107
+ #### SQL Operations
108
+ - **`sql_execute(path: str, query: str, params: tuple)`**
109
+ - Executes SQL queries on a database file.
110
+
111
+ #### Compressed File Handling
112
+ - **`handle_compressed(path: str, action: str, target: Optional[str])`**
113
+ - Compresses directories or extracts files from archives.
114
+
115
+ ---
116
+
117
+ ## Installation
118
+ To include the library in your project:
119
+ 1. Clone this repository.
120
+ 2. Import the module:
121
+ ```python
122
+ from YoungLion.function import File
123
+ ```
124
+
125
+ ---
126
+
127
+ Here is the complete example section for all functions in the **File** class. These examples are ready to be included in your README file.
128
+
129
+ ---
130
+
131
+ ## Usage Examples
132
+
133
+ Below are examples for using each function in the `File` class.
134
+
135
+ ### JSON File Operations
136
+
137
+ #### `json_read`
138
+ ```python
139
+ file_handler = File()
140
+
141
+ # Reading a JSON file
142
+ default_data = {"name": "Unknown", "age": 0}
143
+ data = file_handler.json_read("data.json", default=default_data)
144
+ print(data)
145
+ ```
146
+
147
+ #### `json_write`
148
+ ```python
149
+ # Writing to a JSON file
150
+ data_to_save = {"name": "John", "age": 30}
151
+ file_handler.json_write("data.json", data_to_save)
152
+ ```
153
+
154
+ ### TXT File Operations
155
+
156
+ #### `txt_read_str`
157
+ ```python
158
+ # Reading text from a file
159
+ content = file_handler.txt_read_str("example.txt")
160
+ print(content)
161
+ ```
162
+
163
+ #### `txt_write_str`
164
+ ```python
165
+ # Writing text to a file
166
+ file_handler.txt_write_str("example.txt", "Hello, World!")
167
+ ```
168
+
169
+ ### CSV File Operations
170
+
171
+ #### `csv_read`
172
+ ```python
173
+ # Reading a CSV file
174
+ csv_data = file_handler.csv_read("data.csv")
175
+ print(csv_data)
176
+ ```
177
+
178
+ #### `csv_write`
179
+ ```python
180
+ # Writing to a CSV file
181
+ csv_content = [{"name": "Alice", "age": "25"}, {"name": "Bob", "age": "30"}]
182
+ file_handler.csv_write("data.csv", csv_content, fieldnames=["name", "age"])
183
+ ```
184
+
185
+ ### PDF File Operations
186
+
187
+ #### `pdf_read`
188
+ ```python
189
+ # Reading a PDF file
190
+ pdf_text = file_handler.pdf_read("example.pdf")
191
+ print(pdf_text)
192
+ ```
193
+
194
+ #### `pdf_write`
195
+ ```python
196
+ # Writing to a PDF file
197
+ file_handler.pdf_write("example.pdf", "This is a sample PDF content.")
198
+ ```
199
+
200
+ ### XML File Operations
201
+
202
+ #### `xml_read`
203
+ ```python
204
+ # Reading XML content
205
+ xml_data = file_handler.xml_read("data.xml")
206
+ print(xml_data)
207
+ ```
208
+
209
+ #### `xml_write`
210
+ ```python
211
+ # Writing to an XML file
212
+ xml_content = {"person": {"name": "Alice", "age": "25"}}
213
+ file_handler.xml_write("data.xml", xml_content)
214
+ ```
215
+
216
+ ### YAML File Operations
217
+
218
+ #### `yaml_read`
219
+ ```python
220
+ # Reading a YAML file
221
+ yaml_data = file_handler.yaml_read("config.yaml")
222
+ print(yaml_data)
223
+ ```
224
+
225
+ #### `yaml_write`
226
+ ```python
227
+ # Writing to a YAML file
228
+ yaml_content = {"database": {"host": "localhost", "port": 3306}}
229
+ file_handler.yaml_write("config.yaml", yaml_content)
230
+ ```
231
+
232
+ ### INI File Operations
233
+
234
+ #### `ini_read`
235
+ ```python
236
+ # Reading an INI file
237
+ ini_data = file_handler.ini_read("settings.ini")
238
+ print(ini_data)
239
+ ```
240
+
241
+ #### `ini_write`
242
+ ```python
243
+ # Writing to an INI file
244
+ ini_content = {"Section1": {"key1": "value1", "key2": "value2"}}
245
+ file_handler.ini_write("settings.ini", ini_content)
246
+ ```
247
+
248
+ ### Markdown File Operations
249
+
250
+ #### `md_read`
251
+ ```python
252
+ # Reading a Markdown file
253
+ markdown_content = file_handler.md_read("README.md")
254
+ print(markdown_content)
255
+ ```
256
+
257
+ #### `md_write`
258
+ ```python
259
+ # Writing to a Markdown file
260
+ file_handler.md_write("README.md", "# Hello World\nThis is a markdown file.")
261
+ ```
262
+
263
+ ### Log File Operations
264
+
265
+ #### `log_read`
266
+ ```python
267
+ # Reading a log file
268
+ log_content = file_handler.log_read("app.log")
269
+ print(log_content)
270
+ ```
271
+
272
+ #### `log_write`
273
+ ```python
274
+ # Writing a log entry
275
+ file_handler.log_write("app.log", "Application started.")
276
+ ```
277
+
278
+ ### HTML File Operations
279
+
280
+ #### `html_read`
281
+ ```python
282
+ # Reading an HTML file
283
+ html_content = file_handler.html_read("index.html")
284
+ print(html_content)
285
+ ```
286
+
287
+ #### `html_write`
288
+ ```python
289
+ # Writing to an HTML file
290
+ file_handler.html_write("index.html", "<h1>Hello World</h1>")
291
+ ```
292
+
293
+ ### Compressed File Handling
294
+
295
+ #### `handle_compressed`
296
+ ```python
297
+ # Compressing a directory
298
+ file_handler.handle_compressed("example_folder", "compress", "archive.zip")
299
+
300
+ # Extracting from a compressed file
301
+ file_handler.handle_compressed("archive.zip", "extract", "output_folder")
302
+ ```
303
+ ---
304
+
305
+ # YoungLion VISTA
306
+
307
+ Here’s a detailed explanation of the **VISTA** classes, describing their purpose, functionality, and available methods:
308
+
309
+ ---
310
+
311
+ ## **1. ImageTool Class**
312
+
313
+ ### Description:
314
+ The **ImageTool** class is designed for handling image processing tasks. It allows developers to perform common operations such as loading, saving, resizing, and text recognition with images.
315
+
316
+ ### Key Features:
317
+ - Load images from disk or URLs.
318
+ - Save images in multiple formats.
319
+ - Resize images or convert them to grayscale.
320
+ - Perform Optical Character Recognition (OCR) to extract text from images.
321
+ - Overlay text on images or convert them to binary (black-and-white).
322
+
323
+ ### Methods:
324
+ 1. **`load(path: str)`**
325
+ Loads an image from the specified path. If the file doesn’t exist, it creates a placeholder black image.
326
+
327
+ 2. **`save(image, path: str, format: str = 'PNG', optimize: bool = True, quality: int = 85)`**
328
+ Saves an image with options for format, optimization, and quality.
329
+
330
+ 3. **`load_url(url: str, mode: str = 'RGBA')`**
331
+ Fetches an image from a URL and converts it to a specified mode.
332
+
333
+ 4. **`resize(image, size: tuple)`**
334
+ Changes the dimensions of an image.
335
+
336
+ 5. **`convert_to_grayscale(image)`**
337
+ Converts the image to grayscale.
338
+
339
+ 6. **`read_text_from_image(image)`**
340
+ Extracts text from an image using OCR.
341
+
342
+ 7. **`draw_text_on_image(image, text: str, position: tuple, font_size: int, color: str)`**
343
+ Adds text to an image at a specified position.
344
+
345
+ 8. **`convert_to_binary(image, threshold: int = 128)`**
346
+ Converts an image to black-and-white based on a threshold.
347
+
348
+ ---
349
+
350
+ ## **2. VideoTool Class**
351
+
352
+ ### Description:
353
+ The **VideoTool** class provides utilities for working with video files. It supports creating videos, adding audio, extracting frames, and manipulating existing videos.
354
+
355
+ ### Key Features:
356
+ - Generate videos from images or waveforms.
357
+ - Add or replace audio tracks in video files.
358
+ - Resize or convert video formats.
359
+ - Combine multiple videos into one.
360
+ - Trim or annotate videos with text.
361
+
362
+ ### Methods:
363
+ 1. **`image_to_video(image_path: str, duration: int, output_path: str, fps: int = 24)`**
364
+ Creates a video from a single image with a set duration.
365
+
366
+ 2. **`audio_to_waveform_video(audio_path: str, output_path: str, sample_rate: int, fps: int)`**
367
+ Converts an audio file into a waveform video.
368
+
369
+ 3. **`add_audio_to_video(video_path: str, audio_path: str, output_path: str)`**
370
+ Combines a video file with an audio file.
371
+
372
+ 4. **`resize_video(video_path: str, output_path: str, size: tuple)`**
373
+ Resizes a video to new dimensions.
374
+
375
+ 5. **`trim_video(video_path: str, start_time: float, end_time: float, output_path: str)`**
376
+ Extracts a specific segment from a video.
377
+
378
+ 6. **`concatenate_videos(video_paths: list, output_path: str)`**
379
+ Joins multiple videos into one.
380
+
381
+ 7. **`extract_audio_from_video(video_path: str, output_audio_path: str)`**
382
+ Saves the audio track of a video as a separate file.
383
+
384
+ ---
385
+
386
+ ## **3. AudioTool Class**
387
+
388
+ ### Description:
389
+ The **AudioTool** class focuses on audio processing tasks. It enables developers to manipulate audio files, including trimming, merging, adjusting pitch, and generating sine waves.
390
+
391
+ ### Key Features:
392
+ - Trim audio or extract segments.
393
+ - Adjust playback speed or pitch.
394
+ - Merge multiple audio files or create waveforms.
395
+ - Generate tones or rhythms programmatically.
396
+
397
+ ### Methods:
398
+ 1. **`trim_audio(audio_path: str, output_path: str, target_duration: float)`**
399
+ Shortens the audio file to a specified duration.
400
+
401
+ 2. **`change_speed(audio_path: str, output_path: str, speed_factor: float)`**
402
+ Speeds up or slows down the audio.
403
+
404
+ 3. **`change_pitch(audio_path: str, output_path: str, n_steps: int)`**
405
+ Modifies the pitch of the audio.
406
+
407
+ 4. **`merge_audios(audio_paths: list, output_path: str)`**
408
+ Combines multiple audio files into one.
409
+
410
+ 5. **`generate_sine_wave(frequency: float, duration: float, output_path: str)`**
411
+ Creates a pure sine wave audio file.
412
+
413
+ 6. **`extract_segment(audio_path: str, output_path: str, start_time: float, end_time: float)`**
414
+ Extracts a section of audio between specific time intervals.
415
+
416
+ ---
417
+
418
+ ## **4. AnalysisTableTool Class**
419
+
420
+ ### Description:
421
+ The **AnalysisTableTool** class provides utilities for creating graphical representations of data, including graphs, charts, and scatter plots. It’s ideal for visualizing data in analytics and reports.
422
+
423
+ ### Key Features:
424
+ - Create bar, pie, scatter, and line charts.
425
+ - Visualize graphs with nodes and curved edges.
426
+ - Save charts as images or display them interactively.
427
+
428
+ ### Methods:
429
+ 1. **`plot_graph(nodes: dict, edges: list, title: str, rad: int)`**
430
+ Visualizes a graph with curved edges connecting nodes.
431
+
432
+ 2. **`generate_bar_chart(data: dict, x_axis_label: str, y_axis_label: str)`**
433
+ Creates a bar chart from a dictionary of data.
434
+
435
+ 3. **`generate_pie_chart(data: dict, title: str)`**
436
+ Generates a pie chart.
437
+
438
+ 4. **`generate_line_chart(x_data: list, y_data: list, title: str, x_axis_label: str, y_axis_label: str)`**
439
+ Plots a line chart.
440
+
441
+ 5. **`generate_scatter_plot(x_data: list, y_data: list, title: str)`**
442
+ Creates a scatter plot to visualize relationships.
443
+
444
+ 6. **`generate_histogram(data: list, num_bins: int, title: str)`**
445
+ Creates a histogram to display data distribution.
446
+
447
+ 7. **`generate_box_plot(data: list, labels: list, title: str)`**
448
+ Produces a box plot for statistical analysis.
449
+
450
+ ---
451
+
452
+ ## Installation
453
+ To include the library in your project:
454
+ 1. Clone this repository.
455
+ 2. Import the module:
456
+ ```python
457
+ from YoungLion import VISTA
458
+ ```
459
+
460
+ ---
461
+
462
+ ## Usage Examples
463
+
464
+ ---
465
+
466
+ Usage of `ImageTool` and `Image` class:
467
+
468
+ ### Examples
469
+
470
+ #### 1. **Loading and Saving a Local Image**
471
+ ```python
472
+
473
+ # Loading and saving an image using the ImageTool class
474
+ tool = VISTA.ImageTool()
475
+ image = tool.load("example.jpg") # Loads a local file
476
+ tool.save(image, "output.png") # Saves in a different format
477
+ ```
478
+
479
+ ```python
480
+ # Using the Image class
481
+ img = VISTA.Image()
482
+ img.load("example.jpg").save("output.png")
483
+ ```
484
+
485
+ ---
486
+
487
+ #### 2. **Loading an Image from a URL**
488
+ ```python
489
+ # Using ImageTool
490
+ image = tool.load_url("https://example.com/image.png")
491
+ tool.save(image, "downloaded_image.png")
492
+ ```
493
+
494
+ ```python
495
+ # Use with Image class
496
+ img = VISTA.Image()
497
+ img.load_from_url("https://example.com/image.png").save("downloaded_image.png")
498
+ ```
499
+
500
+ ---
501
+
502
+ #### 3. **Resize Image**
503
+ ```python
504
+ # Using ImageTool
505
+ resized_image = tool.resize(image, (100, 100))
506
+ tool.save(resized_image, "resized_image.png")
507
+ ```
508
+
509
+ ```python
510
+ # Use with Image class
511
+ img = VISTA.Image()
512
+ img.load("example.jpg").resize((100, 100)).save("resized_image.png")
513
+ ```
514
+
515
+ ---
516
+
517
+ #### 4. **Converting an Image to Grayscale**
518
+ ```python
519
+ # Using ImageTool
520
+ grayscale_image = tool.convert_to_grayscale(image)
521
+ tool.save(grayscale_image, "grayscale_image.png")
522
+ ```
523
+
524
+ ```python
525
+ # Using Image class
526
+ img = VISTA.Image()
527
+ img.load("example.jpg").convert_to_grayscale().save("grayscale_image.png")
528
+ ```
529
+
530
+ ---
531
+
532
+ #### 5. **Writing Text on an Image**
533
+ ```python
534
+ # Using ImageTool
535
+ text_image = tool.draw_text_on_image(image, "Hello World!", position=(50, 50), font_size=20, color="red")
536
+ tool.save(text_image, "text_on_image.png")
537
+ ```
538
+
539
+ ```python
540
+ # Using with Image class
541
+ img = VISTA.Image()
542
+ img.load("example.jpg").draw_text("Hello World!", position=(50, 50), font_size=20, color="red").save("text_on_image.png")
543
+ ```
544
+
545
+ ---
546
+
547
+ #### 6. **Reading Text from Image with OCR**
548
+ ```python
549
+ # Using ImageTool
550
+ extracted_text = tool.read_text_from_image(image)
551
+ print("Text Read from Image:", extracted_text)
552
+ ```
553
+
554
+ ```python
555
+ # Using with Image class
556
+ img = VISTA.Image()
557
+ img.load("text_image.png")
558
+ extracted_text = img.read_text()
559
+ print("Read from Image Text:", extracted_text)
560
+ ```
561
+
562
+ ---
563
+
564
+ #### 7. **Converting Image to Binary Format**
565
+ ```python
566
+ # Using ImageTool
567
+ binary_image = tool.convert_to_binary(image, threshold=128)
568
+ tool.save(binary_image, "binary_image.png")
569
+ ```
570
+
571
+ ```python
572
+ # Using with Image class
573
+ img = VISTA.Image()
574
+ img.load("example.jpg").convert_to_binary(threshold=128).save("binary_image.png")
575
+ ```
576
+
577
+ ---
578
+
579
+ Usage of `VideoTool` class:
580
+
581
+
582
+ ## Contribution
583
+ Contributions to the **Young Lion Python Library** are welcome! Please open issues or submit pull requests to suggest enhancements or report bugs.
584
+
585
+ ---
586
+
587
+ ## License
588
+ This project is licensed under the MIT License.