ms-file-toolkit 0.4.0__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.
- ms_file_toolkit-0.4.0/PKG-INFO +156 -0
- ms_file_toolkit-0.4.0/README.md +134 -0
- ms_file_toolkit-0.4.0/ms_file_toolkit.egg-info/PKG-INFO +156 -0
- ms_file_toolkit-0.4.0/ms_file_toolkit.egg-info/SOURCES.txt +24 -0
- ms_file_toolkit-0.4.0/ms_file_toolkit.egg-info/dependency_links.txt +1 -0
- ms_file_toolkit-0.4.0/ms_file_toolkit.egg-info/entry_points.txt +2 -0
- ms_file_toolkit-0.4.0/ms_file_toolkit.egg-info/requires.txt +13 -0
- ms_file_toolkit-0.4.0/ms_file_toolkit.egg-info/top_level.txt +1 -0
- ms_file_toolkit-0.4.0/ms_toolkit/__init__.py +5 -0
- ms_file_toolkit-0.4.0/ms_toolkit/auto_tool.py +61 -0
- ms_file_toolkit-0.4.0/ms_toolkit/cli.py +61 -0
- ms_file_toolkit-0.4.0/ms_toolkit/docx_tool.py +41 -0
- ms_file_toolkit-0.4.0/ms_toolkit/docx_writer.py +141 -0
- ms_file_toolkit-0.4.0/ms_toolkit/legacy_tool.py +114 -0
- ms_file_toolkit-0.4.0/ms_toolkit/pdf_tool.py +56 -0
- ms_file_toolkit-0.4.0/ms_toolkit/pdf_writer.py +77 -0
- ms_file_toolkit-0.4.0/ms_toolkit/pptx_tool.py +38 -0
- ms_file_toolkit-0.4.0/ms_toolkit/pptx_writer.py +172 -0
- ms_file_toolkit-0.4.0/ms_toolkit/registry.py +119 -0
- ms_file_toolkit-0.4.0/ms_toolkit/schemas.py +510 -0
- ms_file_toolkit-0.4.0/ms_toolkit/security.py +57 -0
- ms_file_toolkit-0.4.0/ms_toolkit/xlsx_tool.py +47 -0
- ms_file_toolkit-0.4.0/ms_toolkit/xlsx_writer.py +186 -0
- ms_file_toolkit-0.4.0/pyproject.toml +35 -0
- ms_file_toolkit-0.4.0/setup.cfg +4 -0
- ms_file_toolkit-0.4.0/tests/test_toolkit.py +296 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ms-file-toolkit
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: Microsoft fayllarni (DOCX/XLSX/PPTX) o'qish va yozish uchun AI function-calling Python toolkit
|
|
5
|
+
Author: muslihiddinlive
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/muslihiddinlive/ms-file-toolkit
|
|
8
|
+
Project-URL: Repository, https://github.com/muslihiddinlive/ms-file-toolkit
|
|
9
|
+
Requires-Python: >=3.9
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
Requires-Dist: python-docx>=1.1.0
|
|
12
|
+
Requires-Dist: openpyxl>=3.1.0
|
|
13
|
+
Requires-Dist: python-pptx>=0.6.23
|
|
14
|
+
Requires-Dist: Pillow>=10.0.0
|
|
15
|
+
Requires-Dist: pypdf>=4.0.0
|
|
16
|
+
Requires-Dist: pdfplumber>=0.11.0
|
|
17
|
+
Requires-Dist: reportlab>=4.0.0
|
|
18
|
+
Provides-Extra: ai
|
|
19
|
+
Requires-Dist: anthropic>=0.40.0; extra == "ai"
|
|
20
|
+
Provides-Extra: dev
|
|
21
|
+
Requires-Dist: pytest>=8.0.0; extra == "dev"
|
|
22
|
+
|
|
23
|
+
# ms-file-toolkit
|
|
24
|
+
|
|
25
|
+
Microsoft fayllarni va PDF'larni **o'qish va yozish** uchun Python toolkit — **AI function calling** (Claude, GPT va h.k.) uchun tayyor tool schemalari, **xavfsizlik nazorati**, **avtomatik format aniqlash** va **CLI** bilan.
|
|
26
|
+
|
|
27
|
+
## O'rnatish
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pip install -r requirements.txt
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Yoki paket sifatida (PyPI'ga chiqarishga tayyor, CLI bilan birga o'rnatiladi):
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install -e ".[ai,dev]"
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Qo'llab-quvvatlanadigan formatlar
|
|
40
|
+
|
|
41
|
+
| Format | O'qish | Yozish |
|
|
42
|
+
| ------------------------------ | ------------------------------------------------ | --------------------------------------------------------------------------------------- |
|
|
43
|
+
| `.docx` | matn, jadvallar, metama'lumot | yaratish, matn qo'shish/almashtirish, sarlavha, rasm, sahifa bo'linishi |
|
|
44
|
+
| `.xlsx` | varaq nomlari, ma'lumotlar, o'lcham xulosasi | yaratish, varaq/qator qo'shish, formula, formatlash, panellarni muzlatish, **diagramma** |
|
|
45
|
+
| `.pptx` | slayd matnlari, slaydlar soni, notes | yaratish, slayd/rasm qo'shish, fon rangi, **diagramma** |
|
|
46
|
+
| `.pdf` | matn, jadvallar, metama'lumot | yaratish, birlashtirish (merge), bo'lish (split) |
|
|
47
|
+
| `.doc` / `.xls` / `.ppt` (eski) | `read_legacy_file` — LibreOffice orqali | — |
|
|
48
|
+
| **Har qanday (avtomatik)** | `read_any_file`, `get_file_info` | — |
|
|
49
|
+
|
|
50
|
+
> Eski formatlar uchun tizimda **LibreOffice** (`soffice`) kerak: `apt-get install libreoffice`
|
|
51
|
+
|
|
52
|
+
## Xavfsizlik
|
|
53
|
+
|
|
54
|
+
Fayl yo'llari AI tomonidan tanlanadi, shuning uchun **path traversal** himoyasi o'rnatilgan (`ms_toolkit/security.py`):
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
export MS_TOOLKIT_BASE_DIR=/home/bot/user_files # faqat shu papka ichidagi fayllarga ruxsat
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
dispatch("read_docx_text", {"file_path": "../../etc/passwd"})
|
|
62
|
+
# -> {"error": "Xavfsizlik xatosi: ..."}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## CLI (terminal orqali)
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
ms-toolkit list # barcha tool'lar ro'yxati
|
|
69
|
+
ms-toolkit run create_docx '{"file_path": "a.docx", "title": "Salom", "overwrite": true}'
|
|
70
|
+
ms-toolkit run read_any_file '{"file_path": "hujjat.xlsx"}'
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Tez boshlash (API kalitisiz)
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
pip install -e ".[dev]"
|
|
77
|
+
pytest tests/ -v # 23 ta test
|
|
78
|
+
python test_toolkit.py # tezkor smoke-test
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Function calling bilan (Claude API)
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
from ms_toolkit import TOOLS, dispatch
|
|
85
|
+
import anthropic
|
|
86
|
+
|
|
87
|
+
client = anthropic.Anthropic()
|
|
88
|
+
response = client.messages.create(
|
|
89
|
+
model="claude-sonnet-5",
|
|
90
|
+
max_tokens=1024,
|
|
91
|
+
tools=TOOLS,
|
|
92
|
+
messages=[{"role": "user", "content": "test.xlsx faylida nechta qator bor?"}],
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
for block in response.content:
|
|
96
|
+
if block.type == "tool_use":
|
|
97
|
+
print(dispatch(block.name, block.input))
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
To'liq agentic misol: [`example.py`](example.py).
|
|
101
|
+
|
|
102
|
+
## Diagramma qo'shish misoli
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
from ms_toolkit import dispatch
|
|
106
|
+
|
|
107
|
+
dispatch("add_xlsx_chart", {
|
|
108
|
+
"file_path": "hisobot.xlsx", "chart_type": "bar",
|
|
109
|
+
"data_range": "B1:B5", "categories_range": "A2:A5", "title": "Oylik savdo",
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
dispatch("add_pptx_chart", {
|
|
113
|
+
"file_path": "taqdimot.pptx", "chart_type": "pie",
|
|
114
|
+
"categories": ["A", "B", "C"], "series": {"2026": [40, 35, 25]},
|
|
115
|
+
})
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Barcha tool'lar ro'yxati (36 ta)
|
|
119
|
+
|
|
120
|
+
**DOCX (9):** `read_docx_text`, `read_docx_tables`, `get_docx_metadata`, `create_docx`, `append_docx_text`, `replace_docx_text`, `add_docx_heading`, `add_docx_image`, `add_docx_page_break`
|
|
121
|
+
**XLSX (10):** `get_xlsx_sheet_names`, `read_xlsx_data`, `get_xlsx_summary`, `create_xlsx`, `add_xlsx_sheet`, `append_xlsx_rows`, `set_xlsx_formula`, `format_xlsx_cells`, `freeze_xlsx_panes`, `add_xlsx_chart`
|
|
122
|
+
**PPTX (8):** `read_pptx_text`, `get_pptx_slide_count`, `extract_pptx_notes`, `create_pptx`, `add_pptx_slide`, `add_pptx_image`, `set_pptx_background_color`, `add_pptx_chart`
|
|
123
|
+
**PDF (6):** `read_pdf_text`, `read_pdf_tables`, `get_pdf_metadata`, `create_pdf`, `merge_pdfs`, `split_pdf`
|
|
124
|
+
**Eski formatlar (1):** `read_legacy_file`
|
|
125
|
+
**Auto-detect (2):** `read_any_file`, `get_file_info`
|
|
126
|
+
|
|
127
|
+
## Struktura
|
|
128
|
+
|
|
129
|
+
```
|
|
130
|
+
ms_toolkit/
|
|
131
|
+
__init__.py # TOOLS, dispatch export qiladi
|
|
132
|
+
docx_tool.py / docx_writer.py # Word
|
|
133
|
+
xlsx_tool.py / xlsx_writer.py # Excel (+ chart)
|
|
134
|
+
pptx_tool.py / pptx_writer.py # PowerPoint (+ chart)
|
|
135
|
+
pdf_tool.py / pdf_writer.py # PDF
|
|
136
|
+
legacy_tool.py # Eski formatlar
|
|
137
|
+
auto_tool.py # Avtomatik format aniqlash
|
|
138
|
+
security.py # Path-traversal himoyasi
|
|
139
|
+
cli.py # Terminal interfeysi (ms-toolkit)
|
|
140
|
+
schemas.py # AI uchun tool schemalari
|
|
141
|
+
registry.py # tool_name -> funksiya dispatcher
|
|
142
|
+
example.py, test_toolkit.py, tests/ # Misollar va testlar
|
|
143
|
+
pyproject.toml # pip/PyPI paketlash + CLI entry point
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## PyPI'ga chiqarish
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
pip install build twine
|
|
150
|
+
python -m build
|
|
151
|
+
twine upload dist/*
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Litsenziya
|
|
155
|
+
|
|
156
|
+
MIT
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# ms-file-toolkit
|
|
2
|
+
|
|
3
|
+
Microsoft fayllarni va PDF'larni **o'qish va yozish** uchun Python toolkit — **AI function calling** (Claude, GPT va h.k.) uchun tayyor tool schemalari, **xavfsizlik nazorati**, **avtomatik format aniqlash** va **CLI** bilan.
|
|
4
|
+
|
|
5
|
+
## O'rnatish
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install -r requirements.txt
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Yoki paket sifatida (PyPI'ga chiqarishga tayyor, CLI bilan birga o'rnatiladi):
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install -e ".[ai,dev]"
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Qo'llab-quvvatlanadigan formatlar
|
|
18
|
+
|
|
19
|
+
| Format | O'qish | Yozish |
|
|
20
|
+
| ------------------------------ | ------------------------------------------------ | --------------------------------------------------------------------------------------- |
|
|
21
|
+
| `.docx` | matn, jadvallar, metama'lumot | yaratish, matn qo'shish/almashtirish, sarlavha, rasm, sahifa bo'linishi |
|
|
22
|
+
| `.xlsx` | varaq nomlari, ma'lumotlar, o'lcham xulosasi | yaratish, varaq/qator qo'shish, formula, formatlash, panellarni muzlatish, **diagramma** |
|
|
23
|
+
| `.pptx` | slayd matnlari, slaydlar soni, notes | yaratish, slayd/rasm qo'shish, fon rangi, **diagramma** |
|
|
24
|
+
| `.pdf` | matn, jadvallar, metama'lumot | yaratish, birlashtirish (merge), bo'lish (split) |
|
|
25
|
+
| `.doc` / `.xls` / `.ppt` (eski) | `read_legacy_file` — LibreOffice orqali | — |
|
|
26
|
+
| **Har qanday (avtomatik)** | `read_any_file`, `get_file_info` | — |
|
|
27
|
+
|
|
28
|
+
> Eski formatlar uchun tizimda **LibreOffice** (`soffice`) kerak: `apt-get install libreoffice`
|
|
29
|
+
|
|
30
|
+
## Xavfsizlik
|
|
31
|
+
|
|
32
|
+
Fayl yo'llari AI tomonidan tanlanadi, shuning uchun **path traversal** himoyasi o'rnatilgan (`ms_toolkit/security.py`):
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
export MS_TOOLKIT_BASE_DIR=/home/bot/user_files # faqat shu papka ichidagi fayllarga ruxsat
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
dispatch("read_docx_text", {"file_path": "../../etc/passwd"})
|
|
40
|
+
# -> {"error": "Xavfsizlik xatosi: ..."}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## CLI (terminal orqali)
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
ms-toolkit list # barcha tool'lar ro'yxati
|
|
47
|
+
ms-toolkit run create_docx '{"file_path": "a.docx", "title": "Salom", "overwrite": true}'
|
|
48
|
+
ms-toolkit run read_any_file '{"file_path": "hujjat.xlsx"}'
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Tez boshlash (API kalitisiz)
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
pip install -e ".[dev]"
|
|
55
|
+
pytest tests/ -v # 23 ta test
|
|
56
|
+
python test_toolkit.py # tezkor smoke-test
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Function calling bilan (Claude API)
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
from ms_toolkit import TOOLS, dispatch
|
|
63
|
+
import anthropic
|
|
64
|
+
|
|
65
|
+
client = anthropic.Anthropic()
|
|
66
|
+
response = client.messages.create(
|
|
67
|
+
model="claude-sonnet-5",
|
|
68
|
+
max_tokens=1024,
|
|
69
|
+
tools=TOOLS,
|
|
70
|
+
messages=[{"role": "user", "content": "test.xlsx faylida nechta qator bor?"}],
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
for block in response.content:
|
|
74
|
+
if block.type == "tool_use":
|
|
75
|
+
print(dispatch(block.name, block.input))
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
To'liq agentic misol: [`example.py`](example.py).
|
|
79
|
+
|
|
80
|
+
## Diagramma qo'shish misoli
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
from ms_toolkit import dispatch
|
|
84
|
+
|
|
85
|
+
dispatch("add_xlsx_chart", {
|
|
86
|
+
"file_path": "hisobot.xlsx", "chart_type": "bar",
|
|
87
|
+
"data_range": "B1:B5", "categories_range": "A2:A5", "title": "Oylik savdo",
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
dispatch("add_pptx_chart", {
|
|
91
|
+
"file_path": "taqdimot.pptx", "chart_type": "pie",
|
|
92
|
+
"categories": ["A", "B", "C"], "series": {"2026": [40, 35, 25]},
|
|
93
|
+
})
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Barcha tool'lar ro'yxati (36 ta)
|
|
97
|
+
|
|
98
|
+
**DOCX (9):** `read_docx_text`, `read_docx_tables`, `get_docx_metadata`, `create_docx`, `append_docx_text`, `replace_docx_text`, `add_docx_heading`, `add_docx_image`, `add_docx_page_break`
|
|
99
|
+
**XLSX (10):** `get_xlsx_sheet_names`, `read_xlsx_data`, `get_xlsx_summary`, `create_xlsx`, `add_xlsx_sheet`, `append_xlsx_rows`, `set_xlsx_formula`, `format_xlsx_cells`, `freeze_xlsx_panes`, `add_xlsx_chart`
|
|
100
|
+
**PPTX (8):** `read_pptx_text`, `get_pptx_slide_count`, `extract_pptx_notes`, `create_pptx`, `add_pptx_slide`, `add_pptx_image`, `set_pptx_background_color`, `add_pptx_chart`
|
|
101
|
+
**PDF (6):** `read_pdf_text`, `read_pdf_tables`, `get_pdf_metadata`, `create_pdf`, `merge_pdfs`, `split_pdf`
|
|
102
|
+
**Eski formatlar (1):** `read_legacy_file`
|
|
103
|
+
**Auto-detect (2):** `read_any_file`, `get_file_info`
|
|
104
|
+
|
|
105
|
+
## Struktura
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
ms_toolkit/
|
|
109
|
+
__init__.py # TOOLS, dispatch export qiladi
|
|
110
|
+
docx_tool.py / docx_writer.py # Word
|
|
111
|
+
xlsx_tool.py / xlsx_writer.py # Excel (+ chart)
|
|
112
|
+
pptx_tool.py / pptx_writer.py # PowerPoint (+ chart)
|
|
113
|
+
pdf_tool.py / pdf_writer.py # PDF
|
|
114
|
+
legacy_tool.py # Eski formatlar
|
|
115
|
+
auto_tool.py # Avtomatik format aniqlash
|
|
116
|
+
security.py # Path-traversal himoyasi
|
|
117
|
+
cli.py # Terminal interfeysi (ms-toolkit)
|
|
118
|
+
schemas.py # AI uchun tool schemalari
|
|
119
|
+
registry.py # tool_name -> funksiya dispatcher
|
|
120
|
+
example.py, test_toolkit.py, tests/ # Misollar va testlar
|
|
121
|
+
pyproject.toml # pip/PyPI paketlash + CLI entry point
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## PyPI'ga chiqarish
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
pip install build twine
|
|
128
|
+
python -m build
|
|
129
|
+
twine upload dist/*
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Litsenziya
|
|
133
|
+
|
|
134
|
+
MIT
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ms-file-toolkit
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: Microsoft fayllarni (DOCX/XLSX/PPTX) o'qish va yozish uchun AI function-calling Python toolkit
|
|
5
|
+
Author: muslihiddinlive
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/muslihiddinlive/ms-file-toolkit
|
|
8
|
+
Project-URL: Repository, https://github.com/muslihiddinlive/ms-file-toolkit
|
|
9
|
+
Requires-Python: >=3.9
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
Requires-Dist: python-docx>=1.1.0
|
|
12
|
+
Requires-Dist: openpyxl>=3.1.0
|
|
13
|
+
Requires-Dist: python-pptx>=0.6.23
|
|
14
|
+
Requires-Dist: Pillow>=10.0.0
|
|
15
|
+
Requires-Dist: pypdf>=4.0.0
|
|
16
|
+
Requires-Dist: pdfplumber>=0.11.0
|
|
17
|
+
Requires-Dist: reportlab>=4.0.0
|
|
18
|
+
Provides-Extra: ai
|
|
19
|
+
Requires-Dist: anthropic>=0.40.0; extra == "ai"
|
|
20
|
+
Provides-Extra: dev
|
|
21
|
+
Requires-Dist: pytest>=8.0.0; extra == "dev"
|
|
22
|
+
|
|
23
|
+
# ms-file-toolkit
|
|
24
|
+
|
|
25
|
+
Microsoft fayllarni va PDF'larni **o'qish va yozish** uchun Python toolkit — **AI function calling** (Claude, GPT va h.k.) uchun tayyor tool schemalari, **xavfsizlik nazorati**, **avtomatik format aniqlash** va **CLI** bilan.
|
|
26
|
+
|
|
27
|
+
## O'rnatish
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pip install -r requirements.txt
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Yoki paket sifatida (PyPI'ga chiqarishga tayyor, CLI bilan birga o'rnatiladi):
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install -e ".[ai,dev]"
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Qo'llab-quvvatlanadigan formatlar
|
|
40
|
+
|
|
41
|
+
| Format | O'qish | Yozish |
|
|
42
|
+
| ------------------------------ | ------------------------------------------------ | --------------------------------------------------------------------------------------- |
|
|
43
|
+
| `.docx` | matn, jadvallar, metama'lumot | yaratish, matn qo'shish/almashtirish, sarlavha, rasm, sahifa bo'linishi |
|
|
44
|
+
| `.xlsx` | varaq nomlari, ma'lumotlar, o'lcham xulosasi | yaratish, varaq/qator qo'shish, formula, formatlash, panellarni muzlatish, **diagramma** |
|
|
45
|
+
| `.pptx` | slayd matnlari, slaydlar soni, notes | yaratish, slayd/rasm qo'shish, fon rangi, **diagramma** |
|
|
46
|
+
| `.pdf` | matn, jadvallar, metama'lumot | yaratish, birlashtirish (merge), bo'lish (split) |
|
|
47
|
+
| `.doc` / `.xls` / `.ppt` (eski) | `read_legacy_file` — LibreOffice orqali | — |
|
|
48
|
+
| **Har qanday (avtomatik)** | `read_any_file`, `get_file_info` | — |
|
|
49
|
+
|
|
50
|
+
> Eski formatlar uchun tizimda **LibreOffice** (`soffice`) kerak: `apt-get install libreoffice`
|
|
51
|
+
|
|
52
|
+
## Xavfsizlik
|
|
53
|
+
|
|
54
|
+
Fayl yo'llari AI tomonidan tanlanadi, shuning uchun **path traversal** himoyasi o'rnatilgan (`ms_toolkit/security.py`):
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
export MS_TOOLKIT_BASE_DIR=/home/bot/user_files # faqat shu papka ichidagi fayllarga ruxsat
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
dispatch("read_docx_text", {"file_path": "../../etc/passwd"})
|
|
62
|
+
# -> {"error": "Xavfsizlik xatosi: ..."}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## CLI (terminal orqali)
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
ms-toolkit list # barcha tool'lar ro'yxati
|
|
69
|
+
ms-toolkit run create_docx '{"file_path": "a.docx", "title": "Salom", "overwrite": true}'
|
|
70
|
+
ms-toolkit run read_any_file '{"file_path": "hujjat.xlsx"}'
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Tez boshlash (API kalitisiz)
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
pip install -e ".[dev]"
|
|
77
|
+
pytest tests/ -v # 23 ta test
|
|
78
|
+
python test_toolkit.py # tezkor smoke-test
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Function calling bilan (Claude API)
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
from ms_toolkit import TOOLS, dispatch
|
|
85
|
+
import anthropic
|
|
86
|
+
|
|
87
|
+
client = anthropic.Anthropic()
|
|
88
|
+
response = client.messages.create(
|
|
89
|
+
model="claude-sonnet-5",
|
|
90
|
+
max_tokens=1024,
|
|
91
|
+
tools=TOOLS,
|
|
92
|
+
messages=[{"role": "user", "content": "test.xlsx faylida nechta qator bor?"}],
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
for block in response.content:
|
|
96
|
+
if block.type == "tool_use":
|
|
97
|
+
print(dispatch(block.name, block.input))
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
To'liq agentic misol: [`example.py`](example.py).
|
|
101
|
+
|
|
102
|
+
## Diagramma qo'shish misoli
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
from ms_toolkit import dispatch
|
|
106
|
+
|
|
107
|
+
dispatch("add_xlsx_chart", {
|
|
108
|
+
"file_path": "hisobot.xlsx", "chart_type": "bar",
|
|
109
|
+
"data_range": "B1:B5", "categories_range": "A2:A5", "title": "Oylik savdo",
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
dispatch("add_pptx_chart", {
|
|
113
|
+
"file_path": "taqdimot.pptx", "chart_type": "pie",
|
|
114
|
+
"categories": ["A", "B", "C"], "series": {"2026": [40, 35, 25]},
|
|
115
|
+
})
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Barcha tool'lar ro'yxati (36 ta)
|
|
119
|
+
|
|
120
|
+
**DOCX (9):** `read_docx_text`, `read_docx_tables`, `get_docx_metadata`, `create_docx`, `append_docx_text`, `replace_docx_text`, `add_docx_heading`, `add_docx_image`, `add_docx_page_break`
|
|
121
|
+
**XLSX (10):** `get_xlsx_sheet_names`, `read_xlsx_data`, `get_xlsx_summary`, `create_xlsx`, `add_xlsx_sheet`, `append_xlsx_rows`, `set_xlsx_formula`, `format_xlsx_cells`, `freeze_xlsx_panes`, `add_xlsx_chart`
|
|
122
|
+
**PPTX (8):** `read_pptx_text`, `get_pptx_slide_count`, `extract_pptx_notes`, `create_pptx`, `add_pptx_slide`, `add_pptx_image`, `set_pptx_background_color`, `add_pptx_chart`
|
|
123
|
+
**PDF (6):** `read_pdf_text`, `read_pdf_tables`, `get_pdf_metadata`, `create_pdf`, `merge_pdfs`, `split_pdf`
|
|
124
|
+
**Eski formatlar (1):** `read_legacy_file`
|
|
125
|
+
**Auto-detect (2):** `read_any_file`, `get_file_info`
|
|
126
|
+
|
|
127
|
+
## Struktura
|
|
128
|
+
|
|
129
|
+
```
|
|
130
|
+
ms_toolkit/
|
|
131
|
+
__init__.py # TOOLS, dispatch export qiladi
|
|
132
|
+
docx_tool.py / docx_writer.py # Word
|
|
133
|
+
xlsx_tool.py / xlsx_writer.py # Excel (+ chart)
|
|
134
|
+
pptx_tool.py / pptx_writer.py # PowerPoint (+ chart)
|
|
135
|
+
pdf_tool.py / pdf_writer.py # PDF
|
|
136
|
+
legacy_tool.py # Eski formatlar
|
|
137
|
+
auto_tool.py # Avtomatik format aniqlash
|
|
138
|
+
security.py # Path-traversal himoyasi
|
|
139
|
+
cli.py # Terminal interfeysi (ms-toolkit)
|
|
140
|
+
schemas.py # AI uchun tool schemalari
|
|
141
|
+
registry.py # tool_name -> funksiya dispatcher
|
|
142
|
+
example.py, test_toolkit.py, tests/ # Misollar va testlar
|
|
143
|
+
pyproject.toml # pip/PyPI paketlash + CLI entry point
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## PyPI'ga chiqarish
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
pip install build twine
|
|
150
|
+
python -m build
|
|
151
|
+
twine upload dist/*
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Litsenziya
|
|
155
|
+
|
|
156
|
+
MIT
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
ms_file_toolkit.egg-info/PKG-INFO
|
|
4
|
+
ms_file_toolkit.egg-info/SOURCES.txt
|
|
5
|
+
ms_file_toolkit.egg-info/dependency_links.txt
|
|
6
|
+
ms_file_toolkit.egg-info/entry_points.txt
|
|
7
|
+
ms_file_toolkit.egg-info/requires.txt
|
|
8
|
+
ms_file_toolkit.egg-info/top_level.txt
|
|
9
|
+
ms_toolkit/__init__.py
|
|
10
|
+
ms_toolkit/auto_tool.py
|
|
11
|
+
ms_toolkit/cli.py
|
|
12
|
+
ms_toolkit/docx_tool.py
|
|
13
|
+
ms_toolkit/docx_writer.py
|
|
14
|
+
ms_toolkit/legacy_tool.py
|
|
15
|
+
ms_toolkit/pdf_tool.py
|
|
16
|
+
ms_toolkit/pdf_writer.py
|
|
17
|
+
ms_toolkit/pptx_tool.py
|
|
18
|
+
ms_toolkit/pptx_writer.py
|
|
19
|
+
ms_toolkit/registry.py
|
|
20
|
+
ms_toolkit/schemas.py
|
|
21
|
+
ms_toolkit/security.py
|
|
22
|
+
ms_toolkit/xlsx_tool.py
|
|
23
|
+
ms_toolkit/xlsx_writer.py
|
|
24
|
+
tests/test_toolkit.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ms_toolkit
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""Fayl turini avtomatik aniqlab, mos reader'ni chaqiradigan yordamchi modul."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
|
|
5
|
+
_EXT_MAP = {
|
|
6
|
+
".docx": "docx",
|
|
7
|
+
".xlsx": "xlsx",
|
|
8
|
+
".pptx": "pptx",
|
|
9
|
+
".pdf": "pdf",
|
|
10
|
+
".doc": "legacy",
|
|
11
|
+
".xls": "legacy",
|
|
12
|
+
".ppt": "legacy",
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def get_file_info(file_path: str) -> dict:
|
|
17
|
+
"""Fayl haqida asosiy ma'lumot: mavjudmi, kengaytmasi, hajmi, aniqlangan turi."""
|
|
18
|
+
ext = os.path.splitext(file_path)[1].lower()
|
|
19
|
+
exists = os.path.exists(file_path)
|
|
20
|
+
return {
|
|
21
|
+
"file_path": file_path,
|
|
22
|
+
"exists": exists,
|
|
23
|
+
"extension": ext,
|
|
24
|
+
"detected_type": _EXT_MAP.get(ext, "unknown"),
|
|
25
|
+
"size_bytes": os.path.getsize(file_path) if exists else None,
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def read_any_file(file_path: str) -> dict:
|
|
30
|
+
"""Fayl kengaytmasiga qarab mos o'qish funksiyasini avtomatik tanlab chaqiradi.
|
|
31
|
+
|
|
32
|
+
Foydalanuvchi/AI fayl turini oldindan bilmasa yoki noaniq bo'lsa foydali —
|
|
33
|
+
.docx/.xlsx/.pptx va eski .doc/.xls/.ppt formatlarni avtomatik aniqlaydi.
|
|
34
|
+
"""
|
|
35
|
+
from .docx_tool import read_docx_text
|
|
36
|
+
from .xlsx_tool import read_xlsx_data
|
|
37
|
+
from .pptx_tool import read_pptx_text
|
|
38
|
+
from .pdf_tool import read_pdf_text
|
|
39
|
+
from .legacy_tool import read_legacy_file
|
|
40
|
+
|
|
41
|
+
if not os.path.exists(file_path):
|
|
42
|
+
return {"error": f"Fayl topilmadi: {file_path}"}
|
|
43
|
+
|
|
44
|
+
ext = os.path.splitext(file_path)[1].lower()
|
|
45
|
+
kind = _EXT_MAP.get(ext)
|
|
46
|
+
|
|
47
|
+
if kind == "docx":
|
|
48
|
+
result = read_docx_text(file_path)
|
|
49
|
+
elif kind == "xlsx":
|
|
50
|
+
result = read_xlsx_data(file_path)
|
|
51
|
+
elif kind == "pptx":
|
|
52
|
+
result = read_pptx_text(file_path)
|
|
53
|
+
elif kind == "pdf":
|
|
54
|
+
result = read_pdf_text(file_path)
|
|
55
|
+
elif kind == "legacy":
|
|
56
|
+
result = read_legacy_file(file_path)
|
|
57
|
+
else:
|
|
58
|
+
return {"error": f"Qo'llab-quvvatlanmaydigan yoki noma'lum fayl turi: {ext or '(kengaytmasiz)'}"}
|
|
59
|
+
|
|
60
|
+
result["detected_type"] = kind
|
|
61
|
+
return result
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""
|
|
2
|
+
ms_toolkit uchun komandalar qatori (CLI) interfeysi.
|
|
3
|
+
|
|
4
|
+
Ishlatish:
|
|
5
|
+
ms-toolkit list
|
|
6
|
+
ms-toolkit run create_docx '{"file_path": "test.docx", "title": "Salom"}'
|
|
7
|
+
ms-toolkit run read_docx_text '{"file_path": "test.docx"}'
|
|
8
|
+
ms-toolkit run read_any_file '{"file_path": "hujjat.xlsx"}'
|
|
9
|
+
|
|
10
|
+
MS_TOOLKIT_BASE_DIR muhit o'zgaruvchisi bilan fayl amallarini bitta papkaga
|
|
11
|
+
cheklash mumkin (xavfsizlik uchun tavsiya etiladi).
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import sys
|
|
15
|
+
import json
|
|
16
|
+
import argparse
|
|
17
|
+
|
|
18
|
+
from .registry import REGISTRY, dispatch
|
|
19
|
+
from .schemas import TOOLS
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def cmd_list(args):
|
|
23
|
+
for t in TOOLS:
|
|
24
|
+
print(f"{t['name']:<28} {t['description'][:80]}")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def cmd_run(args):
|
|
28
|
+
if args.tool_name not in REGISTRY:
|
|
29
|
+
print(f"Xato: noma'lum tool '{args.tool_name}'. Ro'yxat uchun: ms-toolkit list", file=sys.stderr)
|
|
30
|
+
sys.exit(1)
|
|
31
|
+
|
|
32
|
+
try:
|
|
33
|
+
tool_input = json.loads(args.json_input)
|
|
34
|
+
except json.JSONDecodeError as e:
|
|
35
|
+
print(f"Xato: JSON noto'g'ri formatda: {e}", file=sys.stderr)
|
|
36
|
+
sys.exit(1)
|
|
37
|
+
|
|
38
|
+
result = dispatch(args.tool_name, tool_input)
|
|
39
|
+
print(json.dumps(result, ensure_ascii=False, indent=2, default=str))
|
|
40
|
+
|
|
41
|
+
if "error" in result:
|
|
42
|
+
sys.exit(1)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def main():
|
|
46
|
+
parser = argparse.ArgumentParser(prog="ms-toolkit", description="MS fayllar (DOCX/XLSX/PPTX/PDF) uchun CLI")
|
|
47
|
+
sub = parser.add_subparsers(dest="command", required=True)
|
|
48
|
+
|
|
49
|
+
sub.add_parser("list", help="Barcha mavjud tool'larni ro'yxatini chiqaradi").set_defaults(func=cmd_list)
|
|
50
|
+
|
|
51
|
+
run_parser = sub.add_parser("run", help="Bitta tool'ni ishga tushiradi")
|
|
52
|
+
run_parser.add_argument("tool_name", help="Ishga tushiriladigan tool nomi (masalan: create_docx)")
|
|
53
|
+
run_parser.add_argument("json_input", help="Tool uchun JSON formatidagi kirish, masalan '{\"file_path\": \"a.docx\"}'")
|
|
54
|
+
run_parser.set_defaults(func=cmd_run)
|
|
55
|
+
|
|
56
|
+
args = parser.parse_args()
|
|
57
|
+
args.func(args)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
if __name__ == "__main__":
|
|
61
|
+
main()
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""DOCX (Word) fayllarni o'qish va tahlil qilish funksiyalari."""
|
|
2
|
+
|
|
3
|
+
from docx import Document
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def read_docx_text(file_path: str) -> dict:
|
|
7
|
+
"""Word hujjatidagi barcha matnni paragraflar bo'yicha o'qiydi."""
|
|
8
|
+
doc = Document(file_path)
|
|
9
|
+
paragraphs = [p.text for p in doc.paragraphs if p.text.strip()]
|
|
10
|
+
return {
|
|
11
|
+
"file_path": file_path,
|
|
12
|
+
"paragraph_count": len(paragraphs),
|
|
13
|
+
"text": "\n".join(paragraphs),
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def read_docx_tables(file_path: str) -> dict:
|
|
18
|
+
"""Word hujjatidagi barcha jadvallarni o'qiydi."""
|
|
19
|
+
doc = Document(file_path)
|
|
20
|
+
tables = []
|
|
21
|
+
for table in doc.tables:
|
|
22
|
+
rows = []
|
|
23
|
+
for row in table.rows:
|
|
24
|
+
rows.append([cell.text for cell in row.cells])
|
|
25
|
+
tables.append(rows)
|
|
26
|
+
return {"file_path": file_path, "table_count": len(tables), "tables": tables}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def get_docx_metadata(file_path: str) -> dict:
|
|
30
|
+
"""Word hujjatining metama'lumotlarini (muallif, sarlavha va h.k.) qaytaradi."""
|
|
31
|
+
doc = Document(file_path)
|
|
32
|
+
props = doc.core_properties
|
|
33
|
+
return {
|
|
34
|
+
"file_path": file_path,
|
|
35
|
+
"title": props.title,
|
|
36
|
+
"author": props.author,
|
|
37
|
+
"created": str(props.created) if props.created else None,
|
|
38
|
+
"modified": str(props.modified) if props.modified else None,
|
|
39
|
+
"paragraph_count": len(doc.paragraphs),
|
|
40
|
+
"table_count": len(doc.tables),
|
|
41
|
+
}
|