xparse-client 0.2.8__py3-none-any.whl → 0.2.9__py3-none-any.whl

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.
example/run_pipeline.py CHANGED
@@ -128,14 +128,14 @@ def run_with_manual_setup():
128
128
  # prefix='',
129
129
  # region='cn-east-3'
130
130
  # )
131
- source = S3Source(
132
- endpoint='https://s3.us-east-1.amazonaws.com',
133
- access_key='AKIA6QUE3TVZADUWA4PO',
134
- secret_key='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',
135
- bucket='textin-xparse',
136
- prefix='',
137
- region='us-east-1'
138
- )
131
+ # source = S3Source(
132
+ # endpoint='https://s3.us-east-1.amazonaws.com',
133
+ # access_key='AKIA6QUE3TVZADUWA4PO',
134
+ # secret_key='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',
135
+ # bucket='textin-xparse',
136
+ # prefix='',
137
+ # region='us-east-1'
138
+ # )
139
139
  # source = S3Source(
140
140
  # endpoint='http://127.0.0.1:9000',
141
141
  # access_key='',
@@ -158,10 +158,11 @@ def run_with_manual_setup():
158
158
  # username='', # 用户名,按照实际填写
159
159
  # password='' # 密码,按照实际填写
160
160
  # )
161
- # source = LocalSource(
162
- # directory='/Users/ke_wang/Documents/doc',
163
- # pattern='*.pdf' # 支持通配符: *.pdf, *.docx, **/*.txt
164
- # )
161
+ source = LocalSource(
162
+ directory='/Users/ke_wang/Documents/doc',
163
+ recursive=False,
164
+ pattern=['*'] # 支持通配符: *.pdf, *.docx, **/*.txt
165
+ )
165
166
 
166
167
  # 创建 Milvus 目的地
167
168
  # destination = MilvusDestination(
