|
6 | 6 | Core metadata specifications |
7 | 7 | ============================ |
8 | 8 |
|
9 | | -This page describes version 2.4, approved in August 2024. |
| 9 | +This page describes version 2.5, approved in September 2025. |
10 | 10 |
|
11 | 11 | Fields defined in the following specification should be considered valid, |
12 | 12 | complete and not subject to change. The required fields are: |
@@ -50,7 +50,7 @@ Metadata-Version |
50 | 50 | .. versionadded:: 1.0 |
51 | 51 |
|
52 | 52 | Version of the file format; legal values are "1.0", "1.1", "1.2", "2.1", |
53 | | -"2.2", "2.3", and "2.4". |
| 53 | +"2.2", "2.3", "2.4", and "2.5". |
54 | 54 |
|
55 | 55 | Automated tools consuming metadata SHOULD warn if ``metadata_version`` is |
56 | 56 | greater than the highest version they support, and MUST fail if |
@@ -724,6 +724,101 @@ user SHOULD be warned and the value ignored to avoid ambiguity. Tools MAY choose |
724 | 724 | to raise an error when reading an invalid name for older metadata versions. |
725 | 725 |
|
726 | 726 |
|
| 727 | +.. _core-metadata-import-name: |
| 728 | + |
| 729 | +Import-Name (multiple use) |
| 730 | +========================== |
| 731 | + |
| 732 | +.. versionadded:: 2.5 |
| 733 | + |
| 734 | +A string containing an import name that the project exclusively provides when |
| 735 | +installed. The specified import name MUST be a valid Python identifier or can |
| 736 | +be empty. The import names listed in this field MUST be importable when the |
| 737 | +project is installed on *some* platform for the same version of the project. |
| 738 | +This implies that the metadata MUST be consistent across all sdists and wheels |
| 739 | +for a project release. |
| 740 | + |
| 741 | +An import name MAY be followed by a semicolon and the term "private" |
| 742 | +(e.g. ``; private``) with any amount of whitespace surrounding the semicolon. |
| 743 | +This signals to tools that the import name is not part of the public API for |
| 744 | +the project. |
| 745 | + |
| 746 | +Projects SHOULD list all the shortest import names that are exclusively provided |
| 747 | +by the project. If any of the shortest names are dotted names, all intervening |
| 748 | +names from that name to the top-level name should also be listed appropriately |
| 749 | +in ``Import-Name`` and/or ``Import-Namespace``. |
| 750 | + |
| 751 | +If a project lists the same name in both ``Import-Name`` and |
| 752 | +``Import-Namespace``, tools MUST raise an error due to ambiguity. |
| 753 | + |
| 754 | +Tools SHOULD raise an error when two projects that are about to be installed |
| 755 | +list names that overlap in each other's ``Import-Name`` entries, or when a |
| 756 | +project has an entry in ``Import-Name`` that overlaps with another project's |
| 757 | +``Import-Namespace`` entries. This is to avoid projects unexpectedly shadowing |
| 758 | +another project's code. Tools MAY warn or raise an error when installing a |
| 759 | +project into a preexisting environment where there is import name overlap with |
| 760 | +a project that is already installed. |
| 761 | + |
| 762 | +Projects MAY have an empty ``Import-Name`` field in their metadata to represent |
| 763 | +a project with no import names (i.e. there are no Python modules of any kind in |
| 764 | +the distribution file). |
| 765 | + |
| 766 | +Since projects MAY have no ``Import-Name`` metadata (either because the |
| 767 | +project uses an older metadata version, or because it didn't specify any), then |
| 768 | +tools have no information about what names the project provides. However, in |
| 769 | +practice the majority of projects have their project name match what their |
| 770 | +import name would be. As such, it is a reasonable assumption to make that a |
| 771 | +project name that is normalized in some way to an import name |
| 772 | +(e.g. ``packaging.utils.canonicalize_name(name, validate=True).replace("-", "_")``) |
| 773 | +can be used if some answer is needed. |
| 774 | + |
| 775 | +Examples:: |
| 776 | + |
| 777 | + Import-Name: PIL |
| 778 | + Import-Name: _private_module ; private |
| 779 | + Import-Name: zope.interface |
| 780 | + Import-Name: |
| 781 | + |
| 782 | + |
| 783 | +.. _core-metadata-import-namespace: |
| 784 | + |
| 785 | +Import-Namespace (multiple use) |
| 786 | +=============================== |
| 787 | + |
| 788 | +.. versionadded:: 2.5 |
| 789 | + |
| 790 | +A string containing an import name that the project provides when installed, but |
| 791 | +not exclusively. The specified import name MUST be a valid Python identifier. |
| 792 | +This field is used for namespace packages where multiple projects can contribute |
| 793 | +to the same import namespace. Projects all listing the same import name in |
| 794 | +``Import-Namespace`` can be installed together without shadowing each other. |
| 795 | + |
| 796 | +An import name MAY be followed by a semicolon and the term "private" (e.g. |
| 797 | +``; private``) with any amount of whitespace surrounding the semicolon. This |
| 798 | +signals to tools that the import name is not part of the public API for the |
| 799 | +project. |
| 800 | + |
| 801 | +Projects SHOULD list all the shortest import names that are exclusively provided |
| 802 | +by the project. If any of the shortest names are dotted names, all intervening |
| 803 | +names from that name to the top-level name should also be listed appropriately |
| 804 | +in ``Import-Name`` and/or ``Import-Namespace``. |
| 805 | + |
| 806 | +The import names listed in this field MUST be importable when the project is |
| 807 | +installed on *some* platform for the same version of the project. This implies |
| 808 | +that the metadata MUST be consistent across all sdists and wheels for a project |
| 809 | +release. |
| 810 | + |
| 811 | +If a project lists the same name in both ``Import-Name`` and |
| 812 | +``Import-Namespace``, tools MUST raise an error due to ambiguity. |
| 813 | + |
| 814 | +Note that ``Import-Namespace`` CANNOT be empty like ``Import-Name``. |
| 815 | + |
| 816 | +Examples:: |
| 817 | + |
| 818 | + Import-Namespace: zope |
| 819 | + Import-Name: _private_module ; private |
| 820 | + |
| 821 | + |
727 | 822 | Rarely Used Fields |
728 | 823 | ================== |
729 | 824 |
|
@@ -939,37 +1034,42 @@ Example:: |
939 | 1034 | History |
940 | 1035 | ======= |
941 | 1036 |
|
942 | | -- October 2025: Clarified that ``License-Expression`` applies to the containing |
943 | | - distribution file and not the project itself. |
944 | | - |
945 | | -- August 2025: Clarified that ``Dynamic`` only affects how fields |
946 | | - must be treated when building a wheel from a sdist, not when modifying |
947 | | - a wheel. |
| 1037 | +- March 2001: Core metadata 1.0 was approved through :pep:`241`. |
948 | 1038 |
|
949 | | -- August 2024: Core metadata 2.4 was approved through :pep:`639`. |
| 1039 | +- April 2003: Core metadata 1.1 was approved through :pep:`314`. |
950 | 1040 |
|
951 | | - - Added the ``License-Expression`` field. |
952 | | - - Added the ``License-File`` field. |
| 1041 | +- February 2010: Core metadata 1.2 was approved through :pep:`345`. |
953 | 1042 |
|
954 | | -- March 2022: Core metadata 2.3 was approved through :pep:`685`. |
| 1043 | +- February 2018: Core metadata 2.1 was approved through :pep:`566`. |
955 | 1044 |
|
956 | | - - Restricted extra names to be normalized. |
| 1045 | + - Added ``Description-Content-Type`` and ``Provides-Extra``. |
| 1046 | + - Added canonical method for transforming metadata to JSON. |
| 1047 | + - Restricted the grammar of the ``Name`` field. |
957 | 1048 |
|
958 | 1049 | - October 2020: Core metadata 2.2 was approved through :pep:`643`. |
959 | 1050 |
|
960 | 1051 | - Added the ``Dynamic`` field. |
961 | 1052 |
|
962 | | -- February 2018: Core metadata 2.1 was approved through :pep:`566`. |
| 1053 | +- March 2022: Core metadata 2.3 was approved through :pep:`685`. |
963 | 1054 |
|
964 | | - - Added ``Description-Content-Type`` and ``Provides-Extra``. |
965 | | - - Added canonical method for transforming metadata to JSON. |
966 | | - - Restricted the grammar of the ``Name`` field. |
| 1055 | + - Restricted extra names to be normalized. |
967 | 1056 |
|
968 | | -- February 2010: Core metadata 1.2 was approved through :pep:`345`. |
| 1057 | +- August 2024: Core metadata 2.4 was approved through :pep:`639`. |
969 | 1058 |
|
970 | | -- April 2003: Core metadata 1.1 was approved through :pep:`314`: |
| 1059 | + - Added the ``License-Expression`` field. |
| 1060 | + - Added the ``License-File`` field. |
971 | 1061 |
|
972 | | -- March 2001: Core metadata 1.0 was approved through :pep:`241`. |
| 1062 | +- August 2025: Clarified that ``Dynamic`` only affects how fields |
| 1063 | + must be treated when building a wheel from a sdist, not when modifying |
| 1064 | + a wheel. |
| 1065 | + |
| 1066 | +- September 2025: Core metadata 2.5 was approved through :pep:`794`. |
| 1067 | + |
| 1068 | + - Added the ``Import-Name`` field. |
| 1069 | + - Added the ``Import-Namespace`` field. |
| 1070 | + |
| 1071 | +- October 2025: Clarified that ``License-Expression`` applies to the containing |
| 1072 | + distribution file and not the project itself. |
973 | 1073 |
|
974 | 1074 | ---- |
975 | 1075 |
|
|
0 commit comments