Skip to content

Utils

pgraf.utils

current_timestamp()

Return the current timestamp

Source code in pgraf/utils.py
def current_timestamp() -> datetime.datetime:
    """Return the current timestamp"""
    return datetime.datetime.now(tz=datetime.UTC)

sanitize(url)

Mask passwords in URLs for security.

Parameters:

Name Type Description Default
url str | AnyUrl | PostgresDsn

Input string that may contain URLs with passwords

required

Returns:

Type Description
str

Text with passwords in URLs replaced with asterisks

Source code in pgraf/utils.py
def sanitize(url: str | pydantic.AnyUrl | pydantic.PostgresDsn) -> str:
    """Mask passwords in URLs for security.

    Args:
        url: Input string that may contain URLs with passwords

    Returns:
        Text with passwords in URLs replaced with asterisks

    """
    pattern = re.compile(r'(\w+?://[^:@]+:)([^@]+)(@)')
    return pattern.sub(r'\1******\3', str(url))

uuidv7()

Return a UUIDv7 value as a UUID object

Source code in pgraf/utils.py
def uuidv7() -> uuid.UUID:
    """Return a UUIDv7 value as a UUID object"""
    return uuid.UUID(str(uuid_utils.uuid7()))