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