valgo 0.1.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.
- valgo-0.1.0/.github/workflows/CI.yml +32 -0
- valgo-0.1.0/.github/workflows/publish.yml +38 -0
- valgo-0.1.0/.gitignore +23 -0
- valgo-0.1.0/LICENSE +201 -0
- valgo-0.1.0/PKG-INFO +331 -0
- valgo-0.1.0/README.md +117 -0
- valgo-0.1.0/pyproject.toml +28 -0
- valgo-0.1.0/src/valgo/__init__.py +30 -0
- valgo-0.1.0/src/valgo/client.py +297 -0
- valgo-0.1.0/src/valgo/errors.py +30 -0
- valgo-0.1.0/src/valgo/models.py +56 -0
- valgo-0.1.0/tests/test_client.py +147 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
pull_request:
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
contents: read
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
test:
|
|
12
|
+
name: Python ${{ matrix.python-version }}
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
strategy:
|
|
15
|
+
fail-fast: false
|
|
16
|
+
matrix:
|
|
17
|
+
python-version: ["3.11", "3.12", "3.13"]
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v7
|
|
20
|
+
- uses: astral-sh/setup-uv@v10.0.1
|
|
21
|
+
with:
|
|
22
|
+
python-version: ${{ matrix.python-version }}
|
|
23
|
+
enable-cache: true
|
|
24
|
+
- run: uv sync --group dev
|
|
25
|
+
- run: uv run pytest
|
|
26
|
+
|
|
27
|
+
build:
|
|
28
|
+
runs-on: ubuntu-latest
|
|
29
|
+
steps:
|
|
30
|
+
- uses: actions/checkout@v7
|
|
31
|
+
- uses: astral-sh/setup-uv@v10.0.1
|
|
32
|
+
- run: uv build
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
contents: read
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
build:
|
|
12
|
+
name: Build distributions
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v7
|
|
16
|
+
- uses: astral-sh/setup-uv@v10.0.1
|
|
17
|
+
- run: uv build
|
|
18
|
+
- uses: actions/upload-artifact@v4
|
|
19
|
+
with:
|
|
20
|
+
name: distributions
|
|
21
|
+
path: dist/
|
|
22
|
+
if-no-files-found: error
|
|
23
|
+
|
|
24
|
+
publish:
|
|
25
|
+
name: Publish distributions
|
|
26
|
+
needs: build
|
|
27
|
+
runs-on: ubuntu-latest
|
|
28
|
+
environment:
|
|
29
|
+
name: pypi
|
|
30
|
+
url: https://pypi.org/project/valgo/
|
|
31
|
+
permissions:
|
|
32
|
+
id-token: write
|
|
33
|
+
steps:
|
|
34
|
+
- uses: actions/download-artifact@v4
|
|
35
|
+
with:
|
|
36
|
+
name: distributions
|
|
37
|
+
path: dist/
|
|
38
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
valgo-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
__pycache__/
|
|
2
|
+
*.py[cod]
|
|
3
|
+
*.egg-info/
|
|
4
|
+
.pytest_cache/
|
|
5
|
+
.ruff_cache/
|
|
6
|
+
.mypy_cache/
|
|
7
|
+
.coverage
|
|
8
|
+
htmlcov/
|
|
9
|
+
.venv/
|
|
10
|
+
dist/
|
|
11
|
+
build/
|
|
12
|
+
|
|
13
|
+
.env
|
|
14
|
+
.env.*
|
|
15
|
+
!.env.example
|
|
16
|
+
|
|
17
|
+
.DS_Store
|
|
18
|
+
|
|
19
|
+
*.pem
|
|
20
|
+
*.key
|
|
21
|
+
*.p12
|
|
22
|
+
*.pfx
|
|
23
|
+
credentials.json
|
valgo-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Valgorithmic, Inc. (d.b.a. Valgo)
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
valgo-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: valgo
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: The programmatic interface to Valgo
|
|
5
|
+
Project-URL: Homepage, https://valgo.ai
|
|
6
|
+
Project-URL: Repository, https://github.com/valgorithmic/valgo
|
|
7
|
+
Project-URL: Issues, https://github.com/valgorithmic/valgo/issues
|
|
8
|
+
Author: Valgorithmic, Inc. (d.b.a. Valgo)
|
|
9
|
+
License: Apache License
|
|
10
|
+
Version 2.0, January 2004
|
|
11
|
+
http://www.apache.org/licenses/
|
|
12
|
+
|
|
13
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
14
|
+
|
|
15
|
+
1. Definitions.
|
|
16
|
+
|
|
17
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
18
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
19
|
+
|
|
20
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
21
|
+
the copyright owner that is granting the License.
|
|
22
|
+
|
|
23
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
24
|
+
other entities that control, are controlled by, or are under common
|
|
25
|
+
control with that entity. For the purposes of this definition,
|
|
26
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
27
|
+
direction or management of such entity, whether by contract or
|
|
28
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
29
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
30
|
+
|
|
31
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
32
|
+
exercising permissions granted by this License.
|
|
33
|
+
|
|
34
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
35
|
+
including but not limited to software source code, documentation
|
|
36
|
+
source, and configuration files.
|
|
37
|
+
|
|
38
|
+
"Object" form shall mean any form resulting from mechanical
|
|
39
|
+
transformation or translation of a Source form, including but
|
|
40
|
+
not limited to compiled object code, generated documentation,
|
|
41
|
+
and conversions to other media types.
|
|
42
|
+
|
|
43
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
44
|
+
Object form, made available under the License, as indicated by a
|
|
45
|
+
copyright notice that is included in or attached to the work
|
|
46
|
+
(an example is provided in the Appendix below).
|
|
47
|
+
|
|
48
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
49
|
+
form, that is based on (or derived from) the Work and for which the
|
|
50
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
51
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
52
|
+
of this License, Derivative Works shall not include works that remain
|
|
53
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
54
|
+
the Work and Derivative Works thereof.
|
|
55
|
+
|
|
56
|
+
"Contribution" shall mean any work of authorship, including
|
|
57
|
+
the original version of the Work and any modifications or additions
|
|
58
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
59
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
60
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
61
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
62
|
+
means any form of electronic, verbal, or written communication sent
|
|
63
|
+
to the Licensor or its representatives, including but not limited to
|
|
64
|
+
communication on electronic mailing lists, source code control systems,
|
|
65
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
66
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
67
|
+
excluding communication that is conspicuously marked or otherwise
|
|
68
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
69
|
+
|
|
70
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
71
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
72
|
+
subsequently incorporated within the Work.
|
|
73
|
+
|
|
74
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
78
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
79
|
+
Work and such Derivative Works in Source or Object form.
|
|
80
|
+
|
|
81
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
82
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
83
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
84
|
+
(except as stated in this section) patent license to make, have made,
|
|
85
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
86
|
+
where such license applies only to those patent claims licensable
|
|
87
|
+
by such Contributor that are necessarily infringed by their
|
|
88
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
89
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
90
|
+
institute patent litigation against any entity (including a
|
|
91
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
92
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
93
|
+
or contributory patent infringement, then any patent licenses
|
|
94
|
+
granted to You under this License for that Work shall terminate
|
|
95
|
+
as of the date such litigation is filed.
|
|
96
|
+
|
|
97
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
98
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
99
|
+
modifications, and in Source or Object form, provided that You
|
|
100
|
+
meet the following conditions:
|
|
101
|
+
|
|
102
|
+
(a) You must give any other recipients of the Work or
|
|
103
|
+
Derivative Works a copy of this License; and
|
|
104
|
+
|
|
105
|
+
(b) You must cause any modified files to carry prominent notices
|
|
106
|
+
stating that You changed the files; and
|
|
107
|
+
|
|
108
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
109
|
+
that You distribute, all copyright, patent, trademark, and
|
|
110
|
+
attribution notices from the Source form of the Work,
|
|
111
|
+
excluding those notices that do not pertain to any part of
|
|
112
|
+
the Derivative Works; and
|
|
113
|
+
|
|
114
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
115
|
+
distribution, then any Derivative Works that You distribute must
|
|
116
|
+
include a readable copy of the attribution notices contained
|
|
117
|
+
within such NOTICE file, excluding those notices that do not
|
|
118
|
+
pertain to any part of the Derivative Works, in at least one
|
|
119
|
+
of the following places: within a NOTICE text file distributed
|
|
120
|
+
as part of the Derivative Works; within the Source form or
|
|
121
|
+
documentation, if provided along with the Derivative Works; or,
|
|
122
|
+
within a display generated by the Derivative Works, if and
|
|
123
|
+
wherever such third-party notices normally appear. The contents
|
|
124
|
+
of the NOTICE file are for informational purposes only and
|
|
125
|
+
do not modify the License. You may add Your own attribution
|
|
126
|
+
notices within Derivative Works that You distribute, alongside
|
|
127
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
128
|
+
that such additional attribution notices cannot be construed
|
|
129
|
+
as modifying the License.
|
|
130
|
+
|
|
131
|
+
You may add Your own copyright statement to Your modifications and
|
|
132
|
+
may provide additional or different license terms and conditions
|
|
133
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
134
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
135
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
136
|
+
the conditions stated in this License.
|
|
137
|
+
|
|
138
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
139
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
140
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
141
|
+
this License, without any additional terms or conditions.
|
|
142
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
143
|
+
the terms of any separate license agreement you may have executed
|
|
144
|
+
with Licensor regarding such Contributions.
|
|
145
|
+
|
|
146
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
147
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
148
|
+
except as required for reasonable and customary use in describing the
|
|
149
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
150
|
+
|
|
151
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
152
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
153
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
154
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
155
|
+
implied, including, without limitation, any warranties or conditions
|
|
156
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
157
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
158
|
+
appropriateness of using or redistributing the Work and assume any
|
|
159
|
+
risks associated with Your exercise of permissions under this License.
|
|
160
|
+
|
|
161
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
162
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
163
|
+
unless required by applicable law (such as deliberate and grossly
|
|
164
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
165
|
+
liable to You for damages, including any direct, indirect, special,
|
|
166
|
+
incidental, or consequential damages of any character arising as a
|
|
167
|
+
result of this License or out of the use or inability to use the
|
|
168
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
169
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
170
|
+
other commercial damages or losses), even if such Contributor
|
|
171
|
+
has been advised of the possibility of such damages.
|
|
172
|
+
|
|
173
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
174
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
175
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
176
|
+
or other liability obligations and/or rights consistent with this
|
|
177
|
+
License. However, in accepting such obligations, You may act only
|
|
178
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
179
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
180
|
+
defend, and hold each Contributor harmless for any liability
|
|
181
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
182
|
+
of your accepting any such warranty or additional liability.
|
|
183
|
+
|
|
184
|
+
END OF TERMS AND CONDITIONS
|
|
185
|
+
|
|
186
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
187
|
+
|
|
188
|
+
To apply the Apache License to your work, attach the following
|
|
189
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
190
|
+
replaced with your own identifying information. (Don't include
|
|
191
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
192
|
+
comment syntax for the file format. We also recommend that a
|
|
193
|
+
file or class name and description of purpose be included on the
|
|
194
|
+
same "printed page" as the copyright notice for easier
|
|
195
|
+
identification within third-party archives.
|
|
196
|
+
|
|
197
|
+
Copyright 2026 Valgorithmic, Inc. (d.b.a. Valgo)
|
|
198
|
+
|
|
199
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
200
|
+
you may not use this file except in compliance with the License.
|
|
201
|
+
You may obtain a copy of the License at
|
|
202
|
+
|
|
203
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
204
|
+
|
|
205
|
+
Unless required by applicable law or agreed to in writing, software
|
|
206
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
207
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
208
|
+
See the License for the specific language governing permissions and
|
|
209
|
+
limitations under the License.
|
|
210
|
+
License-File: LICENSE
|
|
211
|
+
Requires-Python: >=3.11
|
|
212
|
+
Requires-Dist: httpx<1,>=0.27
|
|
213
|
+
Description-Content-Type: text/markdown
|
|
214
|
+
|
|
215
|
+
# Valgo API
|
|
216
|
+
|
|
217
|
+
[](https://github.com/valgorithmic/valgo/actions/workflows/CI.yml)
|
|
218
|
+
[](https://pypi.org/project/valgo/)
|
|
219
|
+
|
|
220
|
+
The official Python client for the Valgo API to upload, share, and retrieve datasets programmatically.
|
|
221
|
+
|
|
222
|
+
## Installation
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
pip install valgo
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
Valgo supports Python 3.11 and newer.
|
|
229
|
+
|
|
230
|
+
## Quick start
|
|
231
|
+
|
|
232
|
+
Set the API key issued by your Valgo administrator:
|
|
233
|
+
|
|
234
|
+
```bash
|
|
235
|
+
export VALGO_API_KEY="valgo_live_..."
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
Upload a file:
|
|
239
|
+
|
|
240
|
+
```python
|
|
241
|
+
from valgo import Valgo
|
|
242
|
+
|
|
243
|
+
client = Valgo()
|
|
244
|
+
uploaded = client.upload("data/dataset.parquet")
|
|
245
|
+
print(uploaded.artifact_id)
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
The SDK connects to `https://api.valgo.ai` by default.
|
|
249
|
+
|
|
250
|
+
You can also pass the key directly:
|
|
251
|
+
|
|
252
|
+
```python
|
|
253
|
+
client = Valgo(api_key="valgo_live_...")
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## Uploads
|
|
257
|
+
|
|
258
|
+
Upload a file with an optional logical name and metadata:
|
|
259
|
+
|
|
260
|
+
```python
|
|
261
|
+
uploaded = client.upload(
|
|
262
|
+
"data/dataset.parquet",
|
|
263
|
+
name="datasets/dataset.parquet",
|
|
264
|
+
metadata={"source": "example"},
|
|
265
|
+
)
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
Directories are uploaded concurrently:
|
|
269
|
+
|
|
270
|
+
```python
|
|
271
|
+
result = client.upload("data/datasets")
|
|
272
|
+
|
|
273
|
+
for uploaded in result.completed:
|
|
274
|
+
print(uploaded.path, uploaded.artifact_id)
|
|
275
|
+
|
|
276
|
+
for failure in result.failures:
|
|
277
|
+
print(failure.path, failure.error)
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
Interrupted uploads are resumable. Retrying the same file continues the existing transfer rather than creating a duplicate.
|
|
281
|
+
|
|
282
|
+
## Downloads
|
|
283
|
+
|
|
284
|
+
Download the latest version by logical name:
|
|
285
|
+
|
|
286
|
+
```python
|
|
287
|
+
client.download("datasets/dataset.parquet", "downloads/dataset.parquet")
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
Or retrieve an exact immutable version:
|
|
291
|
+
|
|
292
|
+
```python
|
|
293
|
+
client.download(uploaded.artifact_id, "downloads/dataset.parquet")
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
The SDK verifies the downloaded size and SHA-256 checksum before replacing the destination file.
|
|
297
|
+
|
|
298
|
+
## Configuration
|
|
299
|
+
|
|
300
|
+
| Environment variable | Purpose | Default |
|
|
301
|
+
| --- | --- | --- |
|
|
302
|
+
| `VALGO_API_KEY` | Customer API credential | Required |
|
|
303
|
+
| `VALGO_BASE_URL` | Valgo API endpoint | `https://api.valgo.ai` |
|
|
304
|
+
|
|
305
|
+
Constructor arguments override environment variables:
|
|
306
|
+
|
|
307
|
+
```python
|
|
308
|
+
client = Valgo(
|
|
309
|
+
api_key="valgo_live_...",
|
|
310
|
+
base_url="https://api.valgo.ai",
|
|
311
|
+
timeout=60,
|
|
312
|
+
max_workers=8,
|
|
313
|
+
)
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
## Development
|
|
317
|
+
|
|
318
|
+
From this repository:
|
|
319
|
+
|
|
320
|
+
```bash
|
|
321
|
+
python -m pip install -e .
|
|
322
|
+
pytest
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
Do not commit API keys, presigned URLs, or customer data. Report security issues privately to the Valgo team rather than opening a public issue.
|
|
326
|
+
|
|
327
|
+
## License
|
|
328
|
+
|
|
329
|
+
Licensed under the [Apache License 2.0](LICENSE).
|
|
330
|
+
|
|
331
|
+
Copyright © 2026 Valgorithmic, Inc. (d.b.a. Valgo).
|
valgo-0.1.0/README.md
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# Valgo API
|
|
2
|
+
|
|
3
|
+
[](https://github.com/valgorithmic/valgo/actions/workflows/CI.yml)
|
|
4
|
+
[](https://pypi.org/project/valgo/)
|
|
5
|
+
|
|
6
|
+
The official Python client for the Valgo API to upload, share, and retrieve datasets programmatically.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
pip install valgo
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Valgo supports Python 3.11 and newer.
|
|
15
|
+
|
|
16
|
+
## Quick start
|
|
17
|
+
|
|
18
|
+
Set the API key issued by your Valgo administrator:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
export VALGO_API_KEY="valgo_live_..."
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Upload a file:
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
from valgo import Valgo
|
|
28
|
+
|
|
29
|
+
client = Valgo()
|
|
30
|
+
uploaded = client.upload("data/dataset.parquet")
|
|
31
|
+
print(uploaded.artifact_id)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
The SDK connects to `https://api.valgo.ai` by default.
|
|
35
|
+
|
|
36
|
+
You can also pass the key directly:
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
client = Valgo(api_key="valgo_live_...")
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Uploads
|
|
43
|
+
|
|
44
|
+
Upload a file with an optional logical name and metadata:
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
uploaded = client.upload(
|
|
48
|
+
"data/dataset.parquet",
|
|
49
|
+
name="datasets/dataset.parquet",
|
|
50
|
+
metadata={"source": "example"},
|
|
51
|
+
)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Directories are uploaded concurrently:
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
result = client.upload("data/datasets")
|
|
58
|
+
|
|
59
|
+
for uploaded in result.completed:
|
|
60
|
+
print(uploaded.path, uploaded.artifact_id)
|
|
61
|
+
|
|
62
|
+
for failure in result.failures:
|
|
63
|
+
print(failure.path, failure.error)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Interrupted uploads are resumable. Retrying the same file continues the existing transfer rather than creating a duplicate.
|
|
67
|
+
|
|
68
|
+
## Downloads
|
|
69
|
+
|
|
70
|
+
Download the latest version by logical name:
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
client.download("datasets/dataset.parquet", "downloads/dataset.parquet")
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Or retrieve an exact immutable version:
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
client.download(uploaded.artifact_id, "downloads/dataset.parquet")
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
The SDK verifies the downloaded size and SHA-256 checksum before replacing the destination file.
|
|
83
|
+
|
|
84
|
+
## Configuration
|
|
85
|
+
|
|
86
|
+
| Environment variable | Purpose | Default |
|
|
87
|
+
| --- | --- | --- |
|
|
88
|
+
| `VALGO_API_KEY` | Customer API credential | Required |
|
|
89
|
+
| `VALGO_BASE_URL` | Valgo API endpoint | `https://api.valgo.ai` |
|
|
90
|
+
|
|
91
|
+
Constructor arguments override environment variables:
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
client = Valgo(
|
|
95
|
+
api_key="valgo_live_...",
|
|
96
|
+
base_url="https://api.valgo.ai",
|
|
97
|
+
timeout=60,
|
|
98
|
+
max_workers=8,
|
|
99
|
+
)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Development
|
|
103
|
+
|
|
104
|
+
From this repository:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
python -m pip install -e .
|
|
108
|
+
pytest
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Do not commit API keys, presigned URLs, or customer data. Report security issues privately to the Valgo team rather than opening a public issue.
|
|
112
|
+
|
|
113
|
+
## License
|
|
114
|
+
|
|
115
|
+
Licensed under the [Apache License 2.0](LICENSE).
|
|
116
|
+
|
|
117
|
+
Copyright © 2026 Valgorithmic, Inc. (d.b.a. Valgo).
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "valgo"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "The programmatic interface to Valgo"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = { file = "LICENSE" }
|
|
7
|
+
authors = [{ name = "Valgorithmic, Inc. (d.b.a. Valgo)" }]
|
|
8
|
+
requires-python = ">=3.11"
|
|
9
|
+
dependencies = ["httpx>=0.27,<1"]
|
|
10
|
+
|
|
11
|
+
[project.urls]
|
|
12
|
+
Homepage = "https://valgo.ai"
|
|
13
|
+
Repository = "https://github.com/valgorithmic/valgo"
|
|
14
|
+
Issues = "https://github.com/valgorithmic/valgo/issues"
|
|
15
|
+
|
|
16
|
+
[build-system]
|
|
17
|
+
requires = ["hatchling>=1.27"]
|
|
18
|
+
build-backend = "hatchling.build"
|
|
19
|
+
|
|
20
|
+
[tool.hatch.build.targets.wheel]
|
|
21
|
+
packages = ["src/valgo"]
|
|
22
|
+
|
|
23
|
+
[dependency-groups]
|
|
24
|
+
dev = ["pytest>=8.3"]
|
|
25
|
+
|
|
26
|
+
[tool.pytest.ini_options]
|
|
27
|
+
testpaths = ["tests"]
|
|
28
|
+
addopts = "-q"
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from .client import Valgo
|
|
2
|
+
from .errors import (
|
|
3
|
+
AuthenticationError,
|
|
4
|
+
AuthorizationError,
|
|
5
|
+
ConflictError,
|
|
6
|
+
IntegrityError,
|
|
7
|
+
NotFoundError,
|
|
8
|
+
TransferError,
|
|
9
|
+
ValgoError,
|
|
10
|
+
ValidationError,
|
|
11
|
+
)
|
|
12
|
+
from .models import Artifact, BatchUploadResult, UploadFailure, UploadResult
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"Artifact",
|
|
16
|
+
"AuthenticationError",
|
|
17
|
+
"AuthorizationError",
|
|
18
|
+
"BatchUploadResult",
|
|
19
|
+
"ConflictError",
|
|
20
|
+
"IntegrityError",
|
|
21
|
+
"NotFoundError",
|
|
22
|
+
"TransferError",
|
|
23
|
+
"UploadFailure",
|
|
24
|
+
"UploadResult",
|
|
25
|
+
"ValidationError",
|
|
26
|
+
"Valgo",
|
|
27
|
+
"ValgoError",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import base64
|
|
4
|
+
import hashlib
|
|
5
|
+
import mimetypes
|
|
6
|
+
import os
|
|
7
|
+
import random
|
|
8
|
+
import time
|
|
9
|
+
from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from typing import Any
|
|
12
|
+
|
|
13
|
+
import httpx
|
|
14
|
+
|
|
15
|
+
from .errors import (
|
|
16
|
+
AuthenticationError,
|
|
17
|
+
AuthorizationError,
|
|
18
|
+
ConflictError,
|
|
19
|
+
IntegrityError,
|
|
20
|
+
NotFoundError,
|
|
21
|
+
TransferError,
|
|
22
|
+
ValgoError,
|
|
23
|
+
ValidationError,
|
|
24
|
+
)
|
|
25
|
+
from .models import Artifact, BatchUploadResult, UploadFailure, UploadResult
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class Valgo:
|
|
29
|
+
def __init__(
|
|
30
|
+
self,
|
|
31
|
+
api_key: str | None = None,
|
|
32
|
+
base_url: str | None = None,
|
|
33
|
+
timeout: float = 30,
|
|
34
|
+
max_workers: int = 4,
|
|
35
|
+
) -> None:
|
|
36
|
+
self.api_key = api_key or os.getenv("VALGO_API_KEY")
|
|
37
|
+
if not self.api_key:
|
|
38
|
+
raise ValueError("api_key is required (or set VALGO_API_KEY)")
|
|
39
|
+
self.base_url = (base_url or os.getenv("VALGO_BASE_URL") or "https://api.valgo.ai").rstrip("/")
|
|
40
|
+
self.max_workers = max(1, max_workers)
|
|
41
|
+
self._http = httpx.Client(
|
|
42
|
+
timeout=timeout,
|
|
43
|
+
headers={"Authorization": f"Bearer {self.api_key}", "User-Agent": "valgo-python/0.1.0"},
|
|
44
|
+
)
|
|
45
|
+
# Presigned object-store requests must never inherit the Valgo bearer credential.
|
|
46
|
+
self._storage_http = httpx.Client(timeout=timeout, headers={"User-Agent": "valgo-python/0.1.0"})
|
|
47
|
+
|
|
48
|
+
def __enter__(self) -> Valgo:
|
|
49
|
+
return self
|
|
50
|
+
|
|
51
|
+
def __exit__(self, *_: object) -> None:
|
|
52
|
+
self.close()
|
|
53
|
+
|
|
54
|
+
def close(self) -> None:
|
|
55
|
+
self._http.close()
|
|
56
|
+
self._storage_http.close()
|
|
57
|
+
|
|
58
|
+
def _request(self, method: str, path: str, **kwargs: Any) -> dict[str, Any]:
|
|
59
|
+
url = f"{self.base_url}{path}"
|
|
60
|
+
response: httpx.Response | None = None
|
|
61
|
+
for attempt in range(5):
|
|
62
|
+
try:
|
|
63
|
+
response = self._http.request(method, url, **kwargs)
|
|
64
|
+
except httpx.TransportError as exc:
|
|
65
|
+
if attempt == 4:
|
|
66
|
+
raise TransferError(f"Valgo API request failed: {exc}") from exc
|
|
67
|
+
self._backoff(attempt)
|
|
68
|
+
continue
|
|
69
|
+
if response.status_code not in {429, 500, 502, 503, 504} or attempt == 4:
|
|
70
|
+
break
|
|
71
|
+
self._backoff(attempt)
|
|
72
|
+
assert response is not None
|
|
73
|
+
if response.is_error:
|
|
74
|
+
try:
|
|
75
|
+
detail = response.json().get("detail", response.text)
|
|
76
|
+
except ValueError:
|
|
77
|
+
detail = response.text
|
|
78
|
+
errors: dict[int, type[ValgoError]] = {
|
|
79
|
+
401: AuthenticationError,
|
|
80
|
+
403: AuthorizationError,
|
|
81
|
+
404: NotFoundError,
|
|
82
|
+
409: ConflictError,
|
|
83
|
+
422: ValidationError,
|
|
84
|
+
}
|
|
85
|
+
error = errors.get(response.status_code, TransferError)
|
|
86
|
+
raise error(f"Valgo API returned {response.status_code}: {detail}")
|
|
87
|
+
return response.json() if response.content else {}
|
|
88
|
+
|
|
89
|
+
@staticmethod
|
|
90
|
+
def _backoff(attempt: int) -> None:
|
|
91
|
+
time.sleep(min(0.25 * (2**attempt) + random.random() * 0.1, 3.0))
|
|
92
|
+
|
|
93
|
+
@staticmethod
|
|
94
|
+
def _hash_file(path: Path) -> str:
|
|
95
|
+
digest = hashlib.sha256()
|
|
96
|
+
with path.open("rb") as stream:
|
|
97
|
+
for chunk in iter(lambda: stream.read(1024 * 1024), b""):
|
|
98
|
+
digest.update(chunk)
|
|
99
|
+
return digest.hexdigest()
|
|
100
|
+
|
|
101
|
+
def upload(
|
|
102
|
+
self,
|
|
103
|
+
path: str | os.PathLike[str],
|
|
104
|
+
*,
|
|
105
|
+
name: str | None = None,
|
|
106
|
+
metadata: dict[str, Any] | None = None,
|
|
107
|
+
) -> UploadResult | BatchUploadResult:
|
|
108
|
+
source = Path(path)
|
|
109
|
+
if not source.exists():
|
|
110
|
+
raise FileNotFoundError(source)
|
|
111
|
+
if source.is_symlink():
|
|
112
|
+
raise ValidationError("symbolic links are not uploaded")
|
|
113
|
+
if source.is_file():
|
|
114
|
+
return self._upload_file(source, name or source.name, metadata or {})
|
|
115
|
+
if not source.is_dir():
|
|
116
|
+
raise ValidationError("upload source must be a regular file or directory")
|
|
117
|
+
files = sorted(item for item in source.rglob("*") if item.is_file() and not item.is_symlink())
|
|
118
|
+
completed: list[UploadResult] = []
|
|
119
|
+
failures: list[UploadFailure] = []
|
|
120
|
+
with ThreadPoolExecutor(max_workers=self.max_workers) as pool:
|
|
121
|
+
futures = {}
|
|
122
|
+
for item in files:
|
|
123
|
+
relative = item.relative_to(source).as_posix()
|
|
124
|
+
logical_name = f"{name.strip('/')}/{relative}" if name else relative
|
|
125
|
+
futures[pool.submit(self._upload_file, item, logical_name, metadata or {})] = item
|
|
126
|
+
for future in as_completed(futures):
|
|
127
|
+
item = futures[future]
|
|
128
|
+
try:
|
|
129
|
+
completed.append(future.result())
|
|
130
|
+
except Exception as exc: # batch contract captures per-file failures
|
|
131
|
+
failures.append(UploadFailure(path=item, error=exc))
|
|
132
|
+
completed.sort(key=lambda item: str(item.path))
|
|
133
|
+
failures.sort(key=lambda item: str(item.path))
|
|
134
|
+
return BatchUploadResult(completed=completed, failures=failures)
|
|
135
|
+
|
|
136
|
+
def _upload_file(self, path: Path, name: str, metadata: dict[str, Any]) -> UploadResult:
|
|
137
|
+
size = path.stat().st_size
|
|
138
|
+
checksum = self._hash_file(path)
|
|
139
|
+
idempotency = hashlib.sha256(f"{name}\0{size}\0{checksum}".encode()).hexdigest()
|
|
140
|
+
initiation = self._request(
|
|
141
|
+
"POST",
|
|
142
|
+
"/v1/uploads",
|
|
143
|
+
json={
|
|
144
|
+
"name": name,
|
|
145
|
+
"size_bytes": size,
|
|
146
|
+
"checksum_sha256": checksum,
|
|
147
|
+
"content_type": mimetypes.guess_type(path.name)[0] or "application/octet-stream",
|
|
148
|
+
"metadata": metadata,
|
|
149
|
+
"idempotency_key": idempotency,
|
|
150
|
+
},
|
|
151
|
+
)
|
|
152
|
+
resumed = bool(initiation.get("uploaded_parts"))
|
|
153
|
+
if initiation["status"] == "completed":
|
|
154
|
+
artifact = Artifact(
|
|
155
|
+
artifact_id=initiation["artifact_id"],
|
|
156
|
+
artifact_version_id=initiation["artifact_version_id"],
|
|
157
|
+
name=initiation["name"],
|
|
158
|
+
version=initiation["version"],
|
|
159
|
+
size_bytes=size,
|
|
160
|
+
checksum_sha256=checksum,
|
|
161
|
+
storage_mode="unknown",
|
|
162
|
+
)
|
|
163
|
+
return UploadResult(path, artifact, initiation["transfer_id"], resumed=True)
|
|
164
|
+
if initiation["strategy"] == "single":
|
|
165
|
+
self._upload_single(path, initiation)
|
|
166
|
+
parts: list[dict[str, Any]] = []
|
|
167
|
+
else:
|
|
168
|
+
parts = self._upload_multipart(path, initiation)
|
|
169
|
+
artifact_data = self._request(
|
|
170
|
+
"POST", f"/v1/uploads/{initiation['transfer_id']}/complete", json={"parts": parts}
|
|
171
|
+
)
|
|
172
|
+
return UploadResult(
|
|
173
|
+
path=path,
|
|
174
|
+
artifact=Artifact.from_dict(artifact_data),
|
|
175
|
+
transfer_id=initiation["transfer_id"],
|
|
176
|
+
resumed=resumed,
|
|
177
|
+
)
|
|
178
|
+
|
|
179
|
+
def _upload_single(self, path: Path, initiation: dict[str, Any]) -> None:
|
|
180
|
+
current = initiation
|
|
181
|
+
last_error = "no storage response"
|
|
182
|
+
for attempt in range(5):
|
|
183
|
+
headers = dict(current.get("required_headers", {}))
|
|
184
|
+
headers["content-length"] = str(path.stat().st_size)
|
|
185
|
+
with path.open("rb") as stream:
|
|
186
|
+
response = self._storage_http.put(current["upload_url"], headers=headers, content=stream)
|
|
187
|
+
if response.is_success:
|
|
188
|
+
return
|
|
189
|
+
detail = response.text.strip().replace("\n", " ")[:500]
|
|
190
|
+
last_error = f"HTTP {response.status_code}" + (f": {detail}" if detail else "")
|
|
191
|
+
if response.status_code == 403:
|
|
192
|
+
current = self._request("GET", f"/v1/uploads/{initiation['transfer_id']}")
|
|
193
|
+
elif response.status_code >= 500:
|
|
194
|
+
self._backoff(attempt)
|
|
195
|
+
else:
|
|
196
|
+
raise TransferError(f"object upload failed with status {response.status_code}")
|
|
197
|
+
raise TransferError(f"object upload failed after retries ({last_error})")
|
|
198
|
+
|
|
199
|
+
def _upload_multipart(self, path: Path, initiation: dict[str, Any]) -> list[dict[str, Any]]:
|
|
200
|
+
part_size = int(initiation["part_size"])
|
|
201
|
+
size = path.stat().st_size
|
|
202
|
+
total = (size + part_size - 1) // part_size
|
|
203
|
+
completed = {part["part_number"]: part for part in initiation.get("uploaded_parts", [])}
|
|
204
|
+
missing = [number for number in range(1, total + 1) if number not in completed]
|
|
205
|
+
with ThreadPoolExecutor(max_workers=self.max_workers) as pool:
|
|
206
|
+
futures = {
|
|
207
|
+
pool.submit(self._upload_part, path, initiation["transfer_id"], number, part_size): number
|
|
208
|
+
for number in missing
|
|
209
|
+
}
|
|
210
|
+
for future in as_completed(futures):
|
|
211
|
+
part = future.result()
|
|
212
|
+
completed[part["part_number"]] = part
|
|
213
|
+
return [completed[number] for number in sorted(completed)]
|
|
214
|
+
|
|
215
|
+
def _upload_part(self, path: Path, transfer_id: str, number: int, part_size: int) -> dict[str, Any]:
|
|
216
|
+
with path.open("rb") as stream:
|
|
217
|
+
stream.seek((number - 1) * part_size)
|
|
218
|
+
data = stream.read(part_size)
|
|
219
|
+
checksum = base64.b64encode(hashlib.sha256(data).digest()).decode()
|
|
220
|
+
for attempt in range(5):
|
|
221
|
+
signed = self._request(
|
|
222
|
+
"POST",
|
|
223
|
+
f"/v1/uploads/{transfer_id}/parts/presign",
|
|
224
|
+
json={"parts": [{"part_number": number, "checksum_sha256": checksum}]},
|
|
225
|
+
)["parts"][0]
|
|
226
|
+
response = self._storage_http.put(
|
|
227
|
+
signed["upload_url"],
|
|
228
|
+
headers=signed["required_headers"] | {"content-length": str(len(data))},
|
|
229
|
+
content=data,
|
|
230
|
+
)
|
|
231
|
+
if response.is_success:
|
|
232
|
+
return {
|
|
233
|
+
"part_number": number,
|
|
234
|
+
"etag": response.headers["etag"],
|
|
235
|
+
"checksum_sha256": response.headers.get("x-amz-checksum-sha256", checksum),
|
|
236
|
+
"size_bytes": len(data),
|
|
237
|
+
}
|
|
238
|
+
if response.status_code not in {403, 429} and response.status_code < 500:
|
|
239
|
+
raise TransferError(f"part {number} failed with status {response.status_code}")
|
|
240
|
+
self._backoff(attempt)
|
|
241
|
+
raise TransferError(f"part {number} failed after retries")
|
|
242
|
+
|
|
243
|
+
def attach(
|
|
244
|
+
self,
|
|
245
|
+
s3_uri: str,
|
|
246
|
+
*,
|
|
247
|
+
name: str | None = None,
|
|
248
|
+
metadata: dict[str, Any] | None = None,
|
|
249
|
+
checksum_sha256: str | None = None,
|
|
250
|
+
) -> Artifact:
|
|
251
|
+
value = self._request(
|
|
252
|
+
"POST",
|
|
253
|
+
"/v1/attachments",
|
|
254
|
+
json={
|
|
255
|
+
"uri": s3_uri,
|
|
256
|
+
"name": name,
|
|
257
|
+
"metadata": metadata or {},
|
|
258
|
+
"checksum_sha256": checksum_sha256,
|
|
259
|
+
},
|
|
260
|
+
)
|
|
261
|
+
return Artifact.from_dict(value)
|
|
262
|
+
|
|
263
|
+
def download(
|
|
264
|
+
self,
|
|
265
|
+
artifact_id_or_name: str,
|
|
266
|
+
destination: str | os.PathLike[str] | None = None,
|
|
267
|
+
*,
|
|
268
|
+
overwrite: bool = False,
|
|
269
|
+
) -> Path:
|
|
270
|
+
signed = self._request("POST", "/v1/downloads", json={"artifact": artifact_id_or_name})
|
|
271
|
+
artifact = Artifact.from_dict(signed["artifact"])
|
|
272
|
+
target = Path(destination) if destination is not None else Path(artifact.name).name
|
|
273
|
+
target = Path(target)
|
|
274
|
+
if target.exists() and not overwrite:
|
|
275
|
+
raise FileExistsError(target)
|
|
276
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
277
|
+
temporary = target.with_name(f".{target.name}.valgo-part")
|
|
278
|
+
digest = hashlib.sha256()
|
|
279
|
+
size = 0
|
|
280
|
+
try:
|
|
281
|
+
with self._storage_http.stream("GET", signed["download_url"]) as response:
|
|
282
|
+
if response.is_error:
|
|
283
|
+
raise TransferError(f"object download failed with status {response.status_code}")
|
|
284
|
+
with temporary.open("wb") as stream:
|
|
285
|
+
for chunk in response.iter_bytes():
|
|
286
|
+
stream.write(chunk)
|
|
287
|
+
digest.update(chunk)
|
|
288
|
+
size += len(chunk)
|
|
289
|
+
if size != artifact.size_bytes:
|
|
290
|
+
raise IntegrityError("downloaded size does not match artifact metadata")
|
|
291
|
+
if artifact.checksum_sha256 and digest.hexdigest() != artifact.checksum_sha256:
|
|
292
|
+
raise IntegrityError("downloaded checksum does not match artifact metadata")
|
|
293
|
+
temporary.replace(target)
|
|
294
|
+
except Exception:
|
|
295
|
+
temporary.unlink(missing_ok=True)
|
|
296
|
+
raise
|
|
297
|
+
return target
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
class ValgoError(Exception):
|
|
2
|
+
"""Base exception for the Valgo SDK."""
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class AuthenticationError(ValgoError):
|
|
6
|
+
pass
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class AuthorizationError(ValgoError):
|
|
10
|
+
pass
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class NotFoundError(ValgoError):
|
|
14
|
+
pass
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class ConflictError(ValgoError):
|
|
18
|
+
pass
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class ValidationError(ValgoError):
|
|
22
|
+
pass
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class TransferError(ValgoError):
|
|
26
|
+
pass
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class IntegrityError(TransferError):
|
|
30
|
+
pass
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@dataclass(frozen=True)
|
|
9
|
+
class Artifact:
|
|
10
|
+
artifact_id: str
|
|
11
|
+
artifact_version_id: str
|
|
12
|
+
name: str
|
|
13
|
+
version: int
|
|
14
|
+
size_bytes: int
|
|
15
|
+
checksum_sha256: str | None
|
|
16
|
+
storage_mode: str
|
|
17
|
+
|
|
18
|
+
@classmethod
|
|
19
|
+
def from_dict(cls, value: dict[str, Any]) -> Artifact:
|
|
20
|
+
return cls(
|
|
21
|
+
artifact_id=value["artifact_id"],
|
|
22
|
+
artifact_version_id=value["artifact_version_id"],
|
|
23
|
+
name=value["name"],
|
|
24
|
+
version=value["version"],
|
|
25
|
+
size_bytes=value["size_bytes"],
|
|
26
|
+
checksum_sha256=value.get("checksum_sha256"),
|
|
27
|
+
storage_mode=value["storage_mode"],
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@dataclass(frozen=True)
|
|
32
|
+
class UploadResult:
|
|
33
|
+
path: Path
|
|
34
|
+
artifact: Artifact
|
|
35
|
+
transfer_id: str
|
|
36
|
+
resumed: bool = False
|
|
37
|
+
|
|
38
|
+
@property
|
|
39
|
+
def artifact_id(self) -> str:
|
|
40
|
+
return self.artifact.artifact_version_id
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
@dataclass(frozen=True)
|
|
44
|
+
class UploadFailure:
|
|
45
|
+
path: Path
|
|
46
|
+
error: Exception
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@dataclass(frozen=True)
|
|
50
|
+
class BatchUploadResult:
|
|
51
|
+
completed: list[UploadResult] = field(default_factory=list)
|
|
52
|
+
failures: list[UploadFailure] = field(default_factory=list)
|
|
53
|
+
|
|
54
|
+
@property
|
|
55
|
+
def ok(self) -> bool:
|
|
56
|
+
return not self.failures
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import hashlib
|
|
4
|
+
import json
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
import httpx
|
|
8
|
+
import pytest
|
|
9
|
+
from valgo import BatchUploadResult, IntegrityError, Valgo
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def json_response(status: int, body: dict[str, object]) -> httpx.Response:
|
|
13
|
+
return httpx.Response(status, content=json.dumps(body), headers={"content-type": "application/json"})
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def test_single_upload_and_download(tmp_path: Path) -> None:
|
|
17
|
+
source = tmp_path / "dataset.bin"
|
|
18
|
+
source.write_bytes(b"test-data")
|
|
19
|
+
checksum = hashlib.sha256(b"test-data").hexdigest()
|
|
20
|
+
|
|
21
|
+
def handler(request: httpx.Request) -> httpx.Response:
|
|
22
|
+
if request.url.path == "/v1/uploads":
|
|
23
|
+
return json_response(
|
|
24
|
+
200,
|
|
25
|
+
{
|
|
26
|
+
"transfer_id": "transfer-1",
|
|
27
|
+
"artifact_id": "artifact-1",
|
|
28
|
+
"artifact_version_id": "version-1",
|
|
29
|
+
"name": "dataset.bin",
|
|
30
|
+
"version": 1,
|
|
31
|
+
"status": "uploading",
|
|
32
|
+
"strategy": "single",
|
|
33
|
+
"upload_url": "https://storage.test/object",
|
|
34
|
+
"required_headers": {},
|
|
35
|
+
"uploaded_parts": [],
|
|
36
|
+
},
|
|
37
|
+
)
|
|
38
|
+
if request.url.host == "storage.test" and request.method == "PUT":
|
|
39
|
+
assert "authorization" not in request.headers
|
|
40
|
+
assert request.read() == b"test-data"
|
|
41
|
+
return httpx.Response(200)
|
|
42
|
+
if request.url.path.endswith("/complete"):
|
|
43
|
+
return json_response(
|
|
44
|
+
200,
|
|
45
|
+
{
|
|
46
|
+
"artifact_id": "artifact-1",
|
|
47
|
+
"artifact_version_id": "version-1",
|
|
48
|
+
"name": "dataset.bin",
|
|
49
|
+
"version": 1,
|
|
50
|
+
"size_bytes": 9,
|
|
51
|
+
"checksum_sha256": checksum,
|
|
52
|
+
"storage_mode": "hosted",
|
|
53
|
+
"status": "completed",
|
|
54
|
+
"completed_at": None,
|
|
55
|
+
},
|
|
56
|
+
)
|
|
57
|
+
if request.url.path == "/v1/downloads":
|
|
58
|
+
return json_response(
|
|
59
|
+
200,
|
|
60
|
+
{
|
|
61
|
+
"artifact": {
|
|
62
|
+
"artifact_id": "artifact-1",
|
|
63
|
+
"artifact_version_id": "version-1",
|
|
64
|
+
"name": "dataset.bin",
|
|
65
|
+
"version": 1,
|
|
66
|
+
"size_bytes": 9,
|
|
67
|
+
"checksum_sha256": checksum,
|
|
68
|
+
"storage_mode": "hosted",
|
|
69
|
+
},
|
|
70
|
+
"download_url": "https://storage.test/object",
|
|
71
|
+
"expires_in": 900,
|
|
72
|
+
},
|
|
73
|
+
)
|
|
74
|
+
if request.url.host == "storage.test" and request.method == "GET":
|
|
75
|
+
assert "authorization" not in request.headers
|
|
76
|
+
return httpx.Response(200, content=b"test-data")
|
|
77
|
+
return httpx.Response(500)
|
|
78
|
+
|
|
79
|
+
client = Valgo("valgo_live_test_secret", base_url="https://api.test")
|
|
80
|
+
client._http.close()
|
|
81
|
+
client._http = httpx.Client(transport=httpx.MockTransport(handler))
|
|
82
|
+
client._storage_http.close()
|
|
83
|
+
client._storage_http = httpx.Client(transport=httpx.MockTransport(handler))
|
|
84
|
+
|
|
85
|
+
uploaded = client.upload(source)
|
|
86
|
+
assert uploaded.artifact_id == "version-1"
|
|
87
|
+
|
|
88
|
+
destination = client.download("artifact-1", tmp_path / "download.bin")
|
|
89
|
+
assert destination.read_bytes() == b"test-data"
|
|
90
|
+
client.close()
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def test_directory_upload_collects_failures(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
|
94
|
+
directory = tmp_path / "datasets"
|
|
95
|
+
directory.mkdir()
|
|
96
|
+
(directory / "good.bin").write_bytes(b"good")
|
|
97
|
+
(directory / "bad.bin").write_bytes(b"bad")
|
|
98
|
+
client = Valgo("valgo_live_test_secret")
|
|
99
|
+
|
|
100
|
+
def fake_upload(path: Path, name: str, metadata: dict[str, object]) -> object:
|
|
101
|
+
if path.name == "bad.bin":
|
|
102
|
+
raise RuntimeError("failed")
|
|
103
|
+
return type("Result", (), {"path": path})()
|
|
104
|
+
|
|
105
|
+
monkeypatch.setattr(client, "_upload_file", fake_upload)
|
|
106
|
+
result = client.upload(directory)
|
|
107
|
+
|
|
108
|
+
assert isinstance(result, BatchUploadResult)
|
|
109
|
+
assert len(result.completed) == 1
|
|
110
|
+
assert len(result.failures) == 1
|
|
111
|
+
client.close()
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def test_checksum_failure_removes_partial_download(tmp_path: Path) -> None:
|
|
115
|
+
def handler(request: httpx.Request) -> httpx.Response:
|
|
116
|
+
if request.url.path == "/v1/downloads":
|
|
117
|
+
return json_response(
|
|
118
|
+
200,
|
|
119
|
+
{
|
|
120
|
+
"artifact": {
|
|
121
|
+
"artifact_id": "artifact-1",
|
|
122
|
+
"artifact_version_id": "version-1",
|
|
123
|
+
"name": "dataset.bin",
|
|
124
|
+
"version": 1,
|
|
125
|
+
"size_bytes": 3,
|
|
126
|
+
"checksum_sha256": "0" * 64,
|
|
127
|
+
"storage_mode": "hosted",
|
|
128
|
+
},
|
|
129
|
+
"download_url": "https://storage.test/object",
|
|
130
|
+
"expires_in": 900,
|
|
131
|
+
},
|
|
132
|
+
)
|
|
133
|
+
return httpx.Response(200, content=b"bad")
|
|
134
|
+
|
|
135
|
+
client = Valgo("valgo_live_test_secret", base_url="https://api.test")
|
|
136
|
+
client._http.close()
|
|
137
|
+
client._http = httpx.Client(transport=httpx.MockTransport(handler))
|
|
138
|
+
client._storage_http.close()
|
|
139
|
+
client._storage_http = httpx.Client(transport=httpx.MockTransport(handler))
|
|
140
|
+
destination = tmp_path / "dataset.bin"
|
|
141
|
+
|
|
142
|
+
with pytest.raises(IntegrityError):
|
|
143
|
+
client.download("artifact-1", destination)
|
|
144
|
+
|
|
145
|
+
assert not destination.exists()
|
|
146
|
+
assert not (tmp_path / ".dataset.bin.valgo-part").exists()
|
|
147
|
+
client.close()
|