Common functions for working in Python
Project description
Harrix PyLib
๐ Common Python functions (3.10+) library for my projects for my projects.
๐ Contents โฌ๏ธ
Contents
GitHub: https://github.com/Harrix/harrix-pylib
Documentation: docs
โจ Features
- ๐ File Operations - Directory management, file processing, archive handling
- ๐ Markdown Tools - YAML processing, TOC generation, content manipulation
- ๐ง Development Utils - Project setup, code formatting, documentation generation
- ๐ก๏ธ Code Checkers - Custom validation rules for Python and Markdown (complements standard linters)
๐ฆ Installation
Using pip:
pip install harrix-pylib
Using uv (recommended):
uv add harrix-pylib
๐ Quick start
Examples of using the library:
import harrixpylib as h
h.file.clear_directory("C:/temp_dir")
import harrixpylib as h
md_clean = h.file.remove_yaml_content("""
---
categories: [it, program]
tags: [VSCode, FAQ]
---
# Installing VSCode
""")
print(md_clean) # Installing VSCode
๐ List of functions
๐ File funcs_dev.py
Doc: funcs_dev.g.md
| Function/Class | Description |
|---|---|
๐ง get_project_root |
Find the root folder of the current project. |
๐ง load_config |
Load configuration from a JSON file. |
๐ง run_command |
Run a console command and return its output. |
๐ง run_powershell_script |
Run a PowerShell script with the given commands. |
๐ง run_powershell_script_as_admin |
Execute a PowerShell script with administrator privileges and captures the output. |
๐ง write_in_output_txt |
Decorate to write function output to a temporary file and optionally display it. |
๐ File funcs_file.py
Doc: funcs_file.g.md
| Function/Class | Description |
|---|---|
๐ง all_to_parent_folder |
Move all files from subfolders within the given path to the parent folder and then |
๐ง apply_func |
Recursively apply a function to all files with a specified extension in a directory. |
๐ง check_featured_image |
Check for the presence of featured_image.* files in every child folder, not recursively. |
๐ง check_func |
Recursively applies a checking function to all files with a specified extension in a directory. |
๐ง clear_directory |
Clear directory with sub-directories. |
๐ง extract_zip_archive |
Extract ZIP archive to the folder where the archive is located and remove the archive file. |
๐ง find_max_folder_number |
Find the highest folder number in a given folder based on a pattern. |
๐ง list_files_simple |
Generate a simple list of all files in a directory structure. |
๐ง open_file_or_folder |
Open a file or folder using the operating system's default application. |
๐ง remove_empty_folders |
Remove all empty folders recursively while respecting ignore patterns. |
๐ง rename_epub_file |
Rename EPUB file based on metadata from file content. |
๐ง rename_fb2_file |
Rename FB2 file based on metadata from file content. |
๐ง rename_file_spaces_to_hyphens |
Rename file by replacing spaces with hyphens in the filename. |
๐ง rename_files_by_mapping |
Rename files recursively based on a mapping dictionary while respecting ignore patterns. |
๐ง rename_largest_images_to_featured |
Find the largest image in each subdirectory of the given path and renames it to 'featured-image'. |
๐ง rename_pdf_file |
Rename PDF file based on metadata from file content. |
๐ง should_ignore_path |
Check if a path should be ignored based on common ignore patterns. |
๐ง tree_view_folder |
Generate a tree-like representation of folder contents. |
๐ File funcs_md.py
Doc: funcs_md.g.md
| Function/Class | Description |
|---|---|
๐ง add_diary_entry_in_year |
Add a new diary entry to the yearly Markdown file. |
๐ง add_diary_new_dairy_in_year |
Add a new diary entry to the yearly diary file. |
๐ง add_diary_new_diary |
Create a new diary entry for the current day and time. |
๐ง add_diary_new_dream |
Create a new dream diary entry for the current day and time with placeholders for dream descriptions. |
๐ง add_diary_new_dream_in_year |
Add a new dream diary entry to the yearly dream file. |
๐ง add_diary_new_note |
Add a new note to the diary or dream diary for the given base path. |
๐ง add_note |
Add a note to the specified base path. |
๐ง append_path_to_local_links_images_line |
Append a path to local links and images within a Markdown line. |
๐ง combine_markdown_files |
Combine multiple Markdown files in a folder into a single file with intelligent YAML header merging. |
๐ง combine_markdown_files_recursively |
Recursively process a folder structure and combines Markdown files in each folder that meets specific criteria. |
๐ง delete_g_md_files_recursively |
Delete all *.g.md files recursively in the specified folder. |
๐ง download_and_replace_images |
Download remote images in Markdown text and replaces their URLs with local paths. |
๐ง download_and_replace_images_content |
Download remote images in Markdown text and replaces their URLs with local paths. |
๐ง format_quotes_as_markdown_content |
Convert raw text with quotes into Markdown format. |
๐ง format_yaml |
Format YAML content in a file, ensuring proper indentation and structure. |
๐ง format_yaml_content |
Format the YAML front matter within the given Markdown text. |
๐ง generate_author_book |
Add the author and the title of the book to the quotes and formats them as Markdown quotes. |
๐ง generate_id |
Return exactly the same anchor slug GitHub creates for a Markdown heading. |
๐ง generate_image_captions |
Process a Markdown file to add captions to images based on their alt text. |
๐ง generate_image_captions_content |
Generate image captions in the provided Markdown text. |
๐ง generate_short_note_toc_with_links |
Generate a separate Markdown file with only the Table of Contents (TOC) from a given Markdown file. |
๐ง generate_short_note_toc_with_links_content |
Generate a Markdown content with only the Table of Contents (TOC) from a given Markdown text. |
๐ง generate_summaries |
Generate two summary files for a directory of year-based Markdown files. |
๐ง generate_toc_with_links |
Generate a Table of Contents (TOC) with clickable links for a given Markdown file and inserts or refreshes |
๐ง generate_toc_with_links_content |
Generate a Table of Contents (TOC) with links for the provided Markdown content. |
๐ง get_yaml_content |
Get YAML from text of the Markdown file. |
๐ง identify_code_blocks |
Process a sequence of text lines to identify code blocks and yield each line with a boolean flag. |
๐ง identify_code_blocks_line |
Parse a single line of Markdown to identify inline code blocks. |
๐ง increase_heading_level_content |
Increase the heading level of Markdown content. |
๐ง remove_markdown_formatting_for_headings |
Remove markdown formatting from text. |
๐ง remove_toc_content |
Remove the table of contents (TOC) section from a Markdown document. |
๐ง remove_yaml_and_code_content |
Remove YAML front matter and code blocks, and returns the remaining content. |
๐ง remove_yaml_content |
Remove YAML from text of the Markdown file. |
๐ง replace_section |
Replace a section in a file defined by title_section with the provided replace_content. |
๐ง replace_section_content |
Replace a section in the Markdown text defined by title_section with the provided replace_content. |
๐ง sort_sections |
Sort the sections of a Markdown file by their headings, maintaining YAML front matter |
๐ง sort_sections_content |
Sort sections by their ## headings: top sections first, then dates in descending order, |
๐ง split_toc_content |
Separate the Table of Contents (TOC) from the rest of the Markdown content. |
๐ง split_yaml_content |
Split a Markdown note into YAML front matter and the main content. |
๐ File funcs_py.py
Doc: funcs_py.g.md
| Function/Class | Description |
|---|---|
๐ง create_uv_new_project |
Create a new project using uv, initializes it, and sets up necessary files. |
๐ง extract_functions_and_classes |
Extract all classes and functions from a Python file and formats them into a Markdown list. |
๐ง generate_md_docs |
Generate documentation for all Python files within a given project folder. |
๐ง generate_md_docs_content |
Generate Markdown documentation for a single Python file. |
๐ง lint_and_fix_python_code |
Lints and fixes the provided Python code using the ruff formatter. |
๐ง sort_py_code |
Sorts the Python code in the given file by organizing classes, functions, and statements. |
๐ File markdown_checker.py
| Function/Class | Description |
|---|---|
๐๏ธ Class MarkdownChecker |
Class for checking Markdown files for compliance with specified rules. |
๐ File python_checker.py
Doc: python_checker.g.md
| Function/Class | Description |
|---|---|
๐๏ธ Class PythonChecker |
Class for checking Python files for compliance with specified rules. |
๐ License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file harrix_pylib-0.169.tar.gz.
File metadata
- Download URL: harrix_pylib-0.169.tar.gz
- Upload date:
- Size: 167.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b2612095ca1de329a130990cdda530577f42483389dd04b8bcd8a29455468ce0
|
|
| MD5 |
1957fcaec97bf17997e1a6e6be8d48c4
|
|
| BLAKE2b-256 |
a89cc47f0475c4d02c1debadf444213a94b2ffc59789bac8f56c76f5b8383719
|
File details
Details for the file harrix_pylib-0.169-py3-none-any.whl.
File metadata
- Download URL: harrix_pylib-0.169-py3-none-any.whl
- Upload date:
- Size: 60.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dfff76a95d4fd641d0afcd0780674108f8ea45aa4ddd6554916bf24ff729c496
|
|
| MD5 |
40cd3e720f98d4d8e171249ed28a1599
|
|
| BLAKE2b-256 |
5c172448eefdaa22c05a01306894d08765cfaec818181dcc17021c203cbc8509
|