synapse-sdk 1.0.0a23__py3-none-any.whl → 1.0.0a25__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.

Potentially problematic release.


This version of synapse-sdk might be problematic. Click here for more details.

@@ -1,10 +1,10 @@
1
1
  import tempfile
2
2
 
3
3
  import jwt
4
- from clients.backend import BackendClient
5
4
  from fastapi import FastAPI
6
5
  from ray import serve
7
6
 
7
+ from synapse_sdk.clients.backend import BackendClient
8
8
  from synapse_sdk.utils.file import unarchive
9
9
 
10
10
  app = FastAPI()
synapse_sdk/types.py ADDED
@@ -0,0 +1,19 @@
1
+ from typing import Any
2
+
3
+ from pydantic import HttpUrl
4
+ from pydantic_core import core_schema
5
+ from pydantic_core.core_schema import ValidationInfo
6
+
7
+ from synapse_sdk.utils.file import download_file, get_temp_path
8
+
9
+
10
+ class FileField(str):
11
+ @classmethod
12
+ def __get_pydantic_core_schema__(cls, source_type: Any, _handler: callable) -> core_schema.CoreSchema:
13
+ return core_schema.with_info_before_validator_function(cls.validate, core_schema.str_schema())
14
+
15
+ @staticmethod
16
+ def validate(url: HttpUrl, info: ValidationInfo) -> str:
17
+ path_download = get_temp_path('media')
18
+ path_download.mkdir(parents=True, exist_ok=True)
19
+ return str(download_file(url, path_download))
synapse_sdk/utils/file.py CHANGED
@@ -5,24 +5,33 @@ import operator
5
5
  import zipfile
6
6
  from functools import reduce
7
7
  from pathlib import Path
8
- from urllib.parse import urlparse
9
8
 
10
9
  import aiohttp
11
10
  import requests
12
11
  import yaml
13
12
 
13
+ from synapse_sdk.utils.string import hash_text
14
+
15
+
16
+ def download_file(url, path_download, name=None, coerce=None, use_cached=True):
17
+ chunk_size = 1024 * 1024 * 50
14
18
 
15
- def download_file(url, path_download, name=None, coerce=None):
16
19
  if name:
17
- name += Path(url).suffix
20
+ use_cached = False
18
21
  else:
19
- name = Path(url).name
22
+ name = hash_text(url)
23
+
24
+ name += Path(url).suffix
20
25
 
21
- name = urlparse(name).path
22
26
  path = Path(path_download) / name
23
- if not path.is_file():
24
- r = requests.get(url, allow_redirects=True)
25
- open(str(path), 'wb').write(r.content)
27
+
28
+ if not use_cached or not path.is_file():
29
+ response = requests.get(url, allow_redirects=True, stream=True)
30
+ response.raise_for_status()
31
+
32
+ with path.open('wb') as file:
33
+ for chunk in response.iter_content(chunk_size=chunk_size):
34
+ file.write(chunk)
26
35
 
27
36
  if coerce:
28
37
  path = coerce(path)
@@ -62,19 +71,23 @@ def files_url_to_path_from_objs(objs, files_fields, coerce=None, is_list=False,
62
71
  pass
63
72
 
64
73
 
65
- async def adownload_file(url, path_download, name=None, coerce=None):
74
+ async def adownload_file(url, path_download, name=None, coerce=None, use_cached=True):
75
+ chunk_size = 1024 * 1024 * 50
76
+
66
77
  if name:
67
- name += Path(url).suffix
78
+ use_cached = False
68
79
  else:
69
- name = Path(url).name
80
+ name = hash_text(url)
81
+
82
+ name += Path(url).suffix
70
83
 
71
- name = urlparse(name).path
72
84
  path = Path(path_download) / name
73
- if not path.is_file():
85
+
86
+ if not use_cached or not path.is_file():
74
87
  async with aiohttp.ClientSession() as session:
75
88
  async with session.get(url) as response:
76
- with open(str(path), 'wb') as file:
77
- while chunk := await response.content.read(1024 * 64):
89
+ with path.open('wb') as file:
90
+ while chunk := await response.content.read(chunk_size):
78
91
  file.write(chunk)
79
92
 
80
93
  if coerce:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: synapse-sdk
3
- Version: 1.0.0a23
3
+ Version: 1.0.0a25
4
4
  Summary: synapse sdk
5
5
  Author-email: datamaker <developer@datamaker.io>
6
6
  License: MIT
@@ -5,6 +5,7 @@ locale/ko/LC_MESSAGES/messages.po,sha256=TFii_RbURDH-Du_9ZQf3wNh-2briGk1IqY33-9G
5
5
  synapse_sdk/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  synapse_sdk/i18n.py,sha256=VXMR-Zm_1hTAg9iPk3YZNNq-T1Bhx1J2fEtRT6kyYbg,766
7
7
  synapse_sdk/loggers.py,sha256=RsDDOiOeUCih1XOkWQJseYdYCX_wt50AZJRe6aPf96Q,4004
8
+ synapse_sdk/types.py,sha256=khzn8KpgxFdn1SrpbcuX84m_Md1Mz_HIoUoPq8uok40,698
8
9
  synapse_sdk/cli/__init__.py,sha256=WmYGW1qZEXXIGJe3SGr8QjOStY4svuZKK1Lp_aPvtPs,140
9
10
  synapse_sdk/cli/create_plugin.py,sha256=egbW_92WwxfHz50Gy4znX5Bf5fxDdQj3GFyd0l3Y3SY,228
10
11
  synapse_sdk/clients/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -54,7 +55,7 @@ synapse_sdk/plugins/categories/neural_net/actions/inference.py,sha256=0a655ELqNV
54
55
  synapse_sdk/plugins/categories/neural_net/actions/test.py,sha256=JY25eg-Fo6WbgtMkGoo_qNqoaZkp3AQNEypJmeGzEog,320
55
56
  synapse_sdk/plugins/categories/neural_net/actions/train.py,sha256=4zq2ryWjqDa6MyI2BGe3sAofMh2NeY3XAo-1gEFXBs4,5145
56
57
  synapse_sdk/plugins/categories/neural_net/base/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
57
- synapse_sdk/plugins/categories/neural_net/base/inference.py,sha256=EgL_drVmQUtDKmS89mkDHyd7WyOZiUB65uxaomhZeAo,1085
58
+ synapse_sdk/plugins/categories/neural_net/base/inference.py,sha256=R5DASI6-5vzsjDOYxqeGGMBjnav5qHF4hNJT8zNUR3I,1097
58
59
  synapse_sdk/plugins/categories/neural_net/templates/config.yaml,sha256=dXKB1hO53hDZB73xnxLVCNQl8Sm7svMmVmuMrOCQmEU,343
59
60
  synapse_sdk/plugins/categories/neural_net/templates/plugin/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
60
61
  synapse_sdk/plugins/categories/neural_net/templates/plugin/inference.py,sha256=InfqKWJYi6sqiUnfPKHC5KYGhxckDaWZNQ202u-uVP4,366
@@ -98,7 +99,7 @@ synapse_sdk/shared/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuF
98
99
  synapse_sdk/shared/enums.py,sha256=WMZPag9deVF7VCXaQkLk7ly_uX1KwbNzRx9TdvgaeFE,138
99
100
  synapse_sdk/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
100
101
  synapse_sdk/utils/debug.py,sha256=F7JlUwYjTFZAMRbBqKm6hxOIz-_IXYA8lBInOS4jbS4,100
101
- synapse_sdk/utils/file.py,sha256=jfPHIwKBDE4akuckJsrVfOXBjWgEncFlzE5IUMSGmuE,5153
102
+ synapse_sdk/utils/file.py,sha256=HgSFZ5O_pYCumLH0Qft6C_NVz-H-ECaUfNcs3sTs43g,5443
102
103
  synapse_sdk/utils/module_loading.py,sha256=chHpU-BZjtYaTBD_q0T7LcKWtqKvYBS4L0lPlKkoMQ8,1020
103
104
  synapse_sdk/utils/storage.py,sha256=a8OVbd38ATr0El4G4kuV07lr_tJZrpIJBSy4GHb0qZ8,2581
104
105
  synapse_sdk/utils/string.py,sha256=rEwuZ9SAaZLcQ8TYiwNKr1h2u4CfnrQx7SUL8NWmChg,216
@@ -106,9 +107,9 @@ synapse_sdk/utils/pydantic/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJ
106
107
  synapse_sdk/utils/pydantic/config.py,sha256=1vYOcUI35GslfD1rrqhFkNXXJOXt4IDqOPSx9VWGfNE,123
107
108
  synapse_sdk/utils/pydantic/errors.py,sha256=0v0T12eQBr1KrFiEOBu6KMaPK4aPEGEC6etPJGoR5b4,1061
108
109
  synapse_sdk/utils/pydantic/validators.py,sha256=G47P8ObPhsePmd_QZDK8EdPnik2CbaYzr_N4Z6En8dc,193
109
- synapse_sdk-1.0.0a23.dist-info/LICENSE,sha256=bKzmC5YAg4V1Fhl8OO_tqY8j62hgdncAkN7VrdjmrGk,1101
110
- synapse_sdk-1.0.0a23.dist-info/METADATA,sha256=h1RJux0qCOIxJ69o70K5qUV0Zcd1z6HQf1CrU5w2XyE,1070
111
- synapse_sdk-1.0.0a23.dist-info/WHEEL,sha256=A3WOREP4zgxI0fKrHUG8DC8013e3dK3n7a6HDbcEIwE,91
112
- synapse_sdk-1.0.0a23.dist-info/entry_points.txt,sha256=VNptJoGoNJI8yLXfBmhgUefMsmGI0m3-0YoMvrOgbxo,48
113
- synapse_sdk-1.0.0a23.dist-info/top_level.txt,sha256=ytgJMRK1slVOKUpgcw3LEyHHP7S34J6n_gJzdkcSsw8,12
114
- synapse_sdk-1.0.0a23.dist-info/RECORD,,
110
+ synapse_sdk-1.0.0a25.dist-info/LICENSE,sha256=bKzmC5YAg4V1Fhl8OO_tqY8j62hgdncAkN7VrdjmrGk,1101
111
+ synapse_sdk-1.0.0a25.dist-info/METADATA,sha256=U7zm1tGFEUpAF4cjcsjPSXf1-RGR0GTD6cDyCeFA918,1070
112
+ synapse_sdk-1.0.0a25.dist-info/WHEEL,sha256=A3WOREP4zgxI0fKrHUG8DC8013e3dK3n7a6HDbcEIwE,91
113
+ synapse_sdk-1.0.0a25.dist-info/entry_points.txt,sha256=VNptJoGoNJI8yLXfBmhgUefMsmGI0m3-0YoMvrOgbxo,48
114
+ synapse_sdk-1.0.0a25.dist-info/top_level.txt,sha256=ytgJMRK1slVOKUpgcw3LEyHHP7S34J6n_gJzdkcSsw8,12
115
+ synapse_sdk-1.0.0a25.dist-info/RECORD,,