API Reference - Core¶
instapay_eg.core
¶
Core parsing and building utilities for Egyptian InstaPay links.
InstaPayData
dataclass
¶
Immutable, validated snapshot of an InstaPay payment link.
All fields are guaranteed to be consistent with each other - you will
never receive a handle that does not match the link.
Attributes:
| Name | Type | Description |
|---|---|---|
link |
str
|
The fully validated |
handle |
str
|
The raw handle string extracted from the URL (e.g. |
formatted_handle |
str
|
The |
raw_url_id |
str
|
The short server-generated token at the end of the URL
(e.g. |
is_verified |
bool
|
Always |
Example
data = parse_text( ... "https://ipn.eg/S/alice/instapay/ABC123\n" ... "Click to send money\nalice@instapay\nPowered by InstaPay" ... ) data.link 'https://ipn.eg/S/alice/instapay/ABC123' data.handle 'alice' data.formatted_handle 'alice@instapay' data.raw_url_id 'ABC123' data.is_verified True
Source code in src/instapay_eg/core.py
parse_text
¶
Parse raw share-sheet text and return a fully validated :class:InstaPayData.
This is the primary entry point of the SDK. Pass in the text that the user copied from the InstaPay app share sheet and receive a clean, safe, validated data object.
The function will:
- Extract the first
https://ipn.egURL from the text. - Run all security checks (HTTPS, exact domain, injection detection, phishing pattern matching).
- Extract and validate the handle.
- Return a frozen :class:
InstaPayDatainstance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Any string that may contain an InstaPay share link, such as the multi-line text copied from the InstaPay mobile app. |
required |
Returns:
| Type | Description |
|---|---|
InstaPayData
|
A validated, immutable :class: |
Raises:
| Type | Description |
|---|---|
LinkNotFoundError
|
If no |
PhishingLinkError
|
If the URL's domain matches a phishing pattern. |
InvalidHandleError
|
If the handle extracted from the URL is malformed. |
Example
data = parse_text( ... "https://ipn.eg/S/alice/instapay/2DcFGv\n" ... "Click the link to send money to\n" ... "alice@instapay\nPowered by InstaPay" ... ) data.handle 'alice' data.is_verified True
Source code in src/instapay_eg/core.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 | |
extract_link
¶
Extract the first valid https://ipn.eg URL from a block of text.
This is the low-level extraction primitive. It does not perform any
security checks. Use :func:parse_text for a fully validated result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Any string, including multi-line share-sheet text pasted directly from the InstaPay mobile app. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The first |
str | None
|
URL is present. |
Example
extract_link( ... "https://ipn.eg/S/mohamed/instapay/2DcFGv\n" ... "Click the link to send money to\n" ... "mohamed@instapay\nPowered by InstaPay" ... ) 'https://ipn.eg/S/mohamed/instapay/2DcFGv'
Source code in src/instapay_eg/core.py
extract_handle
¶
Extract the handle from an InstaPay payment URL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
link
|
str
|
A full |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The handle string (e.g. |
str | None
|
not contain the expected |
Example
extract_handle("https://ipn.eg/S/mohamed/instapay/2DcFGv") 'mohamed'
Source code in src/instapay_eg/core.py
extract_url_id
¶
Extract the short unique token from the end of an InstaPay URL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
link
|
str
|
A full |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The token string (e.g. |
Example
extract_url_id("https://ipn.eg/S/mohamed/instapay/2DcFGv") '2DcFGv'
Source code in src/instapay_eg/core.py
is_valid_handle
¶
Return True if handle meets InstaPay's character constraints.
The @instapay suffix is stripped automatically before validation, so
both 'alice' and 'alice@instapay' are accepted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handle
|
str
|
The handle string to validate. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
bool
|
characters (letters, digits, underscores, hyphens, dots). |
Example
is_valid_handle("alice") True is_valid_handle("alice@instapay") True is_valid_handle("alice!!!") False
Source code in src/instapay_eg/core.py
normalize_handle
¶
Strip the @instapay suffix and normalise whitespace.
This does not validate the handle - call :func:is_valid_handle
afterwards if you need validation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handle
|
str
|
A raw handle string, optionally including the |
required |
Returns:
| Type | Description |
|---|---|
str
|
The cleaned handle, with the suffix removed and whitespace stripped. |
str
|
Does not lowercase, because InstaPay handles are case-sensitive |
str
|
on the platform. |
Example
normalize_handle(" Alice@instapay ") 'Alice'