obsilink 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,207 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ #uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+ #poetry.toml
110
+
111
+ # pdm
112
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
114
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
115
+ #pdm.lock
116
+ #pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # pixi
121
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
122
+ #pixi.lock
123
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
124
+ # in the .venv directory. It is recommended not to include this directory in version control.
125
+ .pixi
126
+
127
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
128
+ __pypackages__/
129
+
130
+ # Celery stuff
131
+ celerybeat-schedule
132
+ celerybeat.pid
133
+
134
+ # SageMath parsed files
135
+ *.sage.py
136
+
137
+ # Environments
138
+ .env
139
+ .envrc
140
+ .venv
141
+ env/
142
+ venv/
143
+ ENV/
144
+ env.bak/
145
+ venv.bak/
146
+
147
+ # Spyder project settings
148
+ .spyderproject
149
+ .spyproject
150
+
151
+ # Rope project settings
152
+ .ropeproject
153
+
154
+ # mkdocs documentation
155
+ /site
156
+
157
+ # mypy
158
+ .mypy_cache/
159
+ .dmypy.json
160
+ dmypy.json
161
+
162
+ # Pyre type checker
163
+ .pyre/
164
+
165
+ # pytype static type analyzer
166
+ .pytype/
167
+
168
+ # Cython debug symbols
169
+ cython_debug/
170
+
171
+ # PyCharm
172
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
173
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
174
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
175
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
176
+ #.idea/
177
+
178
+ # Abstra
179
+ # Abstra is an AI-powered process automation framework.
180
+ # Ignore directories containing user credentials, local state, and settings.
181
+ # Learn more at https://abstra.io/docs
182
+ .abstra/
183
+
184
+ # Visual Studio Code
185
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
186
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
187
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
188
+ # you could uncomment the following to ignore the entire vscode folder
189
+ # .vscode/
190
+
191
+ # Ruff stuff:
192
+ .ruff_cache/
193
+
194
+ # PyPI configuration file
195
+ .pypirc
196
+
197
+ # Cursor
198
+ # Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
199
+ # exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
200
+ # refer to https://docs.cursor.com/context/ignore-files
201
+ .cursorignore
202
+ .cursorindexingignore
203
+
204
+ # Marimo
205
+ marimo/_static/
206
+ marimo/_lsp/
207
+ __marimo__/
@@ -0,0 +1,67 @@
1
+ # AGENTS.md
2
+
3
+ ## Project description
4
+ This project provides a small, deterministic Python library that extracts Obsidian-style
5
+ wikilink targets from input text.
6
+
7
+ ## Core behavior
8
+ - Parse Obsidian links such as `[[Note]]`, `[[Note|Alias]]`, and `[[Folder/Note#Heading]]`.
9
+ - Accept input as either:
10
+ - `str`
11
+ - a text file-like object with a `.read()` method that returns `str`
12
+ - Return `list[str]` in encounter order.
13
+ - Preserve duplicates.
14
+ - Ignore malformed or partial wikilink syntax.
15
+ - Include embed targets (for example `![[Note]]`) by default.
16
+ - Raise `TypeError` for unsupported input types.
17
+ - Propagate exceptions raised by `.read()`.
18
+ - Raise `TypeError` if `.read()` returns non-string data.
19
+
20
+ ## Scope boundaries
21
+ - This repository is extraction/parsing only.
22
+ - Do not add filesystem resolution features (depth traversal, basename/path searching).
23
+ - Do not add CLI/machine-output formatting concerns.
24
+ - Do not rely on environment variables such as `PROJECT_DIR` in parser code.
25
+
26
+ ## API guidelines
27
+ - Keep the public API small and predictable.
28
+ - Main entry point:
29
+ - `extract_obsidian_links(source: str | TextIO) -> list[str]`
30
+ - Optional extension point (if needed): `include_embeds: bool = True`.
31
+ - Validate input types and provide clear error messages.
32
+
33
+ ## Non-goals
34
+ Do not implement the following in this library:
35
+ - recursive graph traversal (`depth`, BFS/DFS)
36
+ - file discovery by basename/path
37
+ - path escaping for shell/xargs
38
+ - CLI machine-output payloads
39
+ - `PROJECT_DIR` or other environment-based resolution
40
+
41
+ ## Development workflows
42
+
43
+ ### Environment and dependencies
44
+ - Sync: `uv sync`
45
+ - Update lockfile: `uv lock --upgrade`
46
+ - Add/remove packages: `uv add <pkg>`, `uv remove <pkg>`
47
+
48
+ ### QA checks
49
+ Prefix commands with `uv run`.
50
+ - Format: `ruff format src/ tests/`
51
+ - Lint: `ruff check src/ tests/`
52
+ - Types: `mypy src/`
53
+ - Tests: `pytest`
54
+ - Full gate:
55
+ `uv run ruff format src/ tests/ && uv run ruff check src/ tests/ && uv run mypy src/ && uv run pytest`
56
+
57
+ ### Standards
58
+ - Follow SemVer (`MAJOR.MINOR.PATCH`).
59
+ - Use Conventional Commits (`feat:`, `fix:`, `chore:`, etc.).
60
+ - Never commit autonomously; only commit when explicitly requested.
61
+
62
+ ## Coding standards
63
+ - Keep behavior deterministic and side-effect free.
64
+ - Use strict typing for `src/` and maintain `mypy` compatibility.
65
+ - Keep line length at 100 characters (`ruff` configuration).
66
+ - Prefer testing through the public API; avoid testing private symbols.
67
+ - Keep imports at module top level (no inline imports in tests).
obsilink-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Christian Gröling
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,88 @@
1
+ Metadata-Version: 2.4
2
+ Name: obsilink
3
+ Version: 0.1.0
4
+ Summary: Extract Obsidian-style wikilink targets from text
5
+ Project-URL: Homepage, https://github.com/chgroeling/obsilink
6
+ Project-URL: Repository, https://github.com/chgroeling/obsilink
7
+ Project-URL: Issues, https://github.com/chgroeling/obsilink/issues
8
+ License-File: LICENSE
9
+ Keywords: markdown,obsidian,parser,text-processing,wikilink
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
18
+ Classifier: Topic :: Text Processing
19
+ Requires-Python: >=3.12
20
+ Description-Content-Type: text/markdown
21
+
22
+ # AGENTS.md
23
+
24
+ ## Project description
25
+ This project provides a small, deterministic Python library that extracts Obsidian-style
26
+ wikilink targets from input text.
27
+
28
+ ## Core behavior
29
+ - Parse Obsidian links such as `[[Note]]`, `[[Note|Alias]]`, and `[[Folder/Note#Heading]]`.
30
+ - Accept input as either:
31
+ - `str`
32
+ - a text file-like object with a `.read()` method that returns `str`
33
+ - Return `list[str]` in encounter order.
34
+ - Preserve duplicates.
35
+ - Ignore malformed or partial wikilink syntax.
36
+ - Include embed targets (for example `![[Note]]`) by default.
37
+ - Raise `TypeError` for unsupported input types.
38
+ - Propagate exceptions raised by `.read()`.
39
+ - Raise `TypeError` if `.read()` returns non-string data.
40
+
41
+ ## Scope boundaries
42
+ - This repository is extraction/parsing only.
43
+ - Do not add filesystem resolution features (depth traversal, basename/path searching).
44
+ - Do not add CLI/machine-output formatting concerns.
45
+ - Do not rely on environment variables such as `PROJECT_DIR` in parser code.
46
+
47
+ ## API guidelines
48
+ - Keep the public API small and predictable.
49
+ - Main entry point:
50
+ - `extract_obsidian_links(source: str | TextIO) -> list[str]`
51
+ - Optional extension point (if needed): `include_embeds: bool = True`.
52
+ - Validate input types and provide clear error messages.
53
+
54
+ ## Non-goals
55
+ Do not implement the following in this library:
56
+ - recursive graph traversal (`depth`, BFS/DFS)
57
+ - file discovery by basename/path
58
+ - path escaping for shell/xargs
59
+ - CLI machine-output payloads
60
+ - `PROJECT_DIR` or other environment-based resolution
61
+
62
+ ## Development workflows
63
+
64
+ ### Environment and dependencies
65
+ - Sync: `uv sync`
66
+ - Update lockfile: `uv lock --upgrade`
67
+ - Add/remove packages: `uv add <pkg>`, `uv remove <pkg>`
68
+
69
+ ### QA checks
70
+ Prefix commands with `uv run`.
71
+ - Format: `ruff format src/ tests/`
72
+ - Lint: `ruff check src/ tests/`
73
+ - Types: `mypy src/`
74
+ - Tests: `pytest`
75
+ - Full gate:
76
+ `uv run ruff format src/ tests/ && uv run ruff check src/ tests/ && uv run mypy src/ && uv run pytest`
77
+
78
+ ### Standards
79
+ - Follow SemVer (`MAJOR.MINOR.PATCH`).
80
+ - Use Conventional Commits (`feat:`, `fix:`, `chore:`, etc.).
81
+ - Never commit autonomously; only commit when explicitly requested.
82
+
83
+ ## Coding standards
84
+ - Keep behavior deterministic and side-effect free.
85
+ - Use strict typing for `src/` and maintain `mypy` compatibility.
86
+ - Keep line length at 100 characters (`ruff` configuration).
87
+ - Prefer testing through the public API; avoid testing private symbols.
88
+ - Keep imports at module top level (no inline imports in tests).
@@ -0,0 +1,150 @@
1
+ # obsilink
2
+
3
+ [![PyPI](https://img.shields.io/pypi/v/obsilink?logo=pypi)](https://pypi.org/project/obsilink/)
4
+ [![Python](https://img.shields.io/pypi/pyversions/obsilink?logo=python)](https://pypi.org/project/obsilink/)
5
+ [![License](https://img.shields.io/pypi/l/obsilink?logo=法律)](LICENSE)
6
+
7
+ `obsilink` is a small, deterministic Python library for extracting links from Markdown text.
8
+
9
+ It supports:
10
+
11
+ - Obsidian wikilinks like `[[Note]]`, `[[Note|Alias]]`, and `![[Embedded]]`
12
+ - Markdown links like `[Docs](https://example.com)` and embeds like `![Logo](logo.png)`
13
+ - Plain URLs like `https://example.com`, `ftp://files.example.com`, and `mailto:user@example.com`
14
+
15
+ The parser returns structured `Link` objects in encounter order and preserves duplicates.
16
+
17
+ ## Features
18
+
19
+ - Deterministic parsing with stable ordering
20
+ - One public extraction function: `extract_links(...)`
21
+ - Accepts either raw `str` or file-like input with `.read()`
22
+ - Preserves duplicates instead of deduplicating
23
+ - Strict, typed API compatible with `mypy` strict mode
24
+
25
+ ## Installation
26
+
27
+ ### With uv (recommended)
28
+
29
+ ```bash
30
+ uv add obsilink
31
+ ```
32
+
33
+ ### With pip
34
+
35
+ ```bash
36
+ pip install obsilink
37
+ ```
38
+
39
+ ### From source
40
+
41
+ ```bash
42
+ git clone https://github.com/chgroeling/obsilink.git
43
+ cd obsilink
44
+ uv sync
45
+ ```
46
+
47
+ If the package is not yet published to your package index, use the source install method.
48
+
49
+ ## Quick start
50
+
51
+ ```python
52
+ from obsilink import extract_links
53
+
54
+ text = """
55
+ See [[Project/Plan#Milestones|Roadmap]],
56
+ ![Logo](assets/logo.png),
57
+ and https://example.com.
58
+ """
59
+
60
+ links = extract_links(text)
61
+
62
+ for link in links:
63
+ print(link.type.value, link.target, link.alias)
64
+ ```
65
+
66
+ ### More complex Obsidian wikilink example
67
+
68
+ ```python
69
+ from obsilink import extract_links
70
+
71
+ text = """
72
+ [[Project/Plan#Milestones|Roadmap]]
73
+ ![[Assets/Diagrams/System Overview#v2]]
74
+ [[People/Ada Lovelace#Biography^early-life|Ada]]
75
+ [[Project/Plan#Milestones|Roadmap]]
76
+ [[Malformed
77
+ """
78
+
79
+ links = extract_links(text)
80
+
81
+ for link in links:
82
+ print(
83
+ link.type.value,
84
+ link.target,
85
+ link.alias,
86
+ link.heading,
87
+ link.blockid,
88
+ )
89
+
90
+ # Encounter order is preserved, duplicates are kept, and malformed
91
+ # wikilinks (like "[[Malformed") are ignored.
92
+ ```
93
+
94
+ ## API
95
+
96
+ ### `extract_links(source)`
97
+
98
+ Extracts links from:
99
+
100
+ - `str`
101
+ - text file-like object with `.read()` returning `str`
102
+
103
+ Returns:
104
+
105
+ - `list[Link]` in encounter order
106
+
107
+ Raises:
108
+
109
+ - `TypeError` for unsupported source types
110
+ - `TypeError` if `.read()` returns non-string data
111
+ - Any exception raised by `.read()` is propagated
112
+
113
+ ### `Link`
114
+
115
+ `Link` is a frozen dataclass with these fields:
116
+
117
+ - `type: LinkType`
118
+ - `target: str`
119
+ - `alias: str | None`
120
+ - `heading: str | None`
121
+ - `blockid: str | None`
122
+
123
+ Convenience properties:
124
+
125
+ - `link.is_url` -> `True` for URL targets (`http`, `https`, `ftp`, `file`, `mailto`)
126
+ - `link.as_path` -> `pathlib.Path` for non-URL targets (raises `ValueError` for URLs)
127
+
128
+ ## Supported link types
129
+
130
+ - `LinkType.WIKILINK`
131
+ - `LinkType.WIKILINK_EMBED`
132
+ - `LinkType.MARKDOWN_LINK`
133
+ - `LinkType.MARKDOWN_EMBED`
134
+ - `LinkType.PLAIN_URL`
135
+
136
+ ## Development
137
+
138
+ This project uses `uv`, `ruff`, `mypy`, and `pytest`.
139
+
140
+ ```bash
141
+ uv sync
142
+ uv run ruff format src/ tests/
143
+ uv run ruff check src/ tests/
144
+ uv run mypy src/
145
+ uv run pytest
146
+ ```
147
+
148
+ ## License
149
+
150
+ This project is licensed under the MIT License. See [LICENSE](LICENSE).
@@ -0,0 +1,48 @@
1
+ [project]
2
+ name = "obsilink"
3
+ version = "0.1.0"
4
+ description = "Extract Obsidian-style wikilink targets from text"
5
+ readme = "AGENTS.md"
6
+ requires-python = ">=3.12"
7
+ classifiers = [
8
+ "Development Status :: 3 - Alpha",
9
+ "Intended Audience :: Developers",
10
+ "License :: OSI Approved :: MIT License",
11
+ "Operating System :: OS Independent",
12
+ "Programming Language :: Python :: 3",
13
+ "Programming Language :: Python :: 3 :: Only",
14
+ "Programming Language :: Python :: 3.12",
15
+ "Topic :: Software Development :: Libraries :: Python Modules",
16
+ "Topic :: Text Processing",
17
+ ]
18
+ keywords = ["obsidian", "wikilink", "parser", "text-processing", "markdown"]
19
+ dependencies = []
20
+
21
+ [project.urls]
22
+ Homepage = "https://github.com/chgroeling/obsilink"
23
+ Repository = "https://github.com/chgroeling/obsilink"
24
+ Issues = "https://github.com/chgroeling/obsilink/issues"
25
+
26
+ [build-system]
27
+ requires = ["hatchling>=1.24.0"]
28
+ build-backend = "hatchling.build"
29
+
30
+ [dependency-groups]
31
+ dev = [
32
+ "mypy>=1.10.0",
33
+ "pytest>=8.2.0",
34
+ "ruff>=0.5.0",
35
+ ]
36
+
37
+ [tool.ruff]
38
+ line-length = 100
39
+ target-version = "py312"
40
+
41
+ [tool.mypy]
42
+ python_version = "3.12"
43
+ strict = true
44
+ mypy_path = ["src"]
45
+
46
+ [tool.pytest.ini_options]
47
+ pythonpath = ["src"]
48
+ testpaths = ["tests"]
@@ -0,0 +1,6 @@
1
+ """Public API for extracting links from Obsidian and Markdown text."""
2
+
3
+ from .models import Link, LinkType
4
+ from .parser import extract_links
5
+
6
+ __all__ = ["Link", "LinkType", "extract_links"]
@@ -0,0 +1,48 @@
1
+ """Data models for parsed Obsidian and Markdown links."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import re
6
+ from dataclasses import dataclass
7
+ from enum import Enum
8
+ from pathlib import Path
9
+
10
+
11
+ class LinkType(Enum):
12
+ """Type of parsed link."""
13
+
14
+ WIKILINK = "wikilink"
15
+ WIKILINK_EMBED = "wikilink_embed"
16
+ MARKDOWN_LINK = "markdown_link"
17
+ MARKDOWN_EMBED = "markdown_embed"
18
+ PLAIN_URL = "plain_url"
19
+
20
+
21
+ @dataclass(frozen=True, slots=True)
22
+ class Link:
23
+ """Structured representation of a parsed link."""
24
+
25
+ type: LinkType
26
+ target: str
27
+ alias: str | None
28
+ heading: str | None
29
+ blockid: str | None
30
+
31
+ @property
32
+ def is_url(self) -> bool:
33
+ """Check if the target is a URL."""
34
+ return bool(re.match(r"^(https?|ftp|file)://", self.target)) or bool(
35
+ re.match(r"^mailto:", self.target)
36
+ )
37
+
38
+ @property
39
+ def as_path(self) -> Path:
40
+ """Return the target as a Path object.
41
+
42
+ Raises:
43
+ ValueError: If the target is a URL.
44
+ """
45
+ if self.is_url:
46
+ msg = f"Cannot convert URL target to Path: {self.target!r}"
47
+ raise ValueError(msg)
48
+ return Path(self.target)