StorageRegistry¶
The storage registry exposes the four production backends
(CSV, JSON, Parquet, DuckDB) plus the auto-detect open(uri)
convenience method. The backend is picked from the file extension;
the SDK round-trips CanonicalDataset byte-for-byte across all
four.
API reference¶
The full reference is generated from the SDK's docstrings via mkdocstrings.
StorageRegistry
¶
Registry mapping StorageBackend → Storage.
The SDK ships with five built-in registrations:
LOCAL_FILES→LocalFilesStorageJSON→JSONStorageCSV→CSVStoragePARQUET→ParquetStorageDUCKDB→DuckDBStorage
All five are placeholders that raise
NotImplementedError. Consumers can:
register(backend, storage)to install a concrete storage over a placeholder.get(backend)to look up the registered storage.
The registry is a plain object; callers can hold
their own registry and pass it to
StorageStage.
Source code in un_comtrade/storage/_base.py
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 668 669 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 771 772 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 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 | |
register
¶
Register (or replace) the storage for
backend.
Source code in un_comtrade/storage/_base.py
get
¶
Return the registered storage for backend.
Raises StorageError if no storage is
registered for the requested backend.
Source code in un_comtrade/storage/_base.py
supported_backends
¶
unregister
¶
Remove the storage for backend.
Raises StorageError if no storage is
registered.
Source code in un_comtrade/storage/_base.py
open
¶
open(
uri: str | "Path",
*,
table_name: str = "trade_records",
overwrite: bool = False,
compression: str = "none",
) -> "CanonicalDataset"
Load a :class:CanonicalDataset from a previously-
persisted file via the public Storage API.
The backend is auto-detected from the file extension
(.csv / .json / .parquet / .duckdb).
A directory path is supported (scanned for the first
known file type — the convention used by
:class:ParquetWriter).
Parameters¶
uri
Path to a stored dataset. The extension
determines the backend.
table_name
For DuckDB: the table to read from.
Default "trade_records".
overwrite
Forwarded to StorageConfig (currently unused
by reads).
compression
Forwarded to StorageConfig (currently unused
by reads).
Returns¶
CanonicalDataset The deserialised dataset.
Raises¶
StorageError
When uri does not exist, the extension is
unsupported, or the backend cannot read the file.
Source code in un_comtrade/storage/_base.py
Examples¶
from un_comtrade import ComtradeClient
with ComtradeClient() as client:
exports = client.trade.get_exports(reporter_code=699, period="2022")
client.storage.open("india_exports_2022.parquet").write(exports)
Related Recipes¶
- RECIPE-031 — ETL pipeline.
- RECIPE-032 — Export to CSV.
- RECIPE-033 — Export to Parquet.
- RECIPE-034 — Export to DuckDB.
Related Guides¶
- Python SDK → Storage — full Python API surface.