@@ -194,7 +195,7 @@ def run_with_manual_setup():
194
195
  stages = [
195
196
  Stage(
196
197
  type='parse',
197
- config=ParseConfig(provider='textin-lite')
198
+ config=ParseConfig(provider='textin')
198
199
  ),
199
200
  Stage(
200
201
  type='chunk',
@@ -236,8 +237,8 @@ def run_with_manual_setup():
236
237
  )
237
238
 
238
239
  # 运行
239
- config = pipeline.get_config()
240
- print(json.dumps(config, ensure_ascii=False, indent=2))
240
+ # config = pipeline.get_config()
241
+ pipeline.run()
241
242
 
242
243
 
243
244
  # ============================================================================
@@ -86,14 +86,14 @@ def run_with_manual_setup():
86
86
  from xparse_client import ChunkConfig, EmbedConfig, ParseConfig, Stage
87
87
 
88
88
  # 创建 S3 数据源
89
- # source = S3Source(
90
- # endpoint='https://textin-minio-api.ai.intsig.net',
91
- # access_key='IEQspf8C7fVcgmp3AZWl',
92
- # secret_key='kLj96I8FGbIrPFW08meXivCy4AVdzBijOJWKWOt1',
93
- # bucket='textin-test',
94
- # prefix='',
95
- # region='us-east-1'
96
- # )
89
+ source = S3Source(
90
+ endpoint='https://textin-minio-api.ai.intsig.net',
91
+ access_key='IEQspf8C7fVcgmp3AZWl',
92
+ secret_key='kLj96I8FGbIrPFW08meXivCy4AVdzBijOJWKWOt1',
93
+ bucket='textin-test',
94
+ prefix='',
95
+ region='us-east-1'
96
+ )
97
97
  source = S3Source(
98
98
  endpoint='https://s3.oss-cn-shanghai.aliyuncs.com',
99
99
  access_key='LTAI5tBgsaVfkbh9rbPyuB17',
@@ -11,7 +11,7 @@ from datetime import datetime, timezone
11
11
  from email.utils import parsedate_to_datetime
12
12
  from fnmatch import fnmatch
13
13
  from pathlib import Path
14
- from typing import List, Dict, Any, Tuple
14
+ from typing import List, Dict, Any, Tuple, Optional
15
15
 
16
16
  from smb.SMBConnection import SMBConnection
17
17
  from botocore.config import Config
@@ -20,6 +20,56 @@ from botocore.config import Config
20
20
  logger = logging.getLogger(__name__)
21
21
 
22
22
 
23
+ def _normalize_wildcard_patterns(pattern: Optional[List[str]]) -> Optional[List[str]]:
24
+ """规范化通配符模式列表
25
+
26
+ Args:
27
+ pattern: 通配符模式列表,如果为 None 或空列表则返回 None(表示匹配所有文件)
28
+
29
+ Returns:
30
+ 通配符模式列表,如果 pattern 是 None、空列表或包含 "*" 则返回 None(表示匹配所有文件)
31
+ """
32
+ if pattern is None or not pattern:
33
+ return None # None 表示匹配所有文件
34
+
35
+ if not isinstance(pattern, list):
36
+ raise ValueError(f"pattern 类型错误: {type(pattern)}")
37
+
38
+ # 过滤空字符串并去除空格
39
+ normalized = [p.strip() for p in pattern if p and p.strip()]
40
+
41
+ if not normalized:
42
+ return None
43
+
44
+ # 如果包含 "*",直接返回 None(匹配所有文件,减少后续开销)
45
+ if '*' in normalized:
46
+ return None
47
+
48
+ return normalized
49
+
50
+
51
+ def _match_file_extension(file_path: str, wildcard_patterns: Optional[List[str]]) -> bool:
52
+ """检查文件路径是否匹配通配符模式
53
+
54
+ Args:
55
+ file_path: 文件路径
56
+ wildcard_patterns: 已规范化的通配符模式列表(如 ['*.pdf', '*.docx'])
57
+
58
+ Returns:
59
+ 如果匹配返回 True,否则返回 False
60
+ """
61
+ # 如果 wildcard_patterns 是 None 或空列表,匹配所有文件
62
+ if wildcard_patterns is None:
63
+ return True
64
+
65
+ # 检查是否匹配任何一个通配符模式
66
+ for wildcard_pattern in wildcard_patterns:
67
+ if fnmatch(file_path, wildcard_pattern):
68
+ return True
69
+
70
+ return False
71
+
72
+
23
73
  def _to_millis_timestamp_string(timestamp):
24
74
  """将时间戳转换为毫秒时间戳字符串
25
75
 
@@ -62,11 +112,11 @@ class S3Source(Source):
62
112
  """S3/MinIO 数据源"""
63
113
 
64
114
  def __init__(self, endpoint: str, access_key: str, secret_key: str,
65
- bucket: str, prefix: str = '', region: str = 'us-east-1', pattern: str = '*', recursive: bool = False):
115
+ bucket: str, prefix: str = '', region: str = 'us-east-1', pattern: Optional[List[str]] = None, recursive: bool = False):
66
116
  self.endpoint = endpoint
67
117
  self.bucket = bucket
68
118
  self.prefix = prefix
69
- self.pattern = pattern or '*'
119
+ self.pattern = _normalize_wildcard_patterns(pattern) # 在初始化时规范化
70
120
  self.recursive = recursive
71
121
 
72
122
  if self.endpoint == 'https://textin-minio-api.ai.intsig.net':
@@ -108,7 +158,7 @@ class S3Source(Source):
108
158
  key = obj['Key']
109
159
  if key.endswith('/') or key.endswith('empty.tmp'):
110
160
  continue
111
- if fnmatch(key, self.pattern):
161
+ if _match_file_extension(key, self.pattern):
112
162
  files.append(key)
113
163
 
114
164
  # 非递归模式下,CommonPrefixes 包含子目录,我们忽略它们
@@ -156,9 +206,9 @@ class S3Source(Source):
156
206
  class LocalSource(Source):
157
207
  """本地文件系统数据源"""
158
208
 
159
- def __init__(self, directory: str, pattern: str = '*', recursive: bool = False):
209
+ def __init__(self, directory: str, pattern: Optional[List[str]] = None, recursive: bool = False):
160
210
  self.directory = Path(directory)
161
- self.pattern = pattern or '*'
211
+ self.pattern = _normalize_wildcard_patterns(pattern) # 在初始化时规范化
162
212
  self.recursive = recursive
163
213
 
164
214
  if not self.directory.exists():
@@ -168,20 +218,29 @@ class LocalSource(Source):
168
218
  logger.info(f"本地目录: {self.directory}")
169
219
 
170
220
  def list_files(self) -> List[str]:
221
+ all_files = []
222
+ # 匹配所有文件
171
223
  if self.recursive:
172
- # 递归模式:使用 rglob
173
- files = [
224
+ all_files.extend([
174
225
  str(f.relative_to(self.directory))
175
- for f in self.directory.rglob(self.pattern)
226
+ for f in self.directory.rglob('*')
176
227
  if f.is_file()
177
- ]
228
+ ])
178
229
  else:
179
- # 非递归模式:只列出根目录下的文件,使用 glob
180
- files = [
230
+ all_files.extend([
181
231
  str(f.relative_to(self.directory))
182
- for f in self.directory.glob(self.pattern)
232
+ for f in self.directory.glob('*')
183
233
  if f.is_file()
184
- ]
234
+ ])
235
+
236
+ files = []
237
+ if self.pattern is not None:
238
+ for file in all_files:
239
+ if _match_file_extension(file, self.pattern):
240
+ files.append(file)
241
+ else:
242
+ files.extend(all_files)
243
+
185
244
  print(f"✓ 本地找到 {len(files)} 个文件")
186
245
  return files
187
246
 
@@ -217,12 +276,12 @@ class LocalSource(Source):
217
276
  class FtpSource(Source):
218
277
  """FTP 数据源"""
219
278
 
220
- def __init__(self, host: str, port: int, username: str, password: str, pattern: str = '*', recursive: bool = False):
279
+ def __init__(self, host: str, port: int, username: str, password: str, pattern: Optional[List[str]] = None, recursive: bool = False):
221
280
  self.host = host
222
281
  self.port = port
223
282
  self.username = username
224
283
  self.password = password
225
- self.pattern = pattern or '*'
284
+ self.pattern = _normalize_wildcard_patterns(pattern) # 在初始化时规范化
226
285
  self.recursive = recursive
227
286
 
228
287
  self.client = ftplib.FTP()
@@ -288,12 +347,12 @@ class FtpSource(Source):
288
347
  except:
289
348
  # 不是目录,是文件
290
349
  relative_path = full_path.lstrip('/')
291
- if fnmatch(relative_path, self.pattern):
350
+ if _match_file_extension(relative_path, self.pattern):
292
351
  files.append(relative_path)
293
352
  else:
294
353
  # 是文件
295
354
  relative_path = full_path.lstrip('/')
296
- if fnmatch(relative_path, self.pattern):
355
+ if _match_file_extension(relative_path, self.pattern):
297
356
  files.append(relative_path)
298
357
 
299
358
  # 恢复原始目录
@@ -325,7 +384,7 @@ class FtpSource(Source):
325
384
  item_type = item_info.get('type', 'unknown')
326
385
  # 只添加文件,排除目录
327
386
  if item_type == 'file' or (item_type == 'unknown' and not item_info.get('type', '').startswith('dir')):
328
- if fnmatch(item_name, self.pattern):
387
+ if _match_file_extension(item_name, self.pattern):
329
388
  files.append(item_name)
330
389
  except:
331
390
  # 如果不支持 MLSD,使用 LIST 命令
@@ -341,7 +400,7 @@ class FtpSource(Source):
341
400
  continue
342
401
  is_dir = parts[0].startswith('d')
343
402
  # 只添加文件,排除目录
344
- if not is_dir and fnmatch(item_name, self.pattern):
403
+ if not is_dir and _match_file_extension(item_name, self.pattern):
345
404
  files.append(item_name)
346
405
  except:
347
406
  # 最后回退到 nlst,通过尝试切换目录来判断是否为目录
@@ -357,7 +416,7 @@ class FtpSource(Source):
357
416
  continue
358
417
  except:
359
418
  # 不能切换,说明是文件
360
- if fnmatch(item_name, self.pattern):
419
+ if _match_file_extension(item_name, self.pattern):
361
420
  files.append(item_name)
362
421
 
363
422
  # 确保回到原始目录
@@ -405,7 +464,7 @@ class SmbSource(Source):
405
464
  """SMB/CIFS 数据源"""
406
465
 
407
466
  def __init__(self, host: str, share_name: str, username: str, password: str,
408
- domain: str = '', port: int = 445, path: str = '', pattern: str = '*', recursive: bool = False):
467
+ domain: str = '', port: int = 445, path: str = '', pattern: Optional[List[str]] = None, recursive: bool = False):
409
468
  self.host = host
410
469
  self.share_name = share_name
411
470
  self.username = username
@@ -413,7 +472,7 @@ class SmbSource(Source):
413
472
  self.domain = domain
414
473
  self.port = port
415
474
  self.path = path.strip('/').strip('\\') if path else ''
416
- self.pattern = pattern or '*'
475
+ self.pattern = _normalize_wildcard_patterns(pattern) # 在初始化时规范化
417
476
  self.recursive = recursive
418
477
 
419
478
  self.conn = SMBConnection(
@@ -451,7 +510,7 @@ class SmbSource(Source):
451
510
  _list_recursive(conn, share, item_path)
452
511
  # 非递归模式:忽略子目录
453
512
  else:
454
- if fnmatch(relative_path, self.pattern):
513
+ if _match_file_extension(relative_path, self.pattern):
455
514
  files.append(relative_path)
456
515
  except Exception as e:
457
516
  logger.warning(f"列出路径失败 {current_path}: {str(e)}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xparse-client
3
- Version: 0.2.8
3
+ Version: 0.2.9
4
4
  Summary: 面向Agent和RAG的新一代文档处理 AI Infra
5
5
  License-Expression: MIT
6
6
  Project-URL: Homepage, https://gitlab.intsig.net/xparse1/xparse-pipeline
@@ -173,7 +173,7 @@ source = S3Source(
173
173
  bucket='textin',
174
174
  prefix='',
175
175
  region='us-east-1',
176
- pattern='*.pdf' # 可选,使用 Shell 通配符过滤对象
176
+ pattern=['*.pdf'] # 可选,通配符模式列表,支持多个扩展名
177
177
  )
178
178
  ```
179
179
  请确保配置的访问凭证至少包括以下几项权限:
@@ -193,7 +193,7 @@ source = S3Source(
193
193
  bucket='textin',
194
194
  prefix='',
195
195
  region='cn-shanghai',
196
- pattern='*.pdf' # 可选,使用 Shell 通配符过滤对象
196
+ pattern=['*.pdf'] # 可选,通配符模式列表,支持多个扩展名
197
197
  )
198
198
  ```
199
199
  请确保配置的访问凭证至少包括以下几项权限:
@@ -214,7 +214,7 @@ source = S3Source(
214
214
  bucket='textin',
215
215
  prefix='',
216
216
  region='ap-shanghai',
217
- pattern='*.pdf' # 可选,使用 Shell 通配符过滤对象
217
+ pattern=['*.pdf'] # 可选,通配符模式列表,支持多个扩展名
218
218
  )
219
219
  ```
220
220
 
@@ -235,7 +235,7 @@ source = S3Source(
235
235
  bucket='textin',
236
236
  prefix='',
237
237
  region='cn-shanghai',
238
- pattern='*.pdf' # 可选,使用 Shell 通配符过滤对象
238
+ pattern=['*.pdf'] # 可选,通配符模式列表,支持多个扩展名
239
239
  )
240
240
  ```
241
241
 
@@ -257,7 +257,7 @@ source = S3Source(
257
257
  bucket='textin',
258
258
  prefix='',
259
259
  region='cn-east-3',
260
- pattern='*.pdf' # 可选,使用 Shell 通配符过滤对象
260
+ pattern=['*.pdf'] # 可选,通配符模式列表,支持多个扩展名
261
261
  )
262
262
  ```
263
263
 
@@ -279,7 +279,7 @@ source = S3Source(
279
279
  bucket='textin-xparse',
280
280
  prefix='',
281
281
  region='us-east-1',
282
- pattern='*.pdf' # 可选,使用 Shell 通配符过滤对象
282
+ pattern=['*.pdf'] # 可选,通配符模式列表,支持多个扩展名
283
283
  )
284
284
  ```
285
285
  请确保配置的访问凭证至少包括以下几项权限:
@@ -294,7 +294,7 @@ s3:GetObject
294
294
  ```python
295
295
  source = LocalSource(
296
296
  directory='./input',
297
- pattern='*.pdf' # 支持通配符: *.pdf, *.docx, **/*.txt
297
+ pattern=['*.pdf', '*.docx'] # 支持多个通配符模式列表
298
298
  )
299
299
  ```
300
300
 
@@ -306,7 +306,7 @@ source = FtpSource(
306
306
  port=21,
307
307
  username='', # 用户名,按照实际填写
308
308
  password='', # 密码,按照实际填写
309
- pattern='*.pdf' # 可选,过滤指定类型文件
309
+ pattern=['*.pdf'] # 可选,通配符模式列表,过滤指定类型文件
310
310
  )
311
311
  ```
312
312
 
@@ -319,11 +319,11 @@ source = SmbSource(
319
319
  username='', # 用户名,按照实际填写
320
320
  password='', # 密码,按照实际填写
321
321
  domain='your-smb-domain',
322
- pattern='**/*.pdf' # 可选,支持多级匹配
322
+ pattern=['**/*.pdf'] # 可选,通配符模式列表,支持多级匹配
323
323
  )
324
324
  ```
325
325
 
326
- > 注 1:所有 Source 均支持 `pattern` 参数,使用 Shell 通配符(`*.pdf`、`**/*.txt` 等)来过滤需要处理的文件;默认为 `*`,即处理全部文件。
326
+ > 注 1:所有 Source 均支持 `pattern` 参数,使用通配符模式列表(如 `['*.pdf', '*.docx']`)来过滤需要处理的文件。支持多个通配符模式,如果列表中包含 `'*'` 则匹配所有文件。默认为 `None`,即处理全部文件。
327
327
 
328
328
  > 注 2:所有 Source 均支持 `recursive` 参数,表示是否递归遍历,默认为 `False`。
329
329
 
@@ -533,7 +533,7 @@ source = S3Source(
533
533
  bucket='documents',
534
534
  prefix='pdfs/',
535
535
  region='us-east-1',
536
- pattern='*.pdf', # 仅处理匹配的文件
536
+ pattern=['*.pdf'], # 仅处理匹配的文件
537
537
  recursive=False # 不递归子目录
538
538
  )
539
539
 
@@ -597,7 +597,7 @@ from xparse_client import (
597
597
  # 手动创建 Pipeline
598
598
  source = LocalSource(
599
599
  directory='./test_files',
600
- pattern='*.pdf',
600
+ pattern=['*.pdf'],
601
601
  recursive=False
602
602
  )
603
603
 
@@ -644,7 +644,7 @@ from xparse_client import (
644
644
  # 创建本地数据源
645
645
  source = LocalSource(
646
646
  directory='./test_files',
647
- pattern='*.pdf',
647
+ pattern=['*.pdf'],
648
648
  recursive=False
649
649
  )
650
650
 
@@ -771,7 +771,7 @@ source = FtpSource(
771
771
  port=21,
772
772
  username='user',
773
773
  password='pass',
774
- pattern='*.pdf',
774
+ pattern=['*.pdf'],
775
775
  recursive=False
776
776
  )
777
777
 
@@ -831,7 +831,7 @@ from xparse_client import (
831
831
  # 创建 Pipeline
832
832
  source = LocalSource(
833
833
  directory='./docs',
834
- pattern='*.pdf',
834
+ pattern=['*.pdf'],
835
835
  recursive=False
836
836
  )
837
837
 
@@ -0,0 +1,13 @@
1
+ example/run_pipeline.py,sha256=xZ8TLofrK7naEwBe-tiuotcQ8yKWUES_k9iCQcIOIYo,15446
2
+ example/run_pipeline_test.py,sha256=pxsNiq_LmP6M4R7tTuja0u-Lu7fW-wIBU1uBf0-agQI,14845
3
+ xparse_client/__init__.py,sha256=je1ena3HwLL4CRtLU4r6EAzoOIJthlPjTwshxZnzQDM,1677
4
+ xparse_client/pipeline/__init__.py,sha256=TVlb2AGCNKP0jrv3p4ZLZCPKp68hTVMFi00DTdi6QAo,49
5
+ xparse_client/pipeline/config.py,sha256=FFYq2a0dBWBEj70s2aInXOiQ5MwwHimd6SI2_tkp52w,4138
6
+ xparse_client/pipeline/destinations.py,sha256=F0z1AgVIBOn0m32i4l7LCMkJE0IbBdlpykO_at_wLaE,11931
7
+ xparse_client/pipeline/pipeline.py,sha256=IRTxN4YUJi9Wrm1G1ysGvcwsPsGh0inbquBH3nWYmAA,26477
8
+ xparse_client/pipeline/sources.py,sha256=D-kLrSQ-qsFFFq7JC4sL3Y3Q3Q87Wcpv9R5K85YkDjE,22144
9
+ xparse_client-0.2.9.dist-info/licenses/LICENSE,sha256=ckIP-MbocsP9nqYnta5KgfAicYF196B5TNdHIR6kOO0,1075
10
+ xparse_client-0.2.9.dist-info/METADATA,sha256=Faj3fvt9Fc-EW9yFDewhpkqGVo_qSvL5N-tq1aIkkyk,28086
11
+ xparse_client-0.2.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
12
+ xparse_client-0.2.9.dist-info/top_level.txt,sha256=bfX8BWo1sEEQVsI4Ql4Uu80vrfEh5zfajU9YqFTzxMo,22
13
+ xparse_client-0.2.9.dist-info/RECORD,,
@@ -1,13 +0,0 @@
1
- example/run_pipeline.py,sha256=ybAWBPXcQClRk1HOMySLi9IUPIs1Qn-S5HXNLbNJHjs,15459
2
- example/run_pipeline_test.py,sha256=uIU09FTv_VnTQS1Lc94ydc3kaD86eHkaHQbVXpsGEcA,14861
3
- xparse_client/__init__.py,sha256=je1ena3HwLL4CRtLU4r6EAzoOIJthlPjTwshxZnzQDM,1677
4
- xparse_client/pipeline/__init__.py,sha256=TVlb2AGCNKP0jrv3p4ZLZCPKp68hTVMFi00DTdi6QAo,49
5
- xparse_client/pipeline/config.py,sha256=FFYq2a0dBWBEj70s2aInXOiQ5MwwHimd6SI2_tkp52w,4138
6
- xparse_client/pipeline/destinations.py,sha256=F0z1AgVIBOn0m32i4l7LCMkJE0IbBdlpykO_at_wLaE,11931
7
- xparse_client/pipeline/pipeline.py,sha256=IRTxN4YUJi9Wrm1G1ysGvcwsPsGh0inbquBH3nWYmAA,26477
8
- xparse_client/pipeline/sources.py,sha256=UeVbWv6n0wQkIZIBBhrFCiyydQX7cvwmkoMgcf12p9g,19940
9
- xparse_client-0.2.8.dist-info/licenses/LICENSE,sha256=ckIP-MbocsP9nqYnta5KgfAicYF196B5TNdHIR6kOO0,1075
10
- xparse_client-0.2.8.dist-info/METADATA,sha256=LX8TfLSbFZerGPhh16x5QK1lwrPh55CYKNLhr2kdBcY,27850
11
- xparse_client-0.2.8.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
12
- xparse_client-0.2.8.dist-info/top_level.txt,sha256=bfX8BWo1sEEQVsI4Ql4Uu80vrfEh5zfajU9YqFTzxMo,22
13
- xparse_client-0.2.8.dist-info/RECORD,,