Files
py-libp2p/libp2p/utils/version.py
acul71 18c6f529c6 Feat/issue 605 debug logging via env variable (#608)
* feat: Debug Logging via Environment Variable

* refactor: deleted libp2p/utils.py

* fix: double messages logging fix

* doc: add logging info to getting_started.rst
2025-05-20 14:07:22 -06:00

23 lines
525 B
Python

from importlib.metadata import (
version,
)
import logging
logger = logging.getLogger("libp2p.utils.version")
def get_agent_version() -> str:
"""
Return the version of libp2p.
If the version cannot be determined due to an exception, return "py-libp2p/unknown".
:return: The version of libp2p.
:rtype: str
"""
try:
return f"py-libp2p/{version('libp2p')}"
except Exception as e:
logger.warning("Could not fetch libp2p version: %s", e)
return "py-libp2p/unknown"