API Reference
Auto-generated API documentation from source code.
Module Functions
socials.parse(url)
Parse a single URL into a typed object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
URL to parse. |
required |
Returns:
| Type | Description |
|---|---|
SocialsURL | None
|
Parsed SocialsURL object, or None if not recognized. |
Examples:
result = socials.parse("https://github.com/lorey/socials")
result.platform # "github"
result.entity_type # "repo"
Source code in socials/__init__.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
socials.parse_all(urls)
Parse multiple URLs and return an Extraction result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
urls
|
list[str]
|
List of URLs to parse. |
required |
Returns:
| Type | Description |
|---|---|
Extraction
|
Extraction object with helper methods for grouping/filtering. |
Examples:
extraction = socials.parse_all(urls)
extraction.by_platform() # {"github": [...], "twitter": [...]}
Source code in socials/__init__.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
Classes
socials.Extractor
Extractor for parsing social URLs.
Source code in socials/extractor.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | |
parse(url)
Parse a single URL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
URL to parse. |
required |
Returns:
| Type | Description |
|---|---|
SocialsURL | None
|
Parsed SocialsURL object, or None if not recognized. |
Raises:
| Type | Description |
|---|---|
ParseError
|
If strict mode is enabled and URL is not recognized. |
Source code in socials/extractor.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
extract(urls)
Parse multiple URLs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
urls
|
list[str]
|
List of URLs to parse. |
required |
Returns:
| Type | Description |
|---|---|
Extraction
|
Extraction object containing parsed results. |
Source code in socials/extractor.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | |
socials.Extraction
Result of extracting social URLs from a list of URLs.
Source code in socials/extractor.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
all()
Return all parsed URLs.
Returns:
| Type | Description |
|---|---|
list[SocialsURL]
|
List of all SocialsURL objects. |
Source code in socials/extractor.py
30 31 32 33 34 35 36 37 | |
by_platform()
Group results by platform.
Returns:
| Type | Description |
|---|---|
dict[str, list[SocialsURL]]
|
Dictionary mapping platform names to lists of URLs. |
Source code in socials/extractor.py
39 40 41 42 43 44 45 46 47 48 49 | |
by_type()
Group results by entity type.
Returns:
| Type | Description |
|---|---|
dict[str, list[SocialsURL]]
|
Dictionary mapping entity types to lists of URLs. |
Source code in socials/extractor.py
51 52 53 54 55 56 57 58 59 60 61 | |
socials.registry.Registry
Registry that maps hostnames to platform parsers.
When multiple parsers could handle the same URL, the first registered parser takes priority. This is a "first match wins" policy.
Source code in socials/registry.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
parsers
property
Return list of registered parsers.
__init__(parsers=None)
Initialize registry with optional list of parsers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parsers
|
list[PlatformParser] | None
|
List of platform parsers to register. |
None
|
Source code in socials/registry.py
21 22 23 24 25 26 27 28 29 30 31 | |
get_parser_for_hostname(hostname)
Find the parser that handles the given hostname.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hostname
|
str
|
Hostname to find parser for. |
required |
Returns:
| Type | Description |
|---|---|
PlatformParser | None
|
Parser that handles the hostname, or None. |
Source code in socials/registry.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
get_parser_for_scheme(scheme)
Find the parser that handles the given URL scheme.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scheme
|
str
|
URL scheme to find parser for (e.g., 'mailto', 'tel'). |
required |
Returns:
| Type | Description |
|---|---|
PlatformParser | None
|
Parser that handles the scheme, or None. |
Source code in socials/registry.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
get_parser_for_url(url)
Find the parser that handles the given URL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
URL to find parser for. |
required |
Returns:
| Type | Description |
|---|---|
PlatformParser | None
|
Parser that handles the URL, or None. |
Source code in socials/registry.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
parse(url)
Parse a URL using the appropriate parser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
URL to parse. |
required |
Returns:
| Type | Description |
|---|---|
SocialsURL | None
|
Parsed URL object, or None if no parser handles it. |
Source code in socials/registry.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
register(parser)
Register a new parser.
If another parser already handles the same schemes, a warning is issued. The first registered parser takes priority (first match wins).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parser
|
PlatformParser
|
Parser to register. |
required |
Source code in socials/registry.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
Protocols
socials.protocols.SocialsURL
Bases: Protocol
Common interface all parsed URLs implement.
Source code in socials/protocols.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
entity_type
property
Entity type (e.g., 'profile', 'repo').
platform
property
Platform identifier (e.g., 'github', 'twitter').
url
property
Original URL string.
get_ancestors()
Return full chain from parent to root: [repo, profile].
Source code in socials/protocols.py
39 40 41 | |
get_parent()
Return immediate parent (issue → repo).
Source code in socials/protocols.py
31 32 33 | |
get_root()
Return top of hierarchy (issue → profile/org).
Source code in socials/protocols.py
35 36 37 | |
socials.protocols.PlatformParser
Bases: Protocol
Interface for platform-specific URL parsers.
Source code in socials/protocols.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
handles_hostname(hostname)
Check if this parser handles the given hostname.
Source code in socials/protocols.py
51 52 53 | |
parse(url)
Parse URL into typed object, or None if not recognized.
Source code in socials/protocols.py
55 56 57 | |
socials.protocols.ParseError
Bases: Exception
Raised when URL parsing fails (if strict mode enabled).
Source code in socials/protocols.py
8 9 | |
Platform URL Types
All URL types implement the SocialsURL protocol (see above) with get_parent(), get_root(), and get_ancestors() methods. Below are the platform-specific attributes for each type.
GitHub
socials.platforms.github.GitHubProfileURL
Bases: BaseModel
GitHub user or organization profile URL.
Source code in socials/platforms/github.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
socials.platforms.github.GitHubRepoURL
Bases: BaseModel
GitHub repository URL.
Source code in socials/platforms/github.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
socials.platforms.twitter.TwitterProfileURL
Bases: BaseModel
Twitter/X user profile URL.
Source code in socials/platforms/twitter.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
socials.platforms.linkedin.LinkedInProfileURL
Bases: BaseModel
LinkedIn personal profile URL.
Source code in socials/platforms/linkedin.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
socials.platforms.linkedin.LinkedInCompanyURL
Bases: BaseModel
LinkedIn company page URL.
Source code in socials/platforms/linkedin.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
socials.platforms.facebook.FacebookProfileURL
Bases: BaseModel
Facebook user or page profile URL.
Source code in socials/platforms/facebook.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
socials.platforms.instagram.InstagramProfileURL
Bases: BaseModel
Instagram user profile URL.
Source code in socials/platforms/instagram.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
YouTube
socials.platforms.youtube.YouTubeChannelURL
Bases: BaseModel
YouTube channel URL.
Source code in socials/platforms/youtube.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
Email and Phone
socials.platforms.misc.EmailURL
Bases: BaseModel
Email address (mailto: URL or plain email).
Source code in socials/platforms/misc.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
socials.platforms.misc.PhoneURL
Bases: BaseModel
Phone number (tel: URL).
Source code in socials/platforms/misc.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |