scanii-python 1.0.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.
- scanii_python-1.0.0/.github/workflows/pr.yml +46 -0
- scanii_python-1.0.0/.github/workflows/release.yml +31 -0
- scanii_python-1.0.0/.gitignore +15 -0
- scanii_python-1.0.0/CHANGELOG.md +48 -0
- scanii_python-1.0.0/LICENSE +180 -0
- scanii_python-1.0.0/PKG-INFO +172 -0
- scanii_python-1.0.0/README.md +154 -0
- scanii_python-1.0.0/pyproject.toml +39 -0
- scanii_python-1.0.0/src/scanii/__init__.py +30 -0
- scanii_python-1.0.0/src/scanii/_multipart.py +199 -0
- scanii_python-1.0.0/src/scanii/_version.py +1 -0
- scanii_python-1.0.0/src/scanii/client.py +460 -0
- scanii_python-1.0.0/src/scanii/errors.py +47 -0
- scanii_python-1.0.0/src/scanii/models.py +177 -0
- scanii_python-1.0.0/src/scanii/py.typed +0 -0
- scanii_python-1.0.0/src/scanii/target.py +62 -0
- scanii_python-1.0.0/tests/__init__.py +0 -0
- scanii_python-1.0.0/tests/test_client_integration.py +251 -0
- scanii_python-1.0.0/tests/test_client_unit.py +573 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
name: PR
|
|
2
|
+
|
|
3
|
+
on: pull_request
|
|
4
|
+
|
|
5
|
+
concurrency:
|
|
6
|
+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
|
7
|
+
cancel-in-progress: true
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
verify:
|
|
11
|
+
name: Python ${{ matrix.python }} on ${{ matrix.os }}
|
|
12
|
+
runs-on: ${{ matrix.os }}
|
|
13
|
+
strategy:
|
|
14
|
+
fail-fast: false
|
|
15
|
+
matrix:
|
|
16
|
+
os: [ubuntu-latest, macos-latest, windows-latest]
|
|
17
|
+
python: ["3.13", "3.14"]
|
|
18
|
+
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@v4
|
|
21
|
+
|
|
22
|
+
- uses: actions/setup-python@v5
|
|
23
|
+
with:
|
|
24
|
+
python-version: ${{ matrix.python }}
|
|
25
|
+
|
|
26
|
+
- name: Setup scanii-cli
|
|
27
|
+
uses: scanii/setup-cli-action@v1
|
|
28
|
+
|
|
29
|
+
- name: Install dependencies
|
|
30
|
+
run: pip install -e ".[dev]"
|
|
31
|
+
|
|
32
|
+
- name: Run tests
|
|
33
|
+
run: pytest
|
|
34
|
+
env:
|
|
35
|
+
SCANII_TEST_ENDPOINT: http://localhost:4000
|
|
36
|
+
|
|
37
|
+
- name: Type check
|
|
38
|
+
run: mypy src
|
|
39
|
+
|
|
40
|
+
- name: Lint
|
|
41
|
+
run: ruff check
|
|
42
|
+
|
|
43
|
+
- name: Build
|
|
44
|
+
run: |
|
|
45
|
+
pip install build
|
|
46
|
+
python -m build
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
publish:
|
|
9
|
+
name: Publish to PyPI
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
environment: pypi
|
|
12
|
+
permissions:
|
|
13
|
+
id-token: write
|
|
14
|
+
contents: read
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
with:
|
|
19
|
+
ref: ${{ github.event.release.tag_name }}
|
|
20
|
+
|
|
21
|
+
- uses: actions/setup-python@v5
|
|
22
|
+
with:
|
|
23
|
+
python-version: "3.13"
|
|
24
|
+
|
|
25
|
+
- name: Build
|
|
26
|
+
run: |
|
|
27
|
+
python -m pip install --upgrade pip build
|
|
28
|
+
python -m build
|
|
29
|
+
|
|
30
|
+
- name: Publish to PyPI
|
|
31
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 1.0.0 — 2026-05-05
|
|
4
|
+
|
|
5
|
+
Initial release. Replaces the unmaintained `scanii.py` skeleton.
|
|
6
|
+
|
|
7
|
+
**Reference:** scanii-java v8.1.0 (includes v2.2 API surface).
|
|
8
|
+
|
|
9
|
+
### API surface
|
|
10
|
+
|
|
11
|
+
- `ScaniiClient(*, key, secret, target, timeout)` — synchronous client, zero runtime dependencies, stdlib only; `target` is a required `ScaniiTarget` instance
|
|
12
|
+
- `process(content, filename, content_type, metadata, callback)` — stream-first synchronous scan; `content` is any object with `read(n) -> bytes`
|
|
13
|
+
- `process_file(path, metadata, callback)` — path convenience; opens the file and delegates to `process`
|
|
14
|
+
- `process_async(content, filename, content_type, metadata, callback)` — stream-first async-on-server submission
|
|
15
|
+
- `process_async_file(path, metadata, callback)` — path convenience for async submission
|
|
16
|
+
- `retrieve_trace(id)` — **(v2.2 preview)** retrieve processing event trace; returns `None` on 404
|
|
17
|
+
- `process_from_url(location, callback, metadata)` — **(v2.2 preview)** synchronous URL submission via `POST /files`
|
|
18
|
+
- `fetch(url, metadata, callback)` — async server-side fetch-and-scan via `POST /files/fetch`
|
|
19
|
+
- `retrieve(id)` — retrieve a previous scan result
|
|
20
|
+
- `ping()` — health check
|
|
21
|
+
- `create_auth_token(timeout_seconds)` / `retrieve_auth_token(id)` / `delete_auth_token(id)` — auth token lifecycle
|
|
22
|
+
|
|
23
|
+
### Streaming design
|
|
24
|
+
|
|
25
|
+
True socket-level streaming for `process` and `process_file` — uploads of any size do not buffer the full body in memory. Matches the cross-SDK streaming standard.
|
|
26
|
+
|
|
27
|
+
The multipart encoder builds a chained reader (prologue bytes → caller's IO → epilogue bytes) without reading the file body at construction time. The file content is transferred directly to the socket as urllib reads from the chain. `process_file(path)` streams from disk through the chained reader to the socket without intermediate buffering. IOs without `fileno()` or `seek`/`tell` (pipes, generators) buffer through `SpooledTemporaryFile(max_size=1 MiB)` — small payloads stay in memory, larger ones spill to disk.
|
|
28
|
+
|
|
29
|
+
`process(content, filename)` accepts any IO-like object (`io.BytesIO`, open file handles, network streams). `process_file(path)` is a thin wrapper for the common disk-file case. There is exactly one HTTP-handling code path; the file convenience is syntactic sugar.
|
|
30
|
+
|
|
31
|
+
### Error handling
|
|
32
|
+
|
|
33
|
+
- `ScaniiError` — base exception; carries `status_code`, `request_id`, `host_id`, `body`
|
|
34
|
+
- `ScaniiAuthError(ScaniiError)` — HTTP 401/403
|
|
35
|
+
- `ScaniiRateLimitError(ScaniiError)` — HTTP 429; carries `retry_after` (seconds) when the server provides it
|
|
36
|
+
- Network-level failures (`urllib.error.URLError`) propagate unwrapped per SDK Principle 3
|
|
37
|
+
|
|
38
|
+
### Deprecations (from day one)
|
|
39
|
+
|
|
40
|
+
- `ScaniiProcessingResult.error` — ships deprecated from day one. The server never populates this field on successful responses; errors arrive as non-2xx HTTP responses that raise `ScaniiError` subclasses. Constructing the dataclass with a non-`None` `error` value emits a `DeprecationWarning`. Will be removed in a future major version.
|
|
41
|
+
|
|
42
|
+
### Regional endpoints
|
|
43
|
+
|
|
44
|
+
Explicit `ScaniiTarget` required at construction. Regional endpoints are typed constants on `ScaniiTarget` (`US1`, `EU1`, `EU2`, `AP1`, `AP2`, `CA1`). The constructor takes a `target: ScaniiTarget` parameter with no default — customers must choose explicitly. For testing against scanii-cli or other local mocks, construct `ScaniiTarget("http://localhost:4000")` directly. Latency-based routing (`AUTO` in other Scanii SDKs) is intentionally not provided in Python; chain-of-custody and data-residency compliance require an explicit regional choice.
|
|
45
|
+
|
|
46
|
+
### Notes
|
|
47
|
+
|
|
48
|
+
- Published as `scanii-python` on PyPI; import name is `scanii`
|
|
@@ -0,0 +1,180 @@
|
|
|
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 made available under
|
|
36
|
+
the License, as indicated by a copyright notice that is included in
|
|
37
|
+
or attached to the work (an example is provided in the Appendix below).
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other transformations
|
|
42
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
43
|
+
of this document, Derivative Works shall not include works that remain
|
|
44
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
45
|
+
the Work and Derivative Works thereof.
|
|
46
|
+
|
|
47
|
+
"Contribution" shall mean, as submitted to the Licensor for inclusion
|
|
48
|
+
in the Work by the copyright owner or by an individual or Legal Entity
|
|
49
|
+
authorized to submit on behalf of the copyright owner. For the purposes
|
|
50
|
+
of this definition, "submitted" means any form of electronic, verbal,
|
|
51
|
+
or written communication sent to the Licensor or its representatives,
|
|
52
|
+
including but not limited to communication on electronic mailing lists,
|
|
53
|
+
source code control systems, and issue tracking systems that are managed
|
|
54
|
+
by, or on behalf of, the Licensor for the purpose of discussing and
|
|
55
|
+
improving the Work, but excluding communication that is conspicuously
|
|
56
|
+
marked or designated in writing by the copyright owner as "Not a
|
|
57
|
+
Contribution."
|
|
58
|
+
|
|
59
|
+
"Contributor" shall mean Licensor and any Legal Entity on behalf of
|
|
60
|
+
whom a Contribution has been received by the Licensor and included
|
|
61
|
+
within the Work.
|
|
62
|
+
|
|
63
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
64
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
65
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
66
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
67
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
68
|
+
Work and such Derivative Works in Source or Object form.
|
|
69
|
+
|
|
70
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
71
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
72
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
73
|
+
(except as stated in this section) patent license to make, have made,
|
|
74
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
75
|
+
where such license applies only to those Contributions necessary to
|
|
76
|
+
make, have made, use, offer to sell, sell, import, and otherwise
|
|
77
|
+
transfer the Work, where such license applies only to those
|
|
78
|
+
Contributions necessary to make, have made, use, offer to sell, sell,
|
|
79
|
+
import, and otherwise transfer the Work, where such license applies only
|
|
80
|
+
to those Contributions necessary to make, have made, use, offer to sell,
|
|
81
|
+
sell, import, and otherwise transfer the Work.
|
|
82
|
+
|
|
83
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
84
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
85
|
+
modifications, and in Source or Object form, provided that You
|
|
86
|
+
meet the following conditions:
|
|
87
|
+
|
|
88
|
+
(a) You must give any other recipients of the Work or
|
|
89
|
+
Derivative Works a copy of this License; and
|
|
90
|
+
|
|
91
|
+
(b) You must cause any modified files to carry prominent notices
|
|
92
|
+
stating that You changed the files; and
|
|
93
|
+
|
|
94
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
95
|
+
that You distribute, all copyright, patent, trademark, and
|
|
96
|
+
attribution notices from the Source form of the Work,
|
|
97
|
+
excluding those notices that do not pertain to any part of
|
|
98
|
+
the Derivative Works; and
|
|
99
|
+
|
|
100
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
101
|
+
distribution, You must include a readable copy of the
|
|
102
|
+
attribution notices contained within such NOTICE file, in
|
|
103
|
+
at least one of the following places: within a NOTICE text
|
|
104
|
+
file distributed as part of the Derivative Works; within
|
|
105
|
+
the Source form or documentation, if provided along with the
|
|
106
|
+
Derivative Works; or, within a display generated by the
|
|
107
|
+
Derivative Works, if and where such third-party notices normally
|
|
108
|
+
appear. The contents of the NOTICE file are for informational
|
|
109
|
+
purposes only and do not modify the License. You may add Your
|
|
110
|
+
own attribution notices within Derivative Works that You
|
|
111
|
+
distribute, alongside or in addition to the NOTICE text from
|
|
112
|
+
the Work, provided that such additional attribution notices
|
|
113
|
+
cannot be construed as modifying the License.
|
|
114
|
+
|
|
115
|
+
You may add Your own license statement for Your modifications and
|
|
116
|
+
may provide additional grant of rights to use, copy, modify, merge,
|
|
117
|
+
publish, distribute, sublicense, and/or sell copies of the Work,
|
|
118
|
+
and you may offer support, acceptance, or other conditions.
|
|
119
|
+
|
|
120
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
121
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
122
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
123
|
+
this License, without any additional terms or conditions.
|
|
124
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
125
|
+
the terms of any separate license agreement you may have executed
|
|
126
|
+
with Licensor regarding such Contributions.
|
|
127
|
+
|
|
128
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
129
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
130
|
+
except as required for reasonable and customary use in describing the
|
|
131
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
132
|
+
|
|
133
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
134
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
135
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
136
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
137
|
+
implied, including, without limitation, any warranties or conditions
|
|
138
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
139
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
140
|
+
appropriateness of using or reproducing the Work and assume any
|
|
141
|
+
risks associated with Your exercise of permissions under this License.
|
|
142
|
+
|
|
143
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
144
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
145
|
+
unless required by applicable law (such as deliberate and grossly
|
|
146
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
147
|
+
liable to You for damages, including any direct, indirect, special,
|
|
148
|
+
incidental, or exemplary damages of any character arising as a
|
|
149
|
+
result of this License or out of the use or inability to use the
|
|
150
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
151
|
+
work stoppage, computer failure or malfunction, or all other
|
|
152
|
+
commercial damages or losses), even if such Contributor has been
|
|
153
|
+
advised of the possibility of such damages.
|
|
154
|
+
|
|
155
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
156
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
157
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
158
|
+
or other liability obligations and/or rights consistent with this
|
|
159
|
+
License. However, in accepting such obligations, You may offer only
|
|
160
|
+
on Your behalf, on the sole responsibility of each Contributor, and
|
|
161
|
+
only if You agree to indemnify, defend, and hold each Contributor
|
|
162
|
+
harmless for any liability incurred by, or claims asserted against,
|
|
163
|
+
such Contributor by reason of your accepting any warranty or
|
|
164
|
+
additional liability.
|
|
165
|
+
|
|
166
|
+
END OF TERMS AND CONDITIONS
|
|
167
|
+
|
|
168
|
+
Copyright 2024 Scanii
|
|
169
|
+
|
|
170
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
171
|
+
you may not use this file except in compliance with the License.
|
|
172
|
+
You may obtain a copy of the License at
|
|
173
|
+
|
|
174
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
175
|
+
|
|
176
|
+
Unless required by applicable law or agreed to in writing, software
|
|
177
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
178
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
179
|
+
See the License for the specific language governing permissions and
|
|
180
|
+
limitations under the License.
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: scanii-python
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Zero-dependency Python SDK for the Scanii content security API
|
|
5
|
+
Project-URL: Homepage, https://scanii.com
|
|
6
|
+
Project-URL: Repository, https://github.com/scanii/scanii-python
|
|
7
|
+
Project-URL: Documentation, https://scanii.github.io/openapi/v22/
|
|
8
|
+
Author: Scanii
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Python: >=3.13
|
|
12
|
+
Provides-Extra: dev
|
|
13
|
+
Requires-Dist: mypy; extra == 'dev'
|
|
14
|
+
Requires-Dist: pytest-cov; extra == 'dev'
|
|
15
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
16
|
+
Requires-Dist: ruff; extra == 'dev'
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# scanii-python
|
|
20
|
+
|
|
21
|
+
Python SDK for the [Scanii](https://scanii.com) content security API.
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install scanii-python
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Distribution name is `scanii-python`; import as `from scanii import ScaniiClient`.
|
|
30
|
+
|
|
31
|
+
## SDK Principles
|
|
32
|
+
|
|
33
|
+
1. **Light.** Zero runtime dependencies, stdlib only.
|
|
34
|
+
2. **Up to date.** Always current with the latest Scanii API.
|
|
35
|
+
3. **Integration-only.** Wraps the REST API — retries, concurrency, and batching are the caller's responsibility.
|
|
36
|
+
|
|
37
|
+
## Quickstart
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
from scanii import ScaniiClient, ScaniiTarget
|
|
41
|
+
|
|
42
|
+
client = ScaniiClient(key="your-key", secret="your-secret", target=ScaniiTarget.US1)
|
|
43
|
+
result = client.process_file("./document.pdf")
|
|
44
|
+
print(result.findings) # [] when clean
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Streaming
|
|
48
|
+
|
|
49
|
+
Pass any IO-like object (anything with `read(n) -> bytes`) to `process()` directly — no temp file needed:
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
import io
|
|
53
|
+
|
|
54
|
+
# Scan bytes already in memory
|
|
55
|
+
result = client.process(io.BytesIO(my_bytes), filename="upload.bin")
|
|
56
|
+
|
|
57
|
+
# Scan content from an open file handle
|
|
58
|
+
with open("./large.pdf", "rb") as f:
|
|
59
|
+
result = client.process(f, filename="large.pdf")
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## API Reference
|
|
63
|
+
|
|
64
|
+
### Constructor
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
ScaniiClient(
|
|
68
|
+
*,
|
|
69
|
+
key: str | None = None,
|
|
70
|
+
secret: str | None = None,
|
|
71
|
+
token: str | None = None,
|
|
72
|
+
target: ScaniiTarget,
|
|
73
|
+
timeout: float = 60.0,
|
|
74
|
+
)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Supply either `key` + `secret` (HTTP Basic Auth) or `token` (auth-token authentication). Mixing both raises `ValueError`. `target` is required — see [Regional Endpoints](#regional-endpoints).
|
|
78
|
+
|
|
79
|
+
### File scanning
|
|
80
|
+
|
|
81
|
+
| Method | Description |
|
|
82
|
+
|---|---|
|
|
83
|
+
| `process(content, filename, content_type=None, metadata=None, callback=None)` | Synchronous scan of an IO-like object |
|
|
84
|
+
| `process_file(path, metadata=None, callback=None)` | Synchronous scan of a file on disk |
|
|
85
|
+
| `process_async(content, filename, content_type=None, metadata=None, callback=None)` | Async-on-server scan of an IO-like object; returns `ScaniiPendingResult` |
|
|
86
|
+
| `process_async_file(path, metadata=None, callback=None)` | Async-on-server scan of a file on disk; returns `ScaniiPendingResult` |
|
|
87
|
+
| `retrieve(id)` | Retrieve a previous scan result |
|
|
88
|
+
| `fetch(url, metadata=None, callback=None)` | Server-side async fetch-and-scan of a remote URL |
|
|
89
|
+
|
|
90
|
+
### v2.2 preview methods
|
|
91
|
+
|
|
92
|
+
| Method | Description |
|
|
93
|
+
|---|---|
|
|
94
|
+
| `retrieve_trace(id)` **(v2.2 preview)** | Retrieve processing event trace; returns `None` on 404 |
|
|
95
|
+
| `process_from_url(location, callback=None, metadata=None)` **(v2.2 preview)** | Synchronous scan of a remote URL via `POST /files` |
|
|
96
|
+
|
|
97
|
+
### Auth tokens
|
|
98
|
+
|
|
99
|
+
| Method | Description |
|
|
100
|
+
|---|---|
|
|
101
|
+
| `create_auth_token(timeout_seconds)` | Mint a short-lived token |
|
|
102
|
+
| `retrieve_auth_token(id)` | Inspect a token |
|
|
103
|
+
| `delete_auth_token(id)` | Revoke a token |
|
|
104
|
+
|
|
105
|
+
### Health check
|
|
106
|
+
|
|
107
|
+
| Method | Description |
|
|
108
|
+
|---|---|
|
|
109
|
+
| `ping()` | Returns `True` when the API is reachable with valid credentials |
|
|
110
|
+
|
|
111
|
+
## Regional Endpoints
|
|
112
|
+
|
|
113
|
+
Choose a regional target explicitly. Six regional constants are available: `US1`, `EU1`, `EU2`, `AP1`, `AP2`, `CA1`. Latency-based routing (`AUTO` in other Scanii SDKs) is intentionally not provided — chain-of-custody and data-residency compliance require an explicit regional choice. For local testing against scanii-cli, construct a target with an arbitrary URL: `ScaniiTarget("http://localhost:4000")`.
|
|
114
|
+
|
|
115
|
+
| Constant | URL | Location |
|
|
116
|
+
|---|---|---|
|
|
117
|
+
| `ScaniiTarget.US1` | `https://api-us1.scanii.com` | Virginia, USA |
|
|
118
|
+
| `ScaniiTarget.EU1` | `https://api-eu1.scanii.com` | Dublin, Ireland |
|
|
119
|
+
| `ScaniiTarget.EU2` | `https://api-eu2.scanii.com` | London, United Kingdom |
|
|
120
|
+
| `ScaniiTarget.AP1` | `https://api-ap1.scanii.com` | Sydney, Australia |
|
|
121
|
+
| `ScaniiTarget.AP2` | `https://api-ap2.scanii.com` | Singapore |
|
|
122
|
+
| `ScaniiTarget.CA1` | `https://api-ca1.scanii.com` | Montreal, Canada |
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
client = ScaniiClient(key="your-key", secret="your-secret", target=ScaniiTarget.EU1)
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Error Handling
|
|
129
|
+
|
|
130
|
+
```python
|
|
131
|
+
from scanii import ScaniiClient, ScaniiTarget, ScaniiError, ScaniiAuthError, ScaniiRateLimitError
|
|
132
|
+
import time
|
|
133
|
+
|
|
134
|
+
client = ScaniiClient(key="your-key", secret="your-secret", target=ScaniiTarget.US1)
|
|
135
|
+
|
|
136
|
+
try:
|
|
137
|
+
result = client.process_file("./document.pdf")
|
|
138
|
+
except ScaniiAuthError:
|
|
139
|
+
print("Invalid credentials")
|
|
140
|
+
except ScaniiRateLimitError as e:
|
|
141
|
+
if e.retry_after:
|
|
142
|
+
time.sleep(e.retry_after)
|
|
143
|
+
except ScaniiError as e:
|
|
144
|
+
print(f"API error {e.status_code}: {e}")
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Network-level failures (`urllib.error.URLError`) propagate unwrapped — retries are the caller's responsibility per SDK Principle 3.
|
|
148
|
+
|
|
149
|
+
## Local Testing with scanii-cli
|
|
150
|
+
|
|
151
|
+
All integration tests run against a locally-hosted scanii-cli mock server — no real credentials needed.
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
docker run -d --name scanii-cli -p 4000:4000 ghcr.io/scanii/scanii-cli:latest server
|
|
155
|
+
|
|
156
|
+
# Run tests
|
|
157
|
+
pip install -e ".[dev]"
|
|
158
|
+
pytest
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
client = ScaniiClient(key="key", secret="secret", target=ScaniiTarget("http://localhost:4000"))
|
|
163
|
+
result = client.ping() # True
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## Contributing
|
|
167
|
+
|
|
168
|
+
Pull requests welcome. Please open an issue first for substantial changes.
|
|
169
|
+
|
|
170
|
+
## License
|
|
171
|
+
|
|
172
|
+
Apache 2.0 — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# scanii-python
|
|
2
|
+
|
|
3
|
+
Python SDK for the [Scanii](https://scanii.com) content security API.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install scanii-python
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Distribution name is `scanii-python`; import as `from scanii import ScaniiClient`.
|
|
12
|
+
|
|
13
|
+
## SDK Principles
|
|
14
|
+
|
|
15
|
+
1. **Light.** Zero runtime dependencies, stdlib only.
|
|
16
|
+
2. **Up to date.** Always current with the latest Scanii API.
|
|
17
|
+
3. **Integration-only.** Wraps the REST API — retries, concurrency, and batching are the caller's responsibility.
|
|
18
|
+
|
|
19
|
+
## Quickstart
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
from scanii import ScaniiClient, ScaniiTarget
|
|
23
|
+
|
|
24
|
+
client = ScaniiClient(key="your-key", secret="your-secret", target=ScaniiTarget.US1)
|
|
25
|
+
result = client.process_file("./document.pdf")
|
|
26
|
+
print(result.findings) # [] when clean
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Streaming
|
|
30
|
+
|
|
31
|
+
Pass any IO-like object (anything with `read(n) -> bytes`) to `process()` directly — no temp file needed:
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
import io
|
|
35
|
+
|
|
36
|
+
# Scan bytes already in memory
|
|
37
|
+
result = client.process(io.BytesIO(my_bytes), filename="upload.bin")
|
|
38
|
+
|
|
39
|
+
# Scan content from an open file handle
|
|
40
|
+
with open("./large.pdf", "rb") as f:
|
|
41
|
+
result = client.process(f, filename="large.pdf")
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## API Reference
|
|
45
|
+
|
|
46
|
+
### Constructor
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
ScaniiClient(
|
|
50
|
+
*,
|
|
51
|
+
key: str | None = None,
|
|
52
|
+
secret: str | None = None,
|
|
53
|
+
token: str | None = None,
|
|
54
|
+
target: ScaniiTarget,
|
|
55
|
+
timeout: float = 60.0,
|
|
56
|
+
)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Supply either `key` + `secret` (HTTP Basic Auth) or `token` (auth-token authentication). Mixing both raises `ValueError`. `target` is required — see [Regional Endpoints](#regional-endpoints).
|
|
60
|
+
|
|
61
|
+
### File scanning
|
|
62
|
+
|
|
63
|
+
| Method | Description |
|
|
64
|
+
|---|---|
|
|
65
|
+
| `process(content, filename, content_type=None, metadata=None, callback=None)` | Synchronous scan of an IO-like object |
|
|
66
|
+
| `process_file(path, metadata=None, callback=None)` | Synchronous scan of a file on disk |
|
|
67
|
+
| `process_async(content, filename, content_type=None, metadata=None, callback=None)` | Async-on-server scan of an IO-like object; returns `ScaniiPendingResult` |
|
|
68
|
+
| `process_async_file(path, metadata=None, callback=None)` | Async-on-server scan of a file on disk; returns `ScaniiPendingResult` |
|
|
69
|
+
| `retrieve(id)` | Retrieve a previous scan result |
|
|
70
|
+
| `fetch(url, metadata=None, callback=None)` | Server-side async fetch-and-scan of a remote URL |
|
|
71
|
+
|
|
72
|
+
### v2.2 preview methods
|
|
73
|
+
|
|
74
|
+
| Method | Description |
|
|
75
|
+
|---|---|
|
|
76
|
+
| `retrieve_trace(id)` **(v2.2 preview)** | Retrieve processing event trace; returns `None` on 404 |
|
|
77
|
+
| `process_from_url(location, callback=None, metadata=None)` **(v2.2 preview)** | Synchronous scan of a remote URL via `POST /files` |
|
|
78
|
+
|
|
79
|
+
### Auth tokens
|
|
80
|
+
|
|
81
|
+
| Method | Description |
|
|
82
|
+
|---|---|
|
|
83
|
+
| `create_auth_token(timeout_seconds)` | Mint a short-lived token |
|
|
84
|
+
| `retrieve_auth_token(id)` | Inspect a token |
|
|
85
|
+
| `delete_auth_token(id)` | Revoke a token |
|
|
86
|
+
|
|
87
|
+
### Health check
|
|
88
|
+
|
|
89
|
+
| Method | Description |
|
|
90
|
+
|---|---|
|
|
91
|
+
| `ping()` | Returns `True` when the API is reachable with valid credentials |
|
|
92
|
+
|
|
93
|
+
## Regional Endpoints
|
|
94
|
+
|
|
95
|
+
Choose a regional target explicitly. Six regional constants are available: `US1`, `EU1`, `EU2`, `AP1`, `AP2`, `CA1`. Latency-based routing (`AUTO` in other Scanii SDKs) is intentionally not provided — chain-of-custody and data-residency compliance require an explicit regional choice. For local testing against scanii-cli, construct a target with an arbitrary URL: `ScaniiTarget("http://localhost:4000")`.
|
|
96
|
+
|
|
97
|
+
| Constant | URL | Location |
|
|
98
|
+
|---|---|---|
|
|
99
|
+
| `ScaniiTarget.US1` | `https://api-us1.scanii.com` | Virginia, USA |
|
|
100
|
+
| `ScaniiTarget.EU1` | `https://api-eu1.scanii.com` | Dublin, Ireland |
|
|
101
|
+
| `ScaniiTarget.EU2` | `https://api-eu2.scanii.com` | London, United Kingdom |
|
|
102
|
+
| `ScaniiTarget.AP1` | `https://api-ap1.scanii.com` | Sydney, Australia |
|
|
103
|
+
| `ScaniiTarget.AP2` | `https://api-ap2.scanii.com` | Singapore |
|
|
104
|
+
| `ScaniiTarget.CA1` | `https://api-ca1.scanii.com` | Montreal, Canada |
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
client = ScaniiClient(key="your-key", secret="your-secret", target=ScaniiTarget.EU1)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Error Handling
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
from scanii import ScaniiClient, ScaniiTarget, ScaniiError, ScaniiAuthError, ScaniiRateLimitError
|
|
114
|
+
import time
|
|
115
|
+
|
|
116
|
+
client = ScaniiClient(key="your-key", secret="your-secret", target=ScaniiTarget.US1)
|
|
117
|
+
|
|
118
|
+
try:
|
|
119
|
+
result = client.process_file("./document.pdf")
|
|
120
|
+
except ScaniiAuthError:
|
|
121
|
+
print("Invalid credentials")
|
|
122
|
+
except ScaniiRateLimitError as e:
|
|
123
|
+
if e.retry_after:
|
|
124
|
+
time.sleep(e.retry_after)
|
|
125
|
+
except ScaniiError as e:
|
|
126
|
+
print(f"API error {e.status_code}: {e}")
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Network-level failures (`urllib.error.URLError`) propagate unwrapped — retries are the caller's responsibility per SDK Principle 3.
|
|
130
|
+
|
|
131
|
+
## Local Testing with scanii-cli
|
|
132
|
+
|
|
133
|
+
All integration tests run against a locally-hosted scanii-cli mock server — no real credentials needed.
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
docker run -d --name scanii-cli -p 4000:4000 ghcr.io/scanii/scanii-cli:latest server
|
|
137
|
+
|
|
138
|
+
# Run tests
|
|
139
|
+
pip install -e ".[dev]"
|
|
140
|
+
pytest
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
```python
|
|
144
|
+
client = ScaniiClient(key="key", secret="secret", target=ScaniiTarget("http://localhost:4000"))
|
|
145
|
+
result = client.ping() # True
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Contributing
|
|
149
|
+
|
|
150
|
+
Pull requests welcome. Please open an issue first for substantial changes.
|
|
151
|
+
|
|
152
|
+
## License
|
|
153
|
+
|
|
154
|
+
Apache 2.0 — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "scanii-python"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "Zero-dependency Python SDK for the Scanii content security API"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "Apache-2.0"
|
|
11
|
+
requires-python = ">=3.13"
|
|
12
|
+
authors = [{ name = "Scanii" }]
|
|
13
|
+
dependencies = []
|
|
14
|
+
|
|
15
|
+
[project.optional-dependencies]
|
|
16
|
+
dev = ["pytest>=8", "pytest-cov", "mypy", "ruff"]
|
|
17
|
+
|
|
18
|
+
[project.urls]
|
|
19
|
+
Homepage = "https://scanii.com"
|
|
20
|
+
Repository = "https://github.com/scanii/scanii-python"
|
|
21
|
+
Documentation = "https://scanii.github.io/openapi/v22/"
|
|
22
|
+
|
|
23
|
+
[tool.hatch.build.targets.wheel]
|
|
24
|
+
packages = ["src/scanii"]
|
|
25
|
+
|
|
26
|
+
[tool.pytest.ini_options]
|
|
27
|
+
testpaths = ["tests"]
|
|
28
|
+
|
|
29
|
+
[tool.mypy]
|
|
30
|
+
python_version = "3.13"
|
|
31
|
+
strict = true
|
|
32
|
+
files = ["src"]
|
|
33
|
+
|
|
34
|
+
[tool.ruff]
|
|
35
|
+
line-length = 100
|
|
36
|
+
target-version = "py313"
|
|
37
|
+
|
|
38
|
+
[tool.ruff.lint]
|
|
39
|
+
select = ["E", "F", "W", "I"]
|