Constants¶
This page documents all constants and type aliases available in the social-links library. These are useful when defining custom platforms or working with platform configurations.
sociallinks.constants ¶
Constants and type aliases for the sociallinks library.
This module provides: - Type aliases for platform configuration structures - Common regex patterns for matching profile IDs and phone numbers
These constants are used internally by the SocialLinks class and can
also be imported for use in custom platform definitions.
PlatformEntry
module-attribute
¶
PlatformEntry = List[Dict[str, Any]]
Type alias for a platform configuration entry.
A platform entry is a list of dictionaries, where each dictionary contains platform configuration such as patterns and sanitized URL templates. A platform can have multiple configuration variants (e.g., different URL patterns for profiles vs. companies).
Each dictionary in the list should contain:
- patterns: A list of regex pattern strings that match URLs for this platform
- sanitized: A template string for the sanitized URL format
Note: Entries missing either patterns or sanitized will be skipped during
compilation. At least one complete entry (with both fields) is required for a
valid platform configuration.
Example
entry: PlatformEntry = [
{
"patterns": [r"https?://example.com/(?P<id>\w+)"],
"sanitized": "https://example.com/{id}"
}
]
PlatformEntries
module-attribute
¶
PlatformEntries = Dict[str, PlatformEntry]
Type alias for a collection of platform configurations.
A dictionary mapping platform names (strings) to their configuration entries.
This is the structure used internally by SocialLinks to store all
registered platforms.
Example
platforms: PlatformEntries = {
"example": [
{
"patterns": [r"https?://example.com/(?P<id>\w+)"],
"sanitized": "https://example.com/{id}"
}
],
"another": [
{
"patterns": [r"https?://another.com/user/(?P<id>\w+)"],
"sanitized": "https://another.com/user/{id}"
}
]
}
PROFILE_ID
module-attribute
¶
PROFILE_ID = '(?P<id>[A-Za-z0-9_.-]+)'
Standard profile ID regex pattern.
Matches alphanumeric characters, underscore, period, and hyphen.
Used for most social media platforms with standard username formats.
Example matches
john_doeuser123my.profileuser-name
PROFILE_ID_AT
module-attribute
¶
PROFILE_ID_AT = '(?P<id>@?[A-Za-z0-9_.-]+)'
Profile ID regex pattern with optional @ prefix.
Matches profile IDs that may optionally start with an @ symbol.
Commonly used for platforms like YouTube channels.
Example matches
@channelchannel@user_name
PROFILE_ID_UNICODE
module-attribute
¶
PROFILE_ID_UNICODE = "(?P<id>[\\w&%'–®\\.-]+)"
Profile ID regex pattern supporting Unicode characters.
Matches Unicode word characters (via \w, which includes Unicode letters
and digits in Python 3), plus special characters including:
- Ampersand (&)
- Percent (%)
- Apostrophe (')
- En dash (–)
- Registered trademark (®)
- Period (.)
- Hyphen (-)
Used for platforms like LinkedIn that support international characters.
Example matches
peter-müller-81a8user&coname's-profilejosé-garcía
PROFILE_ID_EXTENDED
module-attribute
¶
PROFILE_ID_EXTENDED = '(?P<id>-?[A-Za-z0-9_@=.\\-]+)'
Extended profile ID regex pattern with additional character support.
Supports:
- Optional leading hyphen (for Telegram groups, e.g., -123456789)
- @ symbol (for platforms like Flickr)
- Equals sign (for Douyin base64 encoded IDs)
- Period (.)
- Standard alphanumeric characters, underscore, and hyphen
Example matches
-123456789(Telegram group)@username(Flickr)base64==(Douyin)normal_user
PHONE_NUMBER
module-attribute
¶
PHONE_NUMBER = '(?P<id>\\+?[0-9]+)'
Phone number regex pattern.
Matches phone numbers that may optionally start with a + sign.
Primarily used for WhatsApp platform.
Example matches
+12345678901234567890+441234567890
NUMERIC_ID
module-attribute
¶
NUMERIC_ID = '(?P<id>\\d+)'
Numeric profile ID regex pattern.
Matches one or more digits. Used for platforms whose profile URLs carry a numeric account id (Goodreads, Pixiv, Roblox, Airbnb, ...).
Example matches
11741101
NOSTR_NPUB
module-attribute
¶
NOSTR_NPUB = '(?P<id>npub1[a-z0-9]{58})'
Nostr public key (NIP-19 npub) regex pattern.
Matches npub1 followed by 58 bech32 characters (63 characters in total).
Used for Primal profile URLs.
Example matches
npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6
ORCID_ID
module-attribute
¶
ORCID_ID = '(?P<id>\\d{4}-\\d{4}-\\d{4}-\\d{3}[\\dX])'
ORCID iD regex pattern.
Matches the 16-digit ORCID identifier in four hyphen-separated groups. The
last character is a checksum digit or X.
Example matches
0000-0002-1825-00970000-0002-1694-233X
HEX32_ID
module-attribute
¶
HEX32_ID = '(?P<id>[0-9a-fA-F]{32})'
32-character hexadecimal ID regex pattern.
Used for platforms with hashed account ids (Coursera profiles, CHZZK channels).
Example matches
85dca6cc1c1ccacdb8d6cbc3853c8eff