Public API Reference¶
Public / stable. Import the symbols on this page from
opensportslib.apisoropensportslib.tools. Other package modules are not compatibility-stable unless a developer page labels them an extension point.
Task wrappers¶
All task wrappers accept a canonical config path or Config, optional local or
Hugging Face weights, and optional remote-server connection parameters.
train() uses configured or supplied manifests; infer() returns an in-memory
prediction payload; evaluate() returns a metrics dictionary; and
save_predictions() is the explicit disk-write operation.
| Class | Use | Important inputs and side effects |
|---|---|---|
ClassificationModel |
Clip, frame-array, and supported tracking classification. | Creates run artifacts under the configured save directory; may load local/Hub weights. |
LocalizationModel |
Action spotting/localization for configured video, feature, tracking, and HDF5 paths. | Model family and loader backend determine the execution route. |
VQAModel |
X-VARS/Qwen visual question answering. | Requires the matching VQA dependency profile; direct inference accepts video_path and question. |
BaseTaskModel |
Shared abstract wrapper contract. | Provides local/remote request lifecycle; subclass methods implement task execution. |
from opensportslib.apis import ClassificationModel
model = ClassificationModel(config="/path/to/classification.yaml")
predictions = model.infer(test_set="/path/to/test.json")
model.save_predictions("/path/to/predictions.json", predictions)
Exact wrapper signatures¶
Bases: ConfigurationMixin, ABC
Thin shared contract for task-level OpenSportsLib wrappers.
Source code in opensportslib/apis/base_task_model.py
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 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 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 | |
is_remote
property
¶
Whether inference requests are sent to an OpenSportsLib server.
submit_inference(*, task_type, test_set, model_id=None, task_options=None)
¶
Upload a complete JSON manifest and its referenced local media as one job.
Source code in opensportslib/apis/base_task_model.py
submit_per_sample_inference(*, task_type, test_set, model_id=None, task_options=None)
¶
Submit one asynchronous remote job for every sample in an OSL manifest.
Source code in opensportslib/apis/base_task_model.py
submit_video_inference(*, task_type, video_path, question=None, session_id=None, model_id=None, task_options=None)
¶
Submit one video for direct task inference.
Source code in opensportslib/apis/base_task_model.py
get_remote_job(job_id)
¶
get_remote_result(job_id)
¶
wait_for_remote_result(job_id, timeout=None)
¶
Poll a submitted remote job until it succeeds, fails, or times out.
Source code in opensportslib/apis/base_task_model.py
wait_for_remote_batch(batch, timeout=None)
¶
Collect a per-sample batch without discarding successful sample predictions.
Source code in opensportslib/apis/base_task_model.py
Bases: BaseTaskModel
Top-level task wrapper for classification.
Source code in opensportslib/apis/classification.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 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 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 | |
load_weights(weights=None, **kwargs)
¶
Source code in opensportslib/apis/classification.py
train(train_set=None, valid_set=None, test_set=None, weights=None, use_ddp=False, use_wandb=True, **kwargs)
¶
Run full training and return best checkpoint path.
Source code in opensportslib/apis/classification.py
infer(test_set=None, weights=None, use_ddp=False, use_wandb=True, video_path=None, session_id=None, **kwargs)
¶
Run model inference and return predictions in OSL JSON format.
Source code in opensportslib/apis/classification.py
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 399 400 401 402 403 404 405 406 407 408 409 410 | |
evaluate(test_set=None, weights=None, predictions=None, use_ddp=False, use_wandb=True, **kwargs)
¶
Run inference on test set and return evaluation metrics.
Source code in opensportslib/apis/classification.py
Bases: BaseTaskModel
Top-level task wrapper for localization / spotting.
Source code in opensportslib/apis/localization.py
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 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 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 | |
load_weights(weights=None, **kwargs)
¶
Source code in opensportslib/apis/localization.py
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 | |
train(train_set=None, valid_set=None, weights=None, use_wandb=True, **kwargs)
¶
Source code in opensportslib/apis/localization.py
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 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 | |
infer(test_set=None, weights=None, use_wandb=True, video_path=None, session_id=None, **kwargs)
¶
Run model inference and return predictions in OSL JSON format.
Source code in opensportslib/apis/localization.py
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 | |
evaluate(test_set=None, weights=None, predictions=None, use_wandb=True, **kwargs)
¶
Source code in opensportslib/apis/localization.py
Bases: BaseTaskModel
Top-level task wrapper for VQA.
Source code in opensportslib/apis/vqa.py
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 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 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 | |
load_weights(weights=None, **kwargs)
¶
Source code in opensportslib/apis/vqa.py
train(train_set=None, valid_set=None, weights=None, resume_from_checkpoint=None, use_ddp=None, use_wandb=True, **kwargs)
¶
Source code in opensportslib/apis/vqa.py
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 | |
infer(test_set=None, weights=None, use_wandb=True, video_path=None, question=None, session_id=None, **kwargs)
¶
Source code in opensportslib/apis/vqa.py
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 | |
evaluate(test_set=None, weights=None, predictions=None, use_wandb=True, **kwargs)
¶
Source code in opensportslib/apis/vqa.py
save_predictions(output_path, predictions, output_format='osl')
¶
Persist VQA predictions, optionally as X-VARS-compatible rows.
Source code in opensportslib/apis/vqa.py
Configuration API¶
Config loads, composes, migrates, validates, and edits a configuration before
model allocation. Config.from_pretrained() downloads config.yaml from a Hub
model repository, so it needs network access and any required Hugging Face
authentication. Use options() before update() to discover supported,
validated settings.
Editable OSL config. Loading this object never allocates model weights.
Source code in opensportslib/core/config/editable.py
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 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 | |
from_file(path)
classmethod
¶
Source code in opensportslib/core/config/editable.py
from_pretrained(model_id)
classmethod
¶
Source code in opensportslib/core/config/editable.py
get_config()
¶
options()
¶
Source code in opensportslib/core/config/editable.py
update(*, data=None, runtime=None, training=None, inference=None, overrides=None, **groups)
¶
Source code in opensportslib/core/config/editable.py
apply_to(config)
¶
Reapply explicit updates after a runtime/checkpoint config merge.
Source code in opensportslib/core/config/editable.py
remote_overrides()
¶
Source code in opensportslib/core/config/editable.py
Remote model registry¶
RemoteModelRegistry is an administrative client for the separately deployed
server. register_model, set_default, unregister_model, and
reconcile_runtime mutate server state; use reconcile_runtime(dry_run=True)
to inspect safely. Local registration requires a server API key; Hub operations
may require an HF token.
Administrative client for an OpenSportsLib server model registry.
Source code in opensportslib/remote_registry.py
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 | |
register_model(*, task_type, huggingface_model_id=None, weights_path=None, config_path=None, model_id=None, hf_token=None)
¶
Register exactly one Hugging Face or server-local model source.
Source code in opensportslib/remote_registry.py
list_models()
¶
get_model(model_id)
¶
get_operation(operation_id)
¶
wait_for_operation(operation_id, *, timeout=7200.0, poll_interval=1.0)
¶
Source code in opensportslib/remote_registry.py
set_default(task_type, model_id)
¶
unregister_model(model_id, hf_token=None)
¶
reconcile_runtime(*, dry_run=True, include_active=False)
¶
Inspect or recover stale server jobs; dry-run is the safe default.
Source code in opensportslib/remote_registry.py
Conversion and Hugging Face tools¶
These exports are stable, but many perform disk and network work. Conversion functions create Parquet/WebDataset or JSON output. Hugging Face download and upload functions access remote repositories and can write local media or remote repository content. Inspect their signatures before use and use the dataset transfer guide for complete flows.
Convert an OpenSportsLib-style JSON annotation file into
1) a Parquet table with flattened metadata 2) WebDataset TAR shards containing the referenced input files + sample metadata
Each sample typically contains
- id
- inputs: [{"type": "...", "path": "...", ...}, ...]
- optional task-specific fields: events / captions / dense_captions / labels / metadata
Public entry point
convert_json_to_parquet(...)
parse_shard_size(value)
¶
Parse byte counts such as 500MB, 1GB, or 1024MiB.
Source code in opensportslib/tools/osl_json_to_parquet.py
convert_json_to_parquet(json_path, media_root, output_dir, *, shard_mode='size', shard_size=DEFAULT_SHARD_SIZE, samples_per_shard=100, compression='zstd', shard_prefix='shard', missing_policy='raise', keep_relative_paths_in_parquet=True, overwrite=False)
¶
Convert an OSL-style JSON file to
- metadata.parquet (flattened, queryable per-sample table)
- shards/*.tar (WebDataset TAR shards with input files + sidecar JSON)
- shard_manifest.parquet
Parameters¶
json_path:
Path to the JSON annotation file.
media_root:
Root directory where files referenced in inputs[].path live.
output_dir:
Destination directory.
shard_mode:
"size" groups samples by target TAR shard size.
"samples" groups samples by samples_per_shard.
shard_size:
Target on-disk TAR shard size for shard_mode="size". Accepts bytes
or strings such as "500MB", "1GB", or "1024MiB".
samples_per_shard:
Number of samples grouped in one TAR shard when shard_mode="samples".
compression:
Parquet compression codec ("zstd", "snappy", "gzip", or None).
shard_prefix:
Prefix for TAR shard file names.
missing_policy:
"raise" — abort if a referenced input file is missing.
"skip" — keep sample in Parquet but omit missing file from shard.
keep_relative_paths_in_parquet:
If True (default), Parquet stores original relative paths from JSON.
If False, Parquet stores resolved absolute paths.
overwrite:
Whether to remove and recreate output_dir if it already exists.
Returns¶
dict Summary with counts of samples, shards, and input files processed.
Source code in opensportslib/tools/osl_json_to_parquet.py
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 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 | |
Convert a dataset stored as
- metadata.parquet
- WebDataset TAR shards (created by osl_json_to_parquet.py)
back into an OpenSportsLib-style JSON file.
Notes¶
- Full reconstruction prefers the per-sample sidecar JSON stored inside each TAR shard.
- Current metadata.parquet files also store a full
sample_payloadcopy, so annotation-only reconstruction does not need to fetch any shard. - By default, reconstructed
inputs[].pathvalues remain the original relative paths. Passextract_media=Trueto also extract the input files from the shards.
Public entry point
convert_parquet_to_json(...)
convert_parquet_metadata_to_json(metadata_path, output_json_path, *, json_indent=2)
¶
Reconstruct OSL JSON using only a WebDataset metadata.parquet file.
Metadata-only reconstruction requires the current schema's full-fidelity
sample_payload column. No TAR shards are opened or required.
Source code in opensportslib/tools/parquet_to_osl_json.py
convert_parquet_to_json(dataset_dir, output_json_path, *, extract_media=False, output_media_root=None, overwrite_media=False, json_indent=2)
¶
Convert a Parquet + WebDataset directory back to an OSL-style JSON file.
The input directory must contain metadata.parquet and a shards/
sub-directory produced by :func:opensportslib.tools.convert_json_to_parquet.
Parameters¶
dataset_dir:
Directory produced by the forward converter.
output_json_path:
Destination JSON file path.
extract_media:
If True, extract media files from TAR shards into output_media_root.
inputs[].path values are preserved as-is (original relative paths).
output_media_root:
Root directory for extracted media. Required when extract_media=True.
overwrite_media:
Whether to overwrite already-extracted media files.
json_indent:
Indentation level for the output JSON.
Returns¶
dict Summary with sample count and extraction statistics.
Source code in opensportslib/tools/parquet_to_osl_json.py
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 | |
HfTransferCancelled
¶
MissingDatasetInputsError
¶
Bases: FileNotFoundError
Raised before upload when dataset references are absent locally.
Source code in opensportslib/tools/hf_transfer.py
download_dataset_split_from_hf(repo_id, revision, split, output_dir, *, download_format='parquet', annotations_only=False, dry_run=False, token=None, progress_cb=None, byte_progress_cb=None, file_plan_cb=None, file_completed_cb=None, json_ready_cb=None, is_cancelled=None)
¶
Source code in opensportslib/tools/hf_transfer.py
download_dataset_sample_inputs_from_hf(dataset_json_path, sample_id, *, input_path=None, overwrite=False, token=None, progress_cb=None, byte_progress_cb=None, is_cancelled=None)
¶
Download one sample or input from the immutable HF source of a local JSON.
Source code in opensportslib/tools/hf_transfer.py
download_dataset_missing_inputs_from_hf(dataset_json_path, *, token=None, progress_cb=None, byte_progress_cb=None, is_cancelled=None)
¶
Hydrate all locally missing inputs from the JSON's pinned HF source.
Source code in opensportslib/tools/hf_transfer.py
1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 | |
find_missing_dataset_inputs(dataset_json_path)
¶
Return referenced primary and companion inputs that are absent locally.
Source code in opensportslib/tools/hf_transfer.py
upload_dataset_inputs_from_json_to_hf(repo_id, json_path, *, revision='main', split=None, commit_message=None, token=None, progress_cb=None, is_cancelled=None)
¶
Source code in opensportslib/tools/hf_transfer.py
1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 | |
upload_dataset_as_parquet_to_hf(repo_id, json_path, *, revision='main', split=None, commit_message=None, shard_mode='size', shard_size=DEFAULT_SHARD_SIZE, samples_per_shard=100, token=None, progress_cb=None, is_cancelled=None)
¶
Convert an OSL JSON dataset to Parquet + WebDataset format and upload the result to a HuggingFace dataset repository under a folder named after the JSON file stem.
For example, annotations_test.json is converted and uploaded to the
annotations_test/ folder on the repository.
A temporary directory is used for the conversion output and removed when done.
Source code in opensportslib/tools/hf_transfer.py
1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 | |
create_dataset_repo_on_hf(repo_id, *, token=None, private=False, progress_cb=None)
¶
Source code in opensportslib/tools/hf_transfer.py
dataset_repo_exists_on_hf(repo_id, *, token=None)
¶
Source code in opensportslib/tools/hf_transfer.py
create_dataset_branch_on_hf(repo_id, branch, *, source_revision='main', token=None, progress_cb=None)
¶
Source code in opensportslib/tools/hf_transfer.py
See extension APIs for builders and runtime modules, and internal catalog for concrete implementation classes.