Skip to main content

A custom pkg_resources to importlib.resources/metadata migration helper.

Project description

A pkg_resources to importlib.resources and importlib.metadata migration helper.

About

packagedata is a migration helper library designed to ease the transition from the deprecated pkg_resources API to the modern importlib.resources and importlib.metadata APIs.

The pkg_resources package was deprecated in setuptools 67.5.0 (05 Mar 2023) and removed on setuptools 82.0.0 (8 Feb 2026). This library provides a replacement specially tailored for maintainers of packages that fall in an impossible position of needing to support both older Python versions while migrating to the new APIs.

If you are maintaining for Python >=3.9, please use the standard library importlib.resources. If you need entry points and maintaining for Python >=3.12, please use importlib.metadata directly. If you don’t fall in those categories this library may help you migrate and maintain your code.

So, to reiterate: if you are maintaining for a modern Python version (>=3.7), this package is not for you.

Installation

pip install packagedata

The package automatically handles the installation of required backports for older Python versions:

  • importlib-resources for Python < 3.9

  • importlib-metadata for Python < 3.9

Migration Guide

Reading Text Files

Change:

from pkg_resources import resource_string
text = resource_string(__package__, 'data/README.txt').decode('utf-8')

To:

import packagedata as pkgdata
text = pkgdata.read_text(__package__, 'data/README.txt', encoding='utf-8')

Then, eventually, when you can, change it to:

from importlib import resources
text = resources.read_text(__package__, 'data/README.txt', encoding='utf-8')

Reading Binary Files

Change:

from pkg_resources import resource_string
data = resource_string(__package__, 'assets/icon.ico')

To:

import packagedata as pkgdata
data = pkgdata.read_bytes(__package__, 'assets/icon.ico')

Then, eventually, when you can, change it to:

from importlib import resources
data = resources.read_binary(__package__, 'assets/icon.ico')

Getting File Paths

Change:

import os
import os.path
from pkg_resources import resource_filename
templates_path = resource_filename(__package__, 'templates')
for filename in os.listdir(templates_path):
    filepath = os.path.join(templates_path, filename)
    print(filepath)

To:

import packagedata as pkgdata
with pkgdata.as_path(__package__, 'templates') as templates_path:
    for filepath in templates_path.iterdir():
        print(filepath)

Then, eventually, when you can, change it to:

from importlib import resources
with resources.as_file(
    resources.files(__package__).joinpath('templates')
) as templates_path:
    for filepath in templates_path.iterdir():
        print(filepath)

Entry Points

Change:

from pkg_resources import iter_entry_points
for ep in iter_entry_points('my_entry_point_group'):
    print(f"{ep.name}: {ep.module_name}:{ep.attrs}")
    plugin = ep.load()

To:

import packagedata as pkgdata
for ep in pkgdata.entry_points('my_entry_point_group'):
    print(f"{ep.name}: {ep.value}")
    plugin = ep.load()

Then, eventually, when you can, change it to:

from importlib import metadata
for ep in metadata.entry_points().select(group='my_entry_point_group'):
    print(f"{ep.name}: {ep.value}")
    plugin = ep.load()

Note on compatibility:

The packagedata.entry_points() function handles API differences between Python versions:

  • Python 3.10+: Uses the new EntryPoints.select() method.

  • Python 3.7-3.9: Uses the legacy dict-like interface.

So while no “selectable” entry points are exposed, the same code works across all supported Python versions and mimics the pkg_resources behavior.

License

Copyright (C) 2025 KuraLabs S.R.L

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

packagedata-1.2.0.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

packagedata-1.2.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file packagedata-1.2.0.tar.gz.

File metadata

  • Download URL: packagedata-1.2.0.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for packagedata-1.2.0.tar.gz
Algorithm Hash digest
SHA256 8c56fa7d9fcf4b352e969ab43ede22fbc9a196d4079a937a7c1b1f0284280c96
MD5 07ee246acf83fddce465a11b591309fb
BLAKE2b-256 273d15857e2a15fd7163ff2ae802eeb0dfc21c90327c7b0e231196a1826e01cd

See more details on using hashes here.

File details

Details for the file packagedata-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: packagedata-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for packagedata-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8808abf54f0a26ce5e4e08107c437b6789fe104919fb9ee13f4ccc364163f375
MD5 caf6f7c1322aa61f1a64c014a28345f8
BLAKE2b-256 00f5bc1e08ed09f7a26974f9d1646dd2e814323a8c794365f406efbad719f2a7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page