CLI API
cli
Typer CLI entry point.
Functions:
| Name | Description |
|---|---|
download_ita |
Download Normattiva datasets and update the inventory database. |
ingest_ita |
Ingest downloaded datasets into canonical SQLite outputs. |
backfill_ita |
Run backfill downloads using ingest-produced missing-interval hints. |
storage_upload |
Upload selected local directories to S3-compatible object storage. |
storage_download |
Download selected object storage prefixes into local directories. |
storage_purge |
Delete all objects under selected prefixes in object storage. |
download_ita
download_ita(
verbose: bool = Option(
False,
"--verbose",
"-v",
help="Enable verbose logging",
),
output_dir: Path = Option(
Path("exports/normattiva/ita"),
"--output-dir",
"-o",
help="Directory for storing downloaded datasets.",
),
overlap_days: int = Option(
2,
"--overlap-days",
help="Number of days to overlap when computing incremental download windows.",
),
skip_history_bulk: bool = Option(
True,
"--skip-history-bulk/--no-skip-history-bulk",
help="Skip historical V/O bulk windows (older than multivigente start).",
),
per_act_concurrency: int = Option(
10,
"--per-act-concurrency",
help="Max parallel per-act exports (default 10).",
),
per_act_export_modes: str = Option(
"V,M,O",
"--per-act-export-modes",
help="Comma-separated export modes for per-act fallback. V=vigente, M=multivigente, O=originario. Order determines priority.",
),
per_act_export_formats: str = Option(
"akn,json,nir",
"--per-act-export-formats",
help="Comma-separated formats to download. Options: json,akn,nir. Default 'akn,json,nir' (nir runs after akn/json).",
),
predefined_export_formats: str = Option(
"akn,json,nir",
"--predefined-export-formats",
help="Comma-separated predefined collection export formats. Options: akn,json,nir.",
),
predefined_vigenza_modes: str = Option(
"O,M,V",
"--predefined-vigenza-modes",
help="Comma-separated predefined collection vigenza modes. Options: O,M,V.",
),
shard_mod: int | None = Option(
None,
"--shard-mod",
help="Shard modulus for deterministic sharding by act_id (e.g. 2 for two machines).",
),
shard_rem: int | None = Option(
None,
"--shard-rem",
help="Shard remainder for deterministic sharding by act_id (e.g. 0 or 1 when --shard-mod=2).",
),
richiesta_export: str = Option(
"M",
"--richiesta-export",
"-r",
help="Async export tipo richiesta: 'M' multivigente, 'V' vigente, 'O' originario.",
),
build_manifest: bool = Option(
True,
"--build-manifest/--no-build-manifest",
help="Build or skip the act manifest enumeration step.",
),
manifest_start_year: int = Option(
1861,
"--manifest-start-year",
help="Start year for act manifest enumeration.",
),
manifest_end_year: int | None = Option(
None,
"--manifest-end-year",
help="Optional end year for act manifest enumeration.",
),
manifest_year_window: int = Option(
1,
"--manifest-year-window",
help="Year window size for act manifest enumeration.",
),
manifest_year_window_concurrency: int = Option(
1,
"--manifest-window-concurrency",
help="Max concurrent act manifest windows.",
),
manifest_page_size: int = Option(
200,
"--manifest-page-size",
help="Page size for act manifest enumeration.",
),
manifest_max_pages: int | None = Option(
None,
"--manifest-max-pages",
help="Optional page cap per manifest enumeration window.",
),
manifest_page_delay_seconds: float = Option(
0.5,
"--manifest-page-delay",
help="Delay (seconds) between manifest page requests.",
),
manifest_window_delay_seconds: float = Option(
1.0,
"--manifest-window-delay",
help="Delay (seconds) before each manifest window request.",
),
manifest_request_retry_attempts: int = Option(
3,
"--manifest-request-retries",
help="Retry attempts for manifest requests.",
),
manifest_request_retry_sleep_seconds: float = Option(
5.0,
"--manifest-request-retry-sleep",
help="Sleep (seconds) between manifest request retries.",
),
log_file: Path | None = Option(
None,
"--log-file",
help="Optional file path to write download logs.",
),
manifest_db_path: Path | None = Option(
None,
"--manifest-db-path",
help="Optional override path for `download_manifest.db` (defaults to output_dir/download_manifest.db).",
),
dedupe_by_sha: bool = Option(
True,
"--dedupe-by-sha/--no-dedupe-by-sha",
help="Skip writing duplicate artifacts when sha256 matches an existing one.",
),
) -> None
Download Normattiva datasets and update the inventory database.
Source code in src/law_graph/cli.py
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 | |
ingest_ita
ingest_ita(
input_dir: Path = Option(
Path("exports/normattiva/ita"),
"--input-dir",
"-i",
help="Directory containing Normattiva exports and download_manifest.db.",
),
output_dir: Path = Option(
Path("exports/processed/ita"),
"--output-dir",
"-o",
help="Output directory for canonical ingest state DB (ingest_manifest.db).",
),
limit: int | None = Option(
None,
"--limit",
"-n",
help="Optional limit of acts to process (for quick local runs).",
),
verbose: bool = Option(
False,
"--verbose",
"-v",
help="Enable verbose debug logging for ingestion.",
),
log_file: Path | None = Option(
None,
"--log-file",
help="Optional file path to write ingestion logs.",
),
quiet: bool = Option(
False,
"--quiet",
help="Reduce logging verbosity during ingestion (suppresses per-node INFO).",
),
act_concurrency: int | None = Option(
None,
"--act-concurrency",
help="Number of parallel acts processed concurrently. Defaults to a CPU-based heuristic.",
),
act_batch_size: int | None = Option(
None,
"--act-batch-size",
help="Maximum number of in-flight variant tasks queued globally.",
),
max_inflight_variants_per_act: int | None = Option(
None,
"--max-inflight-variants-per-act",
help="Cap for in-flight variants of a single act (default: auto == worker count).",
),
memory_budget_mb: int | None = Option(
None,
"--memory-budget-mb",
help="Approximate worker-memory budget in MB for ingestion scheduling decisions (default: auto, 80%% of available RAM).",
),
act_max_tasks: int | None = Option(
15,
"--act-max-tasks",
help="Maximum number of act tasks a worker handles before respawn (maxtasksperchild).",
),
ingest_manifest_path: Path | None = Option(
None,
"--ingest-manifest",
help="Path to the ingest manifest DB used for incremental builds.",
),
missing_intervals_path: Path | None = Option(
None,
"--missing-intervals-path",
help="Optional path to ingest manifest DB used for missing-interval snapshots (defaults to output_dir/ingest_manifest.db).",
),
write_missing_intervals: bool = Option(
True,
"--write-missing-intervals/--no-write-missing-intervals",
help="Enable or disable writing missing-interval hints (records persist across runs and are merged incrementally).",
),
force_reparse: bool = Option(
False,
"--force-reparse",
help="Process all acts even if unchanged and rebuild missing-interval hints from scratch.",
),
) -> None
Ingest downloaded datasets into canonical SQLite outputs.
Source code in src/law_graph/cli.py
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 | |
backfill_ita
backfill_ita(
input_dir: Path = Option(
Path("exports/normattiva/ita"),
"--input-dir",
"-i",
help="Directory containing Normattiva exports and download_manifest.db (backfill writes into this tree).",
),
dry_run: bool = Option(
False,
"--dry-run",
help="Plan queries but do not call Normattiva or write files.",
),
limit_items: int | None = Option(
None,
"--limit-items",
help="Optional cap on how many acts to scan.",
),
max_queries_per_item: int | None = Option(
None,
"--max-queries-per-item",
help="Maximum number of vigenza dates to query per act (default: unlimited).",
),
max_total_queries: int | None = Option(
None,
"--max-total-queries",
help="Maximum number of (date,format) queries across the whole run (default: unlimited).",
),
concurrency: int = Option(
2,
"--concurrency",
"-c",
help="Maximum number of concurrent in-flight Normattiva requests.",
),
min_start_interval_seconds: float = Option(
1.0,
"--min-start-interval-seconds",
help="Minimum delay between starting async searches.",
),
open_interval_offset_days: int = Option(
30,
"--open-interval-offset-days",
help="Days to offset from interval start when end date is open.",
),
cache_path: Path = Option(
Path("backfill_cache.jsonl"),
"--cache-path",
help="Path to the persistent cache index (relative paths resolve under the input directory).",
),
cache_dir: Path = Option(
Path("backfill_cache"),
"--cache-dir",
help="Directory where cached vigente bundles are stored (relative paths resolve under the input directory).",
),
cache_max_bytes: int | None = Option(
2 * 1024 * 1024 * 1024,
"--cache-max-bytes",
help="Max total bytes for cached bundles; set to 0 to disable pruning.",
),
disable_cache: bool = Option(
False,
"--disable-cache",
help="Disable reading and writing the persistent cache (debugging aid).",
),
missing_intervals_path: Path | None = Option(
None,
"--missing-intervals-path",
help="Ingest manifest DB emitted by ingest (required; defaults to processed/ingest_manifest.db when found).",
),
verbose: bool = Option(
False,
"--verbose",
"-v",
help="Enable verbose logging",
),
log_file: Path | None = Option(
None,
"--log-file",
help="Optional file path to write backfill logs.",
),
) -> None
Run backfill downloads using ingest-produced missing-interval hints.
Source code in src/law_graph/cli.py
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 | |
storage_upload
storage_upload(
bucket: str | None = Option(
None,
"--bucket",
help="Target object storage bucket (env: LAW_GRAPH_S3_BUCKET).",
),
endpoint_url: str | None = Option(
None,
"--endpoint-url",
help="S3-compatible endpoint URL (env: LAW_GRAPH_S3_ENDPOINT_URL).",
),
region: str | None = Option(
None,
"--region",
help="Bucket region (env: LAW_GRAPH_S3_REGION).",
),
access_key_id: str | None = Option(
None,
"--access-key-id",
help="Access key ID (env: LAW_GRAPH_S3_ACCESS_KEY_ID).",
),
secret_access_key: str | None = Option(
None,
"--secret-access-key",
help="Secret access key (env: LAW_GRAPH_S3_SECRET_ACCESS_KEY).",
),
session_token: str | None = Option(
None,
"--session-token",
help="Session token (env: LAW_GRAPH_S3_SESSION_TOKEN).",
),
max_pool_connections: int | None = Option(
None,
"--max-pool-connections",
min=1,
help="Max S3 client connection pool size (env: LAW_GRAPH_S3_MAX_POOL_CONNECTIONS).",
),
root_dir: Path = Option(
Path("."),
"--root-dir",
help="Local root directory used to resolve --dir paths and S3 object keys.",
),
directories: list[Path] | None = Option(
None,
"--dir",
help="Directory to upload; repeat for multiple directories.",
),
delete_remote_missing: bool = Option(
True,
"--delete-remote-missing/--no-delete-remote-missing",
help="Delete remote objects under selected prefixes that are absent locally.",
),
skip_existing_non_db: bool = Option(
True,
"--skip-existing-non-db/--no-skip-existing-non-db",
help="Skip re-upload for existing non-DB files.",
),
max_workers: int = Option(
DEFAULT_UPLOAD_WORKERS,
"--max-workers",
min=1,
help="Max parallel upload workers.",
),
verbose: bool = Option(
False,
"--verbose",
"-v",
help="Enable verbose logging",
),
log_file: Path | None = Option(
None,
"--log-file",
help="Optional file path to write upload logs.",
),
) -> None
Upload selected local directories to S3-compatible object storage.
Source code in src/law_graph/cli.py
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 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 | |
storage_download
storage_download(
bucket: str | None = Option(
None,
"--bucket",
help="Source object storage bucket (env: LAW_GRAPH_S3_BUCKET).",
),
endpoint_url: str | None = Option(
None,
"--endpoint-url",
help="S3-compatible endpoint URL (env: LAW_GRAPH_S3_ENDPOINT_URL).",
),
region: str | None = Option(
None,
"--region",
help="Bucket region (env: LAW_GRAPH_S3_REGION).",
),
access_key_id: str | None = Option(
None,
"--access-key-id",
help="Access key ID (env: LAW_GRAPH_S3_ACCESS_KEY_ID).",
),
secret_access_key: str | None = Option(
None,
"--secret-access-key",
help="Secret access key (env: LAW_GRAPH_S3_SECRET_ACCESS_KEY).",
),
session_token: str | None = Option(
None,
"--session-token",
help="Session token (env: LAW_GRAPH_S3_SESSION_TOKEN).",
),
max_pool_connections: int | None = Option(
None,
"--max-pool-connections",
min=1,
help="Max S3 client connection pool size (env: LAW_GRAPH_S3_MAX_POOL_CONNECTIONS).",
),
root_dir: Path = Option(
Path("."),
"--root-dir",
help="Local root directory where downloaded objects are written.",
),
prefixes: list[str] | None = Option(
None,
"--prefix",
help="Object key prefix to download; repeat for multiple prefixes.",
),
db_only: bool = Option(
False,
"--db-only/--all-files",
help="Download only database files instead of all matching objects.",
),
skip_existing_non_db: bool = Option(
True,
"--skip-existing-non-db/--no-skip-existing-non-db",
help="Skip downloading when local non-DB files already exist.",
),
max_workers: int = Option(
DEFAULT_UPLOAD_WORKERS,
"--max-workers",
min=1,
help="Max parallel download workers.",
),
verbose: bool = Option(
False,
"--verbose",
"-v",
help="Enable verbose logging",
),
log_file: Path | None = Option(
None,
"--log-file",
help="Optional file path to write download logs.",
),
) -> None
Download selected object storage prefixes into local directories.
Source code in src/law_graph/cli.py
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 | |
storage_purge
storage_purge(
bucket: str | None = Option(
None,
"--bucket",
help="Target object storage bucket (env: LAW_GRAPH_S3_BUCKET).",
),
endpoint_url: str | None = Option(
None,
"--endpoint-url",
help="S3-compatible endpoint URL (env: LAW_GRAPH_S3_ENDPOINT_URL).",
),
region: str | None = Option(
None,
"--region",
help="Bucket region (env: LAW_GRAPH_S3_REGION).",
),
access_key_id: str | None = Option(
None,
"--access-key-id",
help="Access key ID (env: LAW_GRAPH_S3_ACCESS_KEY_ID).",
),
secret_access_key: str | None = Option(
None,
"--secret-access-key",
help="Secret access key (env: LAW_GRAPH_S3_SECRET_ACCESS_KEY).",
),
session_token: str | None = Option(
None,
"--session-token",
help="Session token (env: LAW_GRAPH_S3_SESSION_TOKEN).",
),
max_pool_connections: int | None = Option(
None,
"--max-pool-connections",
min=1,
help="Max S3 client connection pool size (env: LAW_GRAPH_S3_MAX_POOL_CONNECTIONS).",
),
prefixes: list[str] | None = Option(
None,
"--prefix",
help="Only delete keys under these prefixes; repeat for multiple prefixes.",
),
yes: bool = Option(
False,
"--yes",
help="Required confirmation flag to execute deletion.",
),
verbose: bool = Option(
False,
"--verbose",
"-v",
help="Enable verbose logging",
),
log_file: Path | None = Option(
None,
"--log-file",
help="Optional file path to write purge logs.",
),
) -> None
Delete all objects under selected prefixes in object storage.
Source code in src/law_graph/cli.py
773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 | |