Extract Obsidian-style wikilink targets from text
Project description
obsilink
obsilink is a small, deterministic Python library for extracting links from Markdown text.
It supports:
- Obsidian wikilinks like
[[Note]],[[Note|Alias]], and![[Embedded]] - Markdown links like
[Docs](https://example.com)and embeds like - Plain URLs like
https://example.com,ftp://files.example.com, andmailto:user@example.com
The parser returns structured Link objects in encounter order and preserves duplicates.
Features
- Deterministic parsing with stable ordering
- One public extraction function:
extract_links(...) - Accepts either raw
stror file-like input with.read() - Preserves duplicates instead of deduplicating
- Strict, typed API compatible with
mypystrict mode
Installation
With uv (recommended)
uv add obsilink
With pip
pip install obsilink
From source
git clone https://github.com/chgroeling/obsilink.git
cd obsilink
uv sync
If the package is not yet published to your package index, use the source install method.
Quick start
from obsilink import extract_links
text = """
See [[Project/Plan#Milestones|Roadmap]],
,
and https://example.com.
"""
links = extract_links(text)
for link in links:
print(link.type.value, link.target, link.alias)
More complex Obsidian wikilink example
from obsilink import extract_links
text = """
[[Project/Plan#Milestones|Roadmap]]
![[Assets/Diagrams/System Overview#v2]]
[[People/Ada Lovelace#Biography^early-life|Ada]]
[[Project/Plan#Milestones|Roadmap]]
[[Malformed
"""
links = extract_links(text)
for link in links:
print(
link.type.value,
link.target,
link.alias,
link.heading,
link.blockid,
)
# Encounter order is preserved, duplicates are kept, and malformed
# wikilinks (like "[[Malformed") are ignored.
API
extract_links(source)
Extracts links from:
str- text file-like object with
.read()returningstr
Returns:
list[Link]in encounter order
Raises:
TypeErrorfor unsupported source typesTypeErrorif.read()returns non-string data- Any exception raised by
.read()is propagated
Link
Link is a frozen dataclass with these fields:
type: LinkTypetarget: stralias: str | Noneheading: str | Noneblockid: str | None
Convenience properties:
link.is_url->Truefor URL targets (http,https,ftp,file,mailto)link.as_path->pathlib.Pathfor non-URL targets (raisesValueErrorfor URLs)
Supported link types
LinkType.WIKILINKLinkType.WIKILINK_EMBEDLinkType.MARKDOWN_LINKLinkType.MARKDOWN_EMBEDLinkType.PLAIN_URL
Development
This project uses uv, ruff, mypy, and pytest.
uv sync
uv run ruff format src/ tests/
uv run ruff check src/ tests/
uv run mypy src/
uv run pytest
License
This project is licensed under the MIT License. See LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file obsilink-0.3.0.tar.gz.
File metadata
- Download URL: obsilink-0.3.0.tar.gz
- Upload date:
- Size: 24.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6680a66ee2b61b990ec10e6910548ca7458b0f90cace804f764ecd175ef029c8
|
|
| MD5 |
345b15e12b53db4bf9ffa237ab9fd14f
|
|
| BLAKE2b-256 |
34a0d6e34687b388333e3d43e9b0c1211f6eece3a283ac31d41dc9b180e667d2
|
Provenance
The following attestation bundles were made for obsilink-0.3.0.tar.gz:
Publisher:
publish.yml on chgroeling/obsilink
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
obsilink-0.3.0.tar.gz -
Subject digest:
6680a66ee2b61b990ec10e6910548ca7458b0f90cace804f764ecd175ef029c8 - Sigstore transparency entry: 1238622367
- Sigstore integration time:
-
Permalink:
chgroeling/obsilink@7710d9e8045778da2cef5b098a8c089b7b1c47f1 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/chgroeling
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7710d9e8045778da2cef5b098a8c089b7b1c47f1 -
Trigger Event:
push
-
Statement type:
File details
Details for the file obsilink-0.3.0-py3-none-any.whl.
File metadata
- Download URL: obsilink-0.3.0-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ebf09f94953e2e706a2ccb2c85ba6cd198c891e416ae12af16bd3fd7b3c1911
|
|
| MD5 |
860c707e2f4bb9b71b8f91c4a217b12a
|
|
| BLAKE2b-256 |
097f856b8326fc1f90c358bc527cd435fe6bb9098032b1bc524c3b2618ef448a
|
Provenance
The following attestation bundles were made for obsilink-0.3.0-py3-none-any.whl:
Publisher:
publish.yml on chgroeling/obsilink
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
obsilink-0.3.0-py3-none-any.whl -
Subject digest:
4ebf09f94953e2e706a2ccb2c85ba6cd198c891e416ae12af16bd3fd7b3c1911 - Sigstore transparency entry: 1238622368
- Sigstore integration time:
-
Permalink:
chgroeling/obsilink@7710d9e8045778da2cef5b098a8c089b7b1c47f1 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/chgroeling
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7710d9e8045778da2cef5b098a8c089b7b1c47f1 -
Trigger Event:
push
-
Statement type: