lattica-query 0.6.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.
@@ -0,0 +1,44 @@
1
+ TEMPORARY END USER LICENSE AGREEMENT FOR LATTICA-QUERY PACKAGE
2
+ Version 1.0 - Effective until April 7, 2025
3
+
4
+ IMPORTANT: READ CAREFULLY BEFORE DOWNLOADING, INSTALLING, COPYING, OR USING THE SOFTWARE
5
+
6
+ This Temporary End User License Agreement ("Agreement") is a legal agreement between you (either an individual or a single entity) and LatticaAI Inc. ("Licensor") for the software package identified above, which includes computer software and may include associated media, printed materials, and electronic documentation (collectively, the "Software").
7
+
8
+ BY DOWNLOADING, INSTALLING, COPYING, OR OTHERWISE USING THE SOFTWARE, YOU AGREE TO BE BOUND BY THE TERMS OF THIS AGREEMENT. IF YOU DO NOT AGREE TO THE TERMS OF THIS AGREEMENT, DO NOT DOWNLOAD, INSTALL, COPY, OR USE THE SOFTWARE.
9
+
10
+ 1. GRANT OF LICENSE
11
+ This is a TEMPORARY, NON-EXCLUSIVE, NON-TRANSFERABLE, REVOCABLE license to download and use the Software solely for evaluation purposes. This license explicitly DOES NOT permit any other use of the Software.
12
+
13
+ 2. RESTRICTIONS
14
+ a. You may NOT use the Software for any commercial purpose.
15
+ b. You may NOT redistribute, sell, rent, lease, sublicense, or otherwise transfer rights to the Software.
16
+ c. You may NOT modify, translate, reverse engineer, decompile, disassemble, or create derivative works based on the Software.
17
+ d. You may NOT copy the Software except as expressly permitted by this Agreement.
18
+ e. You may NOT remove any proprietary notices or labels on the Software.
19
+ f. You may NOT use the Software in any manner that could damage, disable, overburden, or impair Licensor's services.
20
+ g. You may NOT use the Software to violate any applicable laws or regulations.
21
+ h. You may NOT publish any benchmark or performance tests run on the Software.
22
+
23
+ 3. NO WARRANTY
24
+ THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT. THE ENTIRE RISK ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE REMAINS WITH YOU.
25
+
26
+ 4. LIMITATION OF LIABILITY
27
+ IN NO EVENT SHALL LICENSOR BE LIABLE FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR INABILITY TO USE THE SOFTWARE, EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
28
+
29
+ 5. TERMINATION
30
+ a. This Agreement is effective until April 7, 2025 or until terminated by Licensor.
31
+ b. This Agreement will terminate automatically without notice if you fail to comply with any provision of this Agreement.
32
+ c. Upon termination, you must destroy all copies of the Software.
33
+ d. Licensor reserves the right to replace this temporary Agreement with a permanent license agreement at any time.
34
+
35
+ 6. GOVERNING LAW
36
+ This Agreement shall be governed by the laws of the jurisdiction in which Licensor is located, without regard to its conflict of law principles.
37
+
38
+ 7. ENTIRE AGREEMENT
39
+ This Agreement constitutes the entire agreement between you and Licensor and supersedes any prior statements, representations, or agreements, whether oral or written.
40
+
41
+ 8. CONTACT INFORMATION
42
+ For questions regarding this Agreement, please contact: support@lattica.ai
43
+
44
+ © 2025 LatticaAI Inc. All rights reserved.
@@ -0,0 +1,29 @@
1
+ Metadata-Version: 2.3
2
+ Name: lattica-query
3
+ Version: 0.6.0
4
+ Summary: Lattica client
5
+ License: Proprietary
6
+ Author: LatticaAI Inc.
7
+ Author-email: hello@lattica.ai
8
+ Requires-Python: >=3.12,<4.0
9
+ Classifier: License :: Other/Proprietary License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Requires-Dist: lattica-common (>=0.5.0,<0.6.0)
14
+ Requires-Dist: timeit-decorator
15
+ Project-URL: Homepage, https://www.lattica.ai/
16
+ Description-Content-Type: text/markdown
17
+
18
+ # Lattica Query
19
+
20
+ This is the official Python client for Lattica's homomorphic encryption service.
21
+
22
+ ## Important Notice
23
+
24
+ This package is distributed under a restrictive proprietary license. Please see LICENSE.txt for the complete terms and conditions.
25
+
26
+ **Contact**: support@lattica.ai
27
+
28
+ © 2025 LatticaAI Inc. All rights reserved.
29
+
@@ -0,0 +1,11 @@
1
+ # Lattica Query
2
+
3
+ This is the official Python client for Lattica's homomorphic encryption service.
4
+
5
+ ## Important Notice
6
+
7
+ This package is distributed under a restrictive proprietary license. Please see LICENSE.txt for the complete terms and conditions.
8
+
9
+ **Contact**: support@lattica.ai
10
+
11
+ © 2025 LatticaAI Inc. All rights reserved.
File without changes
@@ -0,0 +1,18 @@
1
+ from lattica_common.app_api import HttpClient, generate_random_token_name
2
+
3
+
4
+ def get_demo_token(model_id: str) -> str:
5
+ http_client = HttpClient(None)
6
+ token_name = generate_random_token_name(10)
7
+ response = http_client.send_http_request(
8
+ "api/token/generate_token_demo",
9
+ req_params={
10
+ 'modelId': model_id,
11
+ 'tokenName': token_name
12
+ })
13
+ token = response.get('token')
14
+
15
+ if token is None:
16
+ raise ValueError("The response does not contain a 'token' field.")
17
+
18
+ return token
@@ -0,0 +1,14 @@
1
+ from lattica_query import hom_common
2
+ from lattica_common.app_api import LatticaAppAPI
3
+ from lattica_query.worker_api import LatticaWorkerAPI
4
+
5
+ # TODO (pavel): this script is not up to date and won't work!
6
+ worker_api_client = LatticaWorkerAPI("<YOUR-TOKEN-HERE>")
7
+ app_client = LatticaAppAPI("<YOUR-TOKEN-HERE>")
8
+
9
+ hom_common.user_client_init(
10
+ worker_api_client,
11
+ app_client,
12
+ secret_key_file_path='my_secret_key.lsk',
13
+ )
14
+
@@ -0,0 +1,28 @@
1
+ from lattica_query.internal_demos.lattica_query_client_local import LocalQueryClient
2
+ from lattica_common.internal_demos_common.common_demos_utils import print_query_result
3
+ from lattica_query.worker_api import LatticaWorkerAPI
4
+ import torch
5
+
6
+ import lattica_query.hom_common as hom_common
7
+
8
+
9
+ # TODO (pavel): this script is not up to date and won't work!
10
+ worker_api_client = LatticaWorkerAPI("<YOUR-TOKEN-HERE>")
11
+ query_client = LocalQueryClient("<YOUR-TOKEN-HERE>")
12
+
13
+ # or you can pass the token as an arg to `get_context':
14
+ serialized_context, serialized_homseq = worker_api_client.get_user_init_data()
15
+
16
+ print('Loading local secret key...')
17
+ serialized_sk = hom_common.read_byte_arrays_from_file('my_secret_key.lsk')
18
+
19
+ for i in range(5):
20
+ print(f'Iteration {i=}')
21
+
22
+ # create a plaintext tensor with the correct shape
23
+ data_pt = torch.rand(10, dtype=torch.float64)
24
+
25
+ pt_expected = query_client.apply_clear(data_pt)
26
+ print(f'Image {i=}')
27
+ pt_dec = query_client.run_query(serialized_context, serialized_sk, data_pt, serialized_homseq)
28
+ print_query_result(i, data_pt, pt_expected, pt_dec)
@@ -0,0 +1,61 @@
1
+ from typing import Optional, Tuple, Union, TYPE_CHECKING
2
+ import os
3
+
4
+ from lattica_common.app_api import LatticaAppAPI
5
+
6
+ from lattica import interface_query as toolkit_interface
7
+ from lattica_query.worker_api import LatticaWorkerAPI
8
+
9
+
10
+ def _write_byte_arrays_to_file(file_path, byte_array1, byte_array2):
11
+ with open(file_path, 'wb') as f:
12
+ # Write the length of the first byte array
13
+ f.write(len(byte_array1).to_bytes(4, byteorder='little'))
14
+ # Write the first byte array
15
+ f.write(byte_array1)
16
+ # Write the length of the second byte array
17
+ f.write(len(byte_array2).to_bytes(4, byteorder='little'))
18
+ # Write the second byte array
19
+ f.write(byte_array2)
20
+
21
+
22
+ def read_byte_arrays_from_file(file_path):
23
+ with open(file_path, 'rb') as f:
24
+ # Read the length of the first byte array
25
+ len1 = int.from_bytes(f.read(4), byteorder='little')
26
+ # Read the first byte array
27
+ byte_array1 = f.read(len1)
28
+ # Read the length of the second byte array
29
+ len2 = int.from_bytes(f.read(4), byteorder='little')
30
+ # Read the second byte array
31
+ byte_array2 = f.read(len2)
32
+
33
+ return byte_array1, byte_array2
34
+
35
+
36
+ def user_client_init(
37
+ worker_api_client: LatticaWorkerAPI,
38
+ app_client: LatticaAppAPI,
39
+ secret_key_file_path: Union[str, os.PathLike] = 'my_secret_key.lsk',
40
+ ) -> None:
41
+
42
+ serialized_context, serialized_homseq = worker_api_client.get_user_init_data()
43
+
44
+ print(f'Creating client FHE keys...')
45
+ serialized_secret_key, serialized_public_key = toolkit_interface.generate_key(
46
+ serialized_homseq, serialized_context)
47
+
48
+ # Store locally for later use file
49
+ _write_byte_arrays_to_file(secret_key_file_path, *serialized_secret_key)
50
+
51
+ print(f'Registering FHE public key...')
52
+ temp_filename = 'my_pk.lpk'
53
+ # Store as temp file
54
+ with open(temp_filename, 'wb') as handle:
55
+ handle.write(serialized_public_key)
56
+ # Upload to server
57
+ app_client.upload_user_file(temp_filename)
58
+ # Delete temp file
59
+ os.remove(temp_filename)
60
+ print(f'Preprocessing public key...')
61
+ worker_api_client.preprocess_pk()