API Reference: CrossClient
Source code in src/crosscontract/crossclient/crossclient.py
11 12 13 14 15 16 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 | |
__init__(username, password, base_url=DEFAULT_URL, verify=True)
Initialize the client with authentication.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
username
|
str
|
The username for authentication. |
required |
password
|
str
|
The password for authentication. |
required |
base_url
|
str
|
If provided, use this domain instead of the default DEFAULT_URL. The domain must include the protocol (e.g., http:// or https://). Example: "http://example.com". Defaults to DEFAULT_URL: "https://backend.sweet-cross.ch". Trailing slashes are stripped internally. |
DEFAULT_URL
|
verify
|
bool
|
Whether to verify SSL certificates. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
CrossClient |
None
|
An instance of the authenticated client. |
Source code in src/crosscontract/crossclient/crossclient.py
authenticate()
Authenticate with the server and retrieve an access token.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The authentication token. |
Source code in src/crosscontract/crossclient/crossclient.py
close()
delete(endpoint, **kwargs)
Send a DELETE request to the specified endpoint.
get(endpoint, **kwargs)
patch(endpoint, json=None, **kwargs)
Send a PATCH request to the specified endpoint.
post(endpoint, json=None, **kwargs)
Send a POST request to the specified endpoint.
request(method, endpoint, **kwargs)
Send an HTTP request to the specified endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
The HTTP method (e.g., 'GET', 'POST'). |
required |
endpoint
|
str
|
The API endpoint to send the request to. |
required |
**kwargs
|
Any
|
Additional arguments to pass to the request. |
{}
|
Returns:
| Type | Description |
|---|---|
Response
|
httpx.Response: The response from the server. |
Source code in src/crosscontract/crossclient/crossclient.py
Entry point for operations on the collection of contracts.
Source code in src/crosscontract/crossclient/services/contract/contract_service.py
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 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 | |
__init__(client)
Initialize the ContractService. The ContractService is responsible for managing contracts on the CROSS platform. It provides methods to create, retrieve, list, and delete contracts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
CrossClient
|
The CrossClient instance to use for API calls. |
required |
Source code in src/crosscontract/crossclient/services/contract/contract_service.py
change_status(name, status)
Change the status of a contract. Allowable status transitions are enforced by the CROSS platform. The allowable statuses are: 1. Draft 2. Active 3. Suspended 4. Retired Allowed transitions: - Draft -> Active - Active -> Suspended - Suspended -> Active - Active -> Retired - Suspended -> Retired
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the contract to change status. |
required |
status
|
ContractStatus
|
The new status for the contract. |
required |
Raises:
| Type | Description |
|---|---|
HTTPStatusError
|
If the request fails. |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The updated status of the contract. |
Source code in src/crosscontract/crossclient/services/contract/contract_service.py
create(contract, activate=False)
Create a new contract on the CROSS platform
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
contract
|
CrossContract
|
The contract data to create. |
required |
activate
|
bool
|
Whether to activate the contract upon creation. Defaults to False. |
False
|
Raises:
| Type | Description |
|---|---|
HTTPStatusError
|
If the request fails. |
Returns:
| Name | Type | Description |
|---|---|---|
ContractResource |
ContractResource
|
The created contract object. |
Source code in src/crosscontract/crossclient/services/contract/contract_service.py
delete(name, hard=False)
Delete a contract by name if it exists. A contract can only be deleted if: 1. Contract is in "Draft" status 2. Contract status is "Retired" and the data associated with the contract is deleted
If hard is set to True, the contract and all associated data will be deleted.
Note: This is a dangerous operation and should be used with caution. Usually,
admin rights are required.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the contract to delete. |
required |
hard
|
bool
|
Whether to perform a hard delete (including data). Note: This is a dangerous operation and should be used with caution. it will delete all data associated with the contract. Usually, admin rights are required. |
False
|
Source code in src/crosscontract/crossclient/services/contract/contract_service.py
get(name)
Get contract from the CROSS platform by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the contract. |
required |
Raises:
| Type | Description |
|---|---|
HTTPStatusError
|
If the request fails. |
Returns:
| Name | Type | Description |
|---|---|---|
ContractResource |
ContractResource
|
The contract resource object. |
Source code in src/crosscontract/crossclient/services/contract/contract_service.py
get_list(contract_type=None)
Lists all available contracts as ContractResource objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
contract_type
|
list[str] | None
|
Optional filter restricting the
result to one or more contract types (e.g.
|
None
|
Returns:
| Type | Description |
|---|---|
dict[str, ContractResource]
|
dict[str, ContractResource]: Dictionary of contract resources keyed by contract name. |
Source code in src/crosscontract/crossclient/services/contract/contract_service.py
overview()
Get a DataFrame with an overview of all contracts, their status, and metadata.
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: DataFrame containing contract overviews. |
Source code in src/crosscontract/crossclient/services/contract/contract_service.py
A handle to a contract that exists on the CROSS platform.
ContractResources are read-only wrappers around contract data fetched from
the CROSS platform. They are produced exclusively by ContractService
methods (create, get, get_list); end users do not construct them
directly.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the contract. |
status |
str
|
The status of the contract. |
contract |
CrossContract
|
The full contract details. |
contract_type |
str
|
The type of the contract, e.g. |
service |
ContractService
|
The owning |
Source code in src/crosscontract/crossclient/services/contract/contract_resource.py
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 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 | |
is_dimension
property
True if the contract's tableschema is a dimension schema.
__init__(service, payload)
Initialise from a parsed server payload.
Most callers should use :meth:from_response to parse a raw JSON dict;
this constructor takes a pre-validated payload to keep tests direct.
Source code in src/crosscontract/crossclient/services/contract/contract_resource.py
add_data(data, validate=True, *, project_name=None)
Add data for the contract on the CROSS platform.
The rows are stored as owned by the resolved project.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
The data to be added. |
required |
validate
|
bool
|
Whether to validate the data against the contract schema before uploading. Defaults to True. |
True
|
project_name
|
str | None
|
Optional project name under which the data are submitted. If None, the CROSS platform infers the project from the caller's memberships, which succeeds only when there is exactly one. |
None
|
Raises:
| Type | Description |
|---|---|
ValidationError
|
If the data does not conform to the contract schema. |
CrossClientError
|
If the upload fails. Raised via
|
Source code in src/crosscontract/crossclient/services/contract/contract_resource.py
change_status(status)
Change the status of the contract.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
status
|
ContractStatus
|
The new status for the contract. |
required |
Source code in src/crosscontract/crossclient/services/contract/contract_resource.py
delete_data(filters, *, project_name=None, confirm_delete_all=False)
Delete rows from the contract's data matching the given equality filters.
Only rows owned by the resolved project are removed, and the contract
must be Active. drop_data() is the wider, separate operation: it
drops the whole storage table across every project and requires the
contract to be Retired.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filters
|
dict
|
Mapping of column name to value (or list of values)
to match. Values may be str/int/float/bool. Must be non-empty
unless |
required |
project_name
|
str | None
|
Optional project name for which project the data are deleted. If None, the CROSS platform infers the project from the caller's memberships, which succeeds only when there is exactly one. |
None
|
confirm_delete_all
|
bool
|
Confirms that an unfiltered delete is
intended, removing every row the resolved project owns under
this contract. Required when |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the contract's cached status is not |
CrossClientError
|
Propagated from the underlying service/HTTP request if the deletion request fails due to client, server, or network-related errors. |
Source code in src/crosscontract/crossclient/services/contract/contract_resource.py
drop_data()
Drop the storage table backing the contract on the CROSS platform.
This is a decommissioning operation: it discards the data of every
project that submitted under this contract, not only the caller's, and
requires the contract to be Retired. It is restricted to
administrators. To remove only the rows owned by one project, use
delete_data() — with confirm_delete_all=True to clear that
project's rows entirely.
Raises:
| Type | Description |
|---|---|
CrossClientError
|
If the request fails. Raised via
|
Source code in src/crosscontract/crossclient/services/contract/contract_resource.py
from_response(service, response_json)
classmethod
Build a ContractResource from a raw server response dict.
Source code in src/crosscontract/crossclient/services/contract/contract_resource.py
get_data(columns=None, filters=None, unique=False)
Get data for the contract from the CROSS platform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
columns
|
list[str] | None
|
Optional list of columns to retrieve. If None, all columns are retrieved. |
None
|
filters
|
dict[str, str] | None
|
Optional dictionary of filters to apply. The keys are column names and the values are the filter values. Currently, only equality filters are supported and only one value per filter. |
None
|
unique
|
bool
|
Whether to return only unique rows. |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: The data associated with the contract. |
Source code in src/crosscontract/crossclient/services/contract/contract_resource.py
refresh()
Re-fetch the contract details from the CROSS platform.
Source code in src/crosscontract/crossclient/services/contract/contract_resource.py
validate_dataframe(df, check_existing_primary_key=False, check_existing_foreign_key=False, check_dimension_granularity=False, lazy=True)
Validate a DataFrame against the schema of the contract.
By default nothing is read from the CROSS platform and the data is validated on its own. Setting a check flag reads from it: the primary key is then checked against the union of the stored keys and the DataFrame's own, the foreign keys against the stored values of the contracts they reference — plus the DataFrame's own rows in the case of a self-referencing foreign key — and the granularity check reads the hierarchy of each referenced dimension.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The DataFrame to validate. |
required |
check_existing_primary_key
|
bool
|
If True, also check the primary key against the values already stored for this contract. Default is False. |
False
|
check_existing_foreign_key
|
bool
|
If True, also check the foreign keys against the values already stored for the contracts they reference. Default is False. |
False
|
check_dimension_granularity
|
bool
|
If True, also check that no group
of otherwise-identical rows reports a member of a hierarchical
dimension alongside one of its descendants, which would count
that member twice when the data is summed. Only a ValueVariable
is checked, and only its references to a |
False
|
lazy
|
bool
|
If True, collect all validation errors and raise them together. If False, raise the first validation error encountered. Default is True. |
True
|
Raises:
| Type | Description |
|---|---|
ValidationError
|
If the DataFrame does not conform to the schema. |
CrossClientError
|
If fetching the stored values fails. Raised via
|
Source code in src/crosscontract/crossclient/services/contract/contract_resource.py
Bases: ContractResolver
Reads contracts and their data from the CROSS platform.
Answers the two questions a contract cannot answer on its own: what another contract looks like, and which values are already stored under it. Used when validating data against a contract that references other contracts.
Reaches the platform over HTTP through a ContractService, so it sees
whatever the authenticated caller is allowed to read.
Source code in src/crosscontract/crossclient/services/contract/resolver.py
__init__(service)
Initialise the resolver with the service it reads through.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
service
|
ContractService
|
The service used to reach the platform. |
required |
Source code in src/crosscontract/crossclient/services/contract/resolver.py
get_data(name, columns, *, unique=True)
Get the stored values of the given columns for a contract.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the contract to read from. |
required |
columns
|
list[str]
|
The columns to retrieve. |
required |
unique
|
bool
|
Whether to return only unique rows. Defaults to
|
True
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: The requested columns of the named contract. |
Raises:
| Type | Description |
|---|---|
CrossClientError
|
If the read fails. Raised via
|
Source code in src/crosscontract/crossclient/services/contract/resolver.py
resolve(name)
Get a contract by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the contract. |
required |
Returns:
| Type | Description |
|---|---|
CrossContract | None
|
CrossContract | None: The contract, or |
CrossContract | None
|
contract with that name. |
Raises:
| Type | Description |
|---|---|
CrossClientError
|
If the read fails for any reason other than the
contract being absent. Only a missing contract becomes |
Source code in src/crosscontract/crossclient/services/contract/resolver.py
Entry point for operations on submission contracts and their submissions.
Source code in src/crosscontract/crossclient/services/submission/submission_service.py
16 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 | |
__init__(client)
Initialize the service.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
CrossClient
|
The CrossClient instance to use for API calls. |
required |
Source code in src/crosscontract/crossclient/services/submission/submission_service.py
create(contract)
Create a submission contract on the CROSS platform.
Every target of the contract must name an existing, active data contract.
If reading it back after the creation fails, the submission contract
already exists; fetch it with get instead of calling create again.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
contract
|
SubmissionContract
|
The submission contract to create. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
SubmissionContractResource |
SubmissionContractResource
|
The created submission contract. |
Raises:
| Type | Description |
|---|---|
CrossClientError
|
If the request fails, e.g. |
Source code in src/crosscontract/crossclient/services/submission/submission_service.py
delete(name)
Delete a submission contract by name.
The data contracts its targets name are not affected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the submission contract. |
required |
Raises:
| Type | Description |
|---|---|
CrossClientError
|
If the request fails, e.g. |
Source code in src/crosscontract/crossclient/services/submission/submission_service.py
get(name)
Get a submission contract by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the submission contract. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
SubmissionContractResource |
SubmissionContractResource
|
The submission contract. |
Raises:
| Type | Description |
|---|---|
CrossClientError
|
If the request fails, e.g. |
Source code in src/crosscontract/crossclient/services/submission/submission_service.py
get_submission(uuid)
Get a submission by its uuid, e.g. to follow its processing state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uuid
|
UUID | str
|
The uuid of the submission. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Submission |
Submission
|
The submission. |
Raises:
| Type | Description |
|---|---|
CrossClientError
|
If the request fails, e.g. |
Source code in src/crosscontract/crossclient/services/submission/submission_service.py
list_submissions(name)
List every submission of a submission contract, oldest first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the submission contract. |
required |
Returns:
| Type | Description |
|---|---|
list[Submission]
|
list[Submission]: The submissions. |
Raises:
| Type | Description |
|---|---|
CrossClientError
|
If the request fails, e.g. |
Source code in src/crosscontract/crossclient/services/submission/submission_service.py
overview(project_name)
Get an overview of a project's submission contracts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_name
|
str
|
The name of the project. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: One row per submission contract, with the columns
|
Raises:
| Type | Description |
|---|---|
CrossClientError
|
If the request fails, e.g. |
Source code in src/crosscontract/crossclient/services/submission/submission_service.py
set_allow_submissions(name, allow)
Open or close a submission contract for submissions.
Closing it stops new uploads; submissions already received are still processed. Setting the value it already has changes nothing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the submission contract. |
required |
allow
|
bool
|
|
required |
Raises:
| Type | Description |
|---|---|
CrossClientError
|
If the request fails, e.g. |
Source code in src/crosscontract/crossclient/services/submission/submission_service.py
A handle to a submission contract that exists on the CROSS platform.
Produced by the service's create and get; not constructed directly.
Its properties are read-only and change only through its methods.
validate_submission checks a delivered bundle against the stored
submission contract.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the submission contract. |
project_name |
str
|
The name of the project owning the submission contract. |
title |
str
|
The title of the submission contract. |
description |
str
|
The description of the submission contract. |
tags |
list[str]
|
The tags of the submission contract. |
allow_submissions |
bool
|
Whether the owning project may currently upload submissions. |
contract |
SubmissionContract
|
The stored submission contract. |
Source code in src/crosscontract/crossclient/services/submission/submission_resource.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 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 | |
allow_submissions
property
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
Whether the owning project may currently upload submissions. |
contract
property
Returns:
| Name | Type | Description |
|---|---|---|
SubmissionContract |
SubmissionContract
|
The stored submission contract. |
description
property
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The description of the submission contract. |
name
property
Return the name of the submission contract.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The name of the submission contract. |
project_name
property
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The name of the project owning the submission contract. |
tags
property
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: The tags of the submission contract. |
title
property
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The title of the submission contract. |
__init__(service, payload)
Initialize from a parsed server payload.
Use from_response to build a resource from a raw response dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
service
|
SubmissionContractService
|
The service the resource delegates its methods to. |
required |
payload
|
SubmissionContractEntryPayload
|
The parsed server response. |
required |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If |
Source code in src/crosscontract/crossclient/services/submission/submission_resource.py
delete()
Delete the submission contract from the CROSS platform.
The data contracts its targets name are not affected.
Raises:
| Type | Description |
|---|---|
CrossClientError
|
If the request fails, e.g. |
Source code in src/crosscontract/crossclient/services/submission/submission_resource.py
from_response(service, response_json)
classmethod
Build a resource from a raw server response dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
service
|
SubmissionContractService
|
The service the resource delegates its methods to. |
required |
response_json
|
dict[str, Any]
|
The response body of a read of one submission contract. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
SubmissionContractResource |
SubmissionContractResource
|
The resource. |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If the response or its |
Source code in src/crosscontract/crossclient/services/submission/submission_resource.py
refresh()
Reload the submission contract from the CROSS platform.
Raises:
| Type | Description |
|---|---|
CrossClientError
|
If the request fails, e.g. |
ValueError
|
If the CROSS platform returns a submission contract of a different name. |
Source code in src/crosscontract/crossclient/services/submission/submission_resource.py
set_allow_submissions(allow)
Open or close the submission contract for submissions.
Closing it stops new uploads; submissions already received are still processed. Setting the value it already has changes nothing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
allow
|
bool
|
|
required |
Raises:
| Type | Description |
|---|---|
CrossClientError
|
If the request fails, e.g. |
Source code in src/crosscontract/crossclient/services/submission/submission_resource.py
submissions()
Fetch every submission of this submission contract, oldest first.
Returns:
| Type | Description |
|---|---|
list[Submission]
|
list[Submission]: The submissions. |
Raises:
| Type | Description |
|---|---|
CrossClientError
|
If the request fails, e.g. |
Source code in src/crosscontract/crossclient/services/submission/submission_resource.py
submit(df, filename=None, validate=True)
Validate a delivered bundle, then upload it under this submission contract.
The bundle is uploaded as a parquet file, exactly as handed in. With
validate=True it is first checked by validate_submission with its
defaults, and nothing is uploaded if any check fails. To validate with
other settings, call validate_submission with the flags you need and
then submit(df, validate=False).
Validation here is advisory: the CROSS platform validates the
submission again on ingest and can still reject it. Processing on the
platform is asynchronous; follow the returned submission's state with
SubmissionContractService.get_submission.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The bundle as delivered. |
required |
filename
|
str | None
|
The stem of the uploaded file;
|
None
|
validate
|
bool
|
Whether to validate the bundle before
uploading it. Defaults to |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
Submission |
Submission
|
The created submission, in state |
Raises:
| Type | Description |
|---|---|
SchemaValidationError
|
The bundle does not satisfy the submission
contract's own schema. Only with |
UnclaimedRowsError
|
The bundle holds rows no target claims. Only
with |
TargetValidationError
|
At least one target's data failed. Only with
|
ValueError
|
A target names a contract that cannot be read. Only
with |
KeyError
|
A column named by a target's |
ArrowException
|
The bundle cannot be written as parquet,
e.g. |
CrossClientError
|
A request to the CROSS platform failed, e.g.
|
Source code in src/crosscontract/crossclient/services/submission/submission_resource.py
validate_submission(df, check_existing_primary_key=False, check_existing_foreign_key=True, check_dimension_granularity=True, lazy=True)
Validate a delivered bundle against this submission contract.
Runs SubmissionHandler.validate_submission on the stored contract,
reading the target contracts and their stored values from the CROSS
platform. The steps stop at the first failure; see that method for what
each check covers. By default the stored primary keys are not checked,
because a submission replaces the rows stored under its replace_key.
Validation here is advisory: the platform validates a submission again
on ingest and can still reject it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The bundle as delivered. |
required |
check_existing_primary_key
|
bool
|
If True, also check each target's primary key against the values already stored for the contract it names, including the rows this submission would replace. Defaults to False. |
False
|
check_existing_foreign_key
|
bool
|
If True, also check each target's foreign keys against the values already stored for the contracts they reference. Defaults to True. |
True
|
check_dimension_granularity
|
bool
|
If True, also check that no ValueVariable target reports a dimension member alongside one of its descendants. Defaults to True. |
True
|
lazy
|
bool
|
If True, collect all of a step's validation errors and raise them together. If False, raise the first error encountered. Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
dict[str, DataFrame]
|
dict[str, pd.DataFrame]: The validated, coerced target data, keyed by target name. |
Raises:
| Type | Description |
|---|---|
SchemaValidationError
|
The bundle does not satisfy the submission contract's own schema. |
UnclaimedRowsError
|
The bundle holds rows no target claims. |
TargetValidationError
|
At least one target's data failed, holding one entry per failing target. |
ValueError
|
A target names a contract that cannot be read. |
KeyError
|
A column named by a target's |
CrossClientError
|
A read from the CROSS platform failed. |
Source code in src/crosscontract/crossclient/services/submission/submission_resource.py
Bases: BaseModel
A submission on the CROSS platform: what was uploaded, by whom, and its state.
Holds metadata only, not the uploaded file. state is received right
after the upload, processing while the platform works on it, and ends as
current (valid and stored), rejected (invalid, nothing stored) or
failed (a platform error, nothing stored). A current submission becomes
superseded once a newer submission replaces its data.