API Reference¶
This page documents the public API of onedep_lib — the names exported from onedep_lib.__all__, plus DepositConfig.
Factories and facade¶
onedep_lib.dsp.deposit_init(email, users, country, config, experiment_type=None, em_subtype=None, coordinates=None, _base_dir=None, _api_client=None, _check_runner=None)
¶
Create a new local deposition session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
email
|
str
|
Depositor e-mail address. |
required |
users
|
list[str]
|
List of ORCID IDs granted access to this deposition. |
required |
country
|
Country
|
Depositor country (use the Country enum). |
required |
config
|
DepositConfig
|
Pre-built DepositConfig for the target deposition site. |
required |
experiment_type
|
ExperimentType | None
|
Experiment type (can be set later via set_experiment_type). |
None
|
em_subtype
|
EMSubType | None
|
EM experiment subtype (can be set later via set_em_params). |
None
|
coordinates
|
bool | None
|
Whether coordinates are being deposited (can be set later). |
None
|
_base_dir
|
Path | None
|
Override session storage directory (for testing only). |
None
|
_api_client
|
ApiClient | None
|
Override API client (for testing only). |
None
|
_check_runner
|
CheckRunner | None
|
Override check runner (for testing only). |
None
|
Returns:
| Type | Description |
|---|---|
Deposition
|
A Deposition object representing the local session. |
Source code in src/onedep_lib/dsp.py
onedep_lib.dsp.deposit_resume(session_id, config, _base_dir=None, _api_client=None, _check_runner=None)
¶
Resume an existing local deposition session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
The session_id returned by a previous deposit_init() call. |
required |
config
|
DepositConfig
|
Pre-built DepositConfig for the target deposition site. |
required |
_base_dir
|
Path | None
|
Override session storage directory (for testing only). |
None
|
_api_client
|
ApiClient | None
|
Override API client (for testing only). |
None
|
_check_runner
|
CheckRunner | None
|
Override check runner (for testing only). |
None
|
Returns:
| Type | Description |
|---|---|
Deposition
|
A Deposition object for the existing session. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If no session with the given session_id exists. |
Source code in src/onedep_lib/dsp.py
onedep_lib.dsp.list_sessions(base_dir=None)
¶
Return all local sessions with their registered files, newest first.
Source code in src/onedep_lib/dsp.py
onedep_lib.dsp.check_auth_key(config)
¶
Return True if the configured credentials are valid, False otherwise.
Source code in src/onedep_lib/dsp.py
onedep_lib.dsp.Deposition
¶
Local deposition session. Created via deposit_init() or deposit_resume().
Source code in src/onedep_lib/dsp.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 | |
remote_dep_id
property
¶
Remote deposition ID, populated after deposit() is called.
session_id
property
¶
Unique ID of the local session.
site_base_url
property
¶
Remote deposition site root, populated after deposit() is called.
site_url
property
¶
Remote deposition site URL, populated after deposit() is called.
add_file(file_path, file_type)
¶
Register a local file for this deposition.
Returns:
| Type | Description |
|---|---|
str
|
A file_id (UUID string) to reference this file in check methods. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If file_path does not exist. |
Source code in src/onedep_lib/dsp.py
check_file_type(file_id, file_type)
¶
Check that the file matches the expected FileType.
check_mmcif_category(file_id, category)
¶
Check that the mmCIF file contains the given category.
check_mmcif_field(file_id, category, field)
¶
Check that the mmCIF file contains the given field in the given category.
Source code in src/onedep_lib/dsp.py
check_mmcif_file(file_id)
¶
Check that the file identified by file_id is a valid mmCIF.
check_required_files()
¶
Check that the session contains all required files for the experiment type.
Source code in src/onedep_lib/dsp.py
close()
¶
deposit()
¶
Submit this deposition to the OneDep API.
Creates a remote deposition, uploads all registered files, and triggers processing. Returns immediately without waiting for processing to finish.
Returns:
| Type | Description |
|---|---|
str
|
The remote deposition ID (e.g. "D_8000000001"). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If experiment_type has not been set. |
ApiError
|
If any API call fails. |
Source code in src/onedep_lib/dsp.py
get_experiment_file_types()
¶
Return the accepted file types for the current experiment type.
Source code in src/onedep_lib/dsp.py
get_status()
¶
Return the current processing status of the remote deposition.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If deposit() has not been called yet. |
Source code in src/onedep_lib/dsp.py
has_file(file_path)
¶
remove_file(file_id)
¶
set_em_params(em_subtype=None, coordinates=None)
¶
Set EM-specific parameters for this deposition.
Source code in src/onedep_lib/dsp.py
set_experiment_type(experiment_type)
¶
Set or update the experiment type for this deposition.
set_voxel_values(file_id, spacing_x, spacing_y, spacing_z, contour)
¶
Set voxel spacing and contour level for a map file.
Source code in src/onedep_lib/dsp.py
Configuration¶
onedep_lib.config.DepositConfig
dataclass
¶
Resolved configuration for talking to a OneDep deposition site.
Built by :meth:load, which resolves fields from three sources in order
of increasing priority: the on-disk config file (config_path),
environment variables, and keyword argument overrides. See load for
the full resolution order, including how access_token and
refresh_token are populated from the [auths.<fqdn>] section.
Attributes:
| Name | Type | Description |
|---|---|---|
access_token |
str | None
|
Current OAuth access token, or None if not authenticated. |
refresh_token |
str | None
|
Current OAuth refresh token, or None if not authenticated. |
hostname |
str
|
Base URL of the OneDep deposition site to talk to. |
ssl_verify |
bool
|
Whether to verify TLS certificates on API requests. |
redirect |
bool
|
Whether to follow site-redirect responses from the API. |
allowed_redirect_domain |
str
|
Domain suffix that redirect targets must belong to. |
fetch_local_schema |
bool
|
Whether to use the bundled local JSON schemas instead of fetching them from schema_base_url. |
local_schema_cache_dir |
Path
|
Directory containing the bundled local JSON schemas. |
schema_base_url |
str
|
Base URL to fetch remote JSON schemas from. |
schema_cache_dir |
Path
|
Local directory used to cache remote JSON schemas. |
session_dir |
Path
|
Local directory used to store deposition session state. |
config_path |
Path
|
Path to the TOML config file read and written by this class. |
Source code in src/onedep_lib/config.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
load(**overrides)
classmethod
¶
Resolve a DepositConfig from the config file, environment, and overrides.
Resolution order (lowest to highest priority):
- The TOML config file at
config_path(default~/.config/onedep/config.toml), read from its[default]section. - Environment variables (
ONEDEP_ACCESS_TOKEN,ONEDEP_REFRESH_TOKEN,ONEDEP_HOSTNAME,ONEDEP_SSL_VERIFY,ONEDEP_REDIRECT,ONEDEP_SCHEMA_URL). - Keyword arguments passed to this method.
After resolving hostname, also reads the matching [auths.<fqdn>]
section from the config file and populates access_token and
refresh_token from it -- unless either token was explicitly set
via an environment variable (ONEDEP_ACCESS_TOKEN or
ONEDEP_REFRESH_TOKEN) or passed as a keyword argument, in which
case file-based token loading is skipped entirely.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**overrides
|
object
|
Field values that take priority over the config file and environment variables. Pass config_path to read from a non-default config file location. |
{}
|
Returns:
| Type | Description |
|---|---|
DepositConfig
|
A fully resolved DepositConfig. |
Raises:
| Type | Description |
|---|---|
ConfigError
|
If the config file contains invalid TOML, an invalid
boolean environment variable value, or malformed token data
in an [auths. |
Source code in src/onedep_lib/config.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
Check result types¶
onedep_lib.checks.report.CheckReport
dataclass
¶
Result of running one or more checks against a file or session.
Attributes:
| Name | Type | Description |
|---|---|---|
source |
str
|
Identifier of what was checked (a file_id, or "session" for session-level checks like check_required_files). |
issues |
list[CheckIssue]
|
All issues found, of any severity. |
Source code in src/onedep_lib/checks/report.py
onedep_lib.checks.report.CheckIssue
dataclass
¶
A single finding produced by a check.
For example, a missing required file or an invalid mmCIF field.
Source code in src/onedep_lib/checks/report.py
onedep_lib.checks.report.CheckSeverity
¶
Bases: str, Enum
Severity level of a single CheckIssue, from least to most severe.
Source code in src/onedep_lib/checks/report.py
onedep_lib.checks.report.CifLocation
dataclass
¶
Location of a check issue within an mmCIF file, when known.
All fields are optional; any subset may be populated depending on what the originating check was able to determine.
Source code in src/onedep_lib/checks/report.py
Domain enums¶
onedep_lib.enums.Country
¶
Bases: Enum
Source code in src/onedep_lib/enums.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | |
onedep_lib.enums.EMSubType
¶
onedep_lib.enums.ExperimentType
¶
onedep_lib.enums.FileType
¶
Bases: Enum
Source code in src/onedep_lib/enums.py
API response models¶
onedep_lib.apis.deposit.models.DepositStatus
dataclass
¶
Source code in src/onedep_lib/apis/deposit/models.py
onedep_lib.apis.deposit.models.DepositError
dataclass
¶
onedep_lib.apis.deposit.enums.Status
¶
Bases: Enum
Source code in src/onedep_lib/apis/deposit/enums.py
Exceptions¶
onedep_lib.exceptions.OneDepError
¶
onedep_lib.exceptions.ApiError
¶
Bases: OneDepError
HTTP error from the OneDep API.
status_code is the status the API responded with. It is None when no
response was received at all -- see ApiUnreachableError.
Source code in src/onedep_lib/exceptions.py
onedep_lib.exceptions.ApiUnreachableError
¶
Bases: ApiError
The OneDep API could not be reached.
Raised for transport-level failures -- DNS failure, connection refused, TLS
error, timeout -- where no HTTP response was received, so there is no status
code to report and status_code is None.
Subclasses ApiError so that existing except ApiError handlers keep
catching these. Catch it specifically to tell "the server was never reached"
apart from a response the server actually sent, such as a genuine 401/403.
Callers that need to decide whether the user's credentials are bad must make
that distinction: an offline client is not an unauthorized one.
Source code in src/onedep_lib/exceptions.py
onedep_lib.exceptions.DepositApiException = ApiError
module-attribute
¶
Authentication¶
onedep_lib.auths.token.TokenStore
¶
Manages the OneDep access/refresh token lifecycle for a DepositConfig.
Tokens are persisted in the [auths.<fqdn>] section of the config
file, keyed by the FQDN derived from the active hostname. Access tokens
are short-lived JWTs (30-minute TTL); refresh tokens are long-lived
opaque strings (30-day TTL) that rotate on every use.
Source code in src/onedep_lib/auths/token.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
activate_site(site_base_url)
¶
Switch the active hostname to a redirected deposition site.
If credentials already exist for site_base_url, refreshes them against that site. Otherwise exchanges the current refresh token for a token pair scoped to that site via its /auth/tokens/exchange endpoint. Updates config.hostname to site_base_url on success.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
site_base_url
|
str
|
The deposition site root URL to activate. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A valid access token for site_base_url. |
Raises:
| Type | Description |
|---|---|
ConfigError
|
If site_base_url cannot be converted to a valid FQDN key. |
AuthError
|
If the exchange/refresh request is rejected. |
ApiUnreachableError
|
If the request cannot reach the server. |
ApiError
|
If the server returns an unexpected error response. |
Source code in src/onedep_lib/auths/token.py
clear_tokens()
¶
Clear stored tokens locally without contacting the server.
Removes the in-memory access/refresh tokens and deletes the
[auths.
Source code in src/onedep_lib/auths/token.py
get_access_token()
¶
Return a valid access token, refreshing it first if necessary.
Returns:
| Type | Description |
|---|---|
str
|
A non-expired access token for the config's current hostname. |
Raises:
| Type | Description |
|---|---|
AuthError
|
If no refresh token is stored, or refresh fails because the refresh token is expired, revoked, or invalid. |
ApiUnreachableError
|
If a refresh is needed and the request cannot reach the server. |
ApiError
|
If a refresh is needed and the server returns an unexpected error response. |
Source code in src/onedep_lib/auths/token.py
refresh()
¶
Exchange the stored refresh token for a new token pair.
The rotated refresh token replaces the old one; refresh token rotation is mandatory on every call.
Returns:
| Type | Description |
|---|---|
str
|
The new access token. |
Raises:
| Type | Description |
|---|---|
AuthError
|
If no refresh token is stored, or the server rejects the refresh token as expired, revoked, or invalid. |
ApiUnreachableError
|
If the refresh request cannot reach the server. |
ApiError
|
If the server returns an unexpected error response. |
Source code in src/onedep_lib/auths/token.py
revoke()
¶
Revoke the current refresh token on the server and clear it locally.
Posts the current refresh token to the server's revoke endpoint.
On success (204 No Content), removes the [auths.
Raises:
| Type | Description |
|---|---|
AuthError
|
If the server rejects the revoke request (401/403). |
ApiUnreachableError
|
If the request cannot reach the server. |
ApiError
|
If the server returns an unexpected error response. |
Source code in src/onedep_lib/auths/token.py
store_tokens(access_token, refresh_token)
¶
Persist a token pair for the config's current hostname.
Writes both tokens to the [auths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
access_token
|
str
|
The access token to store. |
required |
refresh_token
|
str
|
The refresh token to store. |
required |
Source code in src/onedep_lib/auths/token.py
onedep_lib.auths.types.AuthProvider
¶
Bases: Protocol
Source code in src/onedep_lib/auths/types.py
Protocols¶
onedep_lib.apis.deposit.types.ApiClient
¶
Bases: Protocol