lysqlnb 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.
- lysqlnb-0.1.0/LICENCE +21 -0
- lysqlnb-0.1.0/PKG-INFO +69 -0
- lysqlnb-0.1.0/README.md +47 -0
- lysqlnb-0.1.0/pyproject.toml +78 -0
- lysqlnb-0.1.0/src/lysqlnb/__init__.py +17 -0
- lysqlnb-0.1.0/src/lysqlnb/exceptions.py +5 -0
- lysqlnb-0.1.0/src/lysqlnb/models.py +92 -0
- lysqlnb-0.1.0/src/lysqlnb/py.typed +0 -0
lysqlnb-0.1.0/LICENCE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Leyton Addison-Roach
|
|
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.
|
lysqlnb-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lysqlnb
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A library for reading and validating SQL notebook files.
|
|
5
|
+
Keywords: notebook,sql
|
|
6
|
+
Author: Leyton Addison-Roach
|
|
7
|
+
Author-email: Leyton Addison-Roach <git@laddisonroach.com>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENCE
|
|
10
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
15
|
+
Classifier: Typing :: Typed
|
|
16
|
+
Requires-Dist: pydantic>=2.12.5
|
|
17
|
+
Requires-Dist: pyyaml>=6.0.3
|
|
18
|
+
Requires-Python: >=3.14
|
|
19
|
+
Project-URL: Repository, https://github.com/leyts/lysqlnb
|
|
20
|
+
Project-URL: Issues, https://github.com/leyts/lysqlnb/issues
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# lysqlnb
|
|
24
|
+
|
|
25
|
+
A library for reading and validating SQL notebook files (`.sqlnb`).
|
|
26
|
+
|
|
27
|
+
> [!WARNING]
|
|
28
|
+
> This project is a work in progress and is not yet ready for use. The API is unstable and subject to breaking changes.
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
```shell
|
|
33
|
+
pip install lysqlnb
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Background
|
|
37
|
+
|
|
38
|
+
The data models are based on the VS Code [NotebookSerializer API](https://code.visualstudio.com/api/extension-guides/notebook#serializer).
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
>>> from pathlib import Path
|
|
44
|
+
>>> from lysqlnb import NotebookData
|
|
45
|
+
>>> notebook = NotebookData.from_file(Path("path/to/notebook.sqlnb"))
|
|
46
|
+
>>> print(notebook.model_dump_json(indent=2))
|
|
47
|
+
{
|
|
48
|
+
"cells": [
|
|
49
|
+
{
|
|
50
|
+
"kind": 1,
|
|
51
|
+
"value": "# This is Markdown.",
|
|
52
|
+
"language_id": "markdown"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"kind": 2,
|
|
56
|
+
"value": "SELECT * FROM departments;",
|
|
57
|
+
"language_id": "oracle-sql"
|
|
58
|
+
}
|
|
59
|
+
]
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Requirements
|
|
64
|
+
|
|
65
|
+
Python 3.14+
|
|
66
|
+
|
|
67
|
+
## Licence
|
|
68
|
+
|
|
69
|
+
[MIT](LICENCE)
|
lysqlnb-0.1.0/README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# lysqlnb
|
|
2
|
+
|
|
3
|
+
A library for reading and validating SQL notebook files (`.sqlnb`).
|
|
4
|
+
|
|
5
|
+
> [!WARNING]
|
|
6
|
+
> This project is a work in progress and is not yet ready for use. The API is unstable and subject to breaking changes.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```shell
|
|
11
|
+
pip install lysqlnb
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Background
|
|
15
|
+
|
|
16
|
+
The data models are based on the VS Code [NotebookSerializer API](https://code.visualstudio.com/api/extension-guides/notebook#serializer).
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
>>> from pathlib import Path
|
|
22
|
+
>>> from lysqlnb import NotebookData
|
|
23
|
+
>>> notebook = NotebookData.from_file(Path("path/to/notebook.sqlnb"))
|
|
24
|
+
>>> print(notebook.model_dump_json(indent=2))
|
|
25
|
+
{
|
|
26
|
+
"cells": [
|
|
27
|
+
{
|
|
28
|
+
"kind": 1,
|
|
29
|
+
"value": "# This is Markdown.",
|
|
30
|
+
"language_id": "markdown"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"kind": 2,
|
|
34
|
+
"value": "SELECT * FROM departments;",
|
|
35
|
+
"language_id": "oracle-sql"
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Requirements
|
|
42
|
+
|
|
43
|
+
Python 3.14+
|
|
44
|
+
|
|
45
|
+
## Licence
|
|
46
|
+
|
|
47
|
+
[MIT](LICENCE)
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "lysqlnb"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "A library for reading and validating SQL notebook files."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENCE"]
|
|
8
|
+
authors = [
|
|
9
|
+
{ name = "Leyton Addison-Roach", email = "git@laddisonroach.com" },
|
|
10
|
+
]
|
|
11
|
+
requires-python = ">=3.14"
|
|
12
|
+
keywords = ["notebook", "sql"]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Development Status :: 2 - Pre-Alpha",
|
|
15
|
+
"Intended Audience :: Developers",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Programming Language :: Python :: 3.14",
|
|
19
|
+
"Typing :: Typed",
|
|
20
|
+
]
|
|
21
|
+
dependencies = [
|
|
22
|
+
"pydantic>=2.12.5",
|
|
23
|
+
"pyyaml>=6.0.3",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[project.urls]
|
|
27
|
+
Repository = "https://github.com/leyts/lysqlnb"
|
|
28
|
+
Issues = "https://github.com/leyts/lysqlnb/issues"
|
|
29
|
+
|
|
30
|
+
[dependency-groups]
|
|
31
|
+
dev = [
|
|
32
|
+
"pytest>=9.0.2",
|
|
33
|
+
"pytest-datadir>=1.8.0",
|
|
34
|
+
"ruff>=0.15.2",
|
|
35
|
+
"ty>=0.0.18",
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
[build-system]
|
|
39
|
+
requires = ["uv_build>=0.10.4,<0.11.0"]
|
|
40
|
+
build-backend = "uv_build"
|
|
41
|
+
|
|
42
|
+
[tool.ruff]
|
|
43
|
+
line-length = 79
|
|
44
|
+
|
|
45
|
+
[tool.ruff.format]
|
|
46
|
+
docstring-code-format = true
|
|
47
|
+
docstring-code-line-length = 20
|
|
48
|
+
|
|
49
|
+
[tool.ruff.lint]
|
|
50
|
+
select = ["ALL"]
|
|
51
|
+
ignore = [
|
|
52
|
+
"W191",
|
|
53
|
+
"E111",
|
|
54
|
+
"E114",
|
|
55
|
+
"E117",
|
|
56
|
+
"D206",
|
|
57
|
+
"D300",
|
|
58
|
+
"Q000",
|
|
59
|
+
"Q001",
|
|
60
|
+
"Q002",
|
|
61
|
+
"Q003",
|
|
62
|
+
"COM812",
|
|
63
|
+
"COM819",
|
|
64
|
+
"TD",
|
|
65
|
+
]
|
|
66
|
+
|
|
67
|
+
[tool.ruff.lint.per-file-ignores]
|
|
68
|
+
"tests/*.py" = [
|
|
69
|
+
"ANN201",
|
|
70
|
+
"D100",
|
|
71
|
+
"D103",
|
|
72
|
+
"D104",
|
|
73
|
+
"PLR2004",
|
|
74
|
+
"S101",
|
|
75
|
+
]
|
|
76
|
+
|
|
77
|
+
[tool.ruff.lint.pydocstyle]
|
|
78
|
+
convention = "google"
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""lysqlnb — a library for reading and validating SQL notebook files."""
|
|
2
|
+
|
|
3
|
+
from lysqlnb.exceptions import NotebookParseError
|
|
4
|
+
from lysqlnb.models import (
|
|
5
|
+
NotebookCellData,
|
|
6
|
+
NotebookCellKind,
|
|
7
|
+
NotebookCellLanguage,
|
|
8
|
+
NotebookData,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
__all__ = [
|
|
12
|
+
"NotebookCellData",
|
|
13
|
+
"NotebookCellKind",
|
|
14
|
+
"NotebookCellLanguage",
|
|
15
|
+
"NotebookData",
|
|
16
|
+
"NotebookParseError",
|
|
17
|
+
]
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"""Notebook data models and parsing."""
|
|
2
|
+
|
|
3
|
+
from enum import IntEnum, StrEnum
|
|
4
|
+
from typing import TYPE_CHECKING, Any
|
|
5
|
+
|
|
6
|
+
import yaml
|
|
7
|
+
from pydantic import BaseModel, ConfigDict, Field, ValidationError
|
|
8
|
+
|
|
9
|
+
from lysqlnb.exceptions import NotebookParseError
|
|
10
|
+
|
|
11
|
+
if TYPE_CHECKING:
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class NotebookCellKind(IntEnum):
|
|
16
|
+
"""A notebook cell kind.
|
|
17
|
+
|
|
18
|
+
Attributes:
|
|
19
|
+
MARKUP: Formatted source that is used for display.
|
|
20
|
+
CODE: Source that can be executed and that produces output.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
MARKUP = 1
|
|
24
|
+
CODE = 2
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class NotebookCellLanguage(StrEnum):
|
|
28
|
+
"""Language identifier for a notebook cell.
|
|
29
|
+
|
|
30
|
+
Attributes:
|
|
31
|
+
MARKDOWN: Markdown markup language.
|
|
32
|
+
ORACLE_SQL: Oracle SQL dialect.
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
MARKDOWN = "markdown"
|
|
36
|
+
ORACLE_SQL = "oracle-sql"
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class NotebookCellData(BaseModel):
|
|
40
|
+
"""Raw representation of a notebook cell.
|
|
41
|
+
|
|
42
|
+
Attributes:
|
|
43
|
+
kind: The kind of cell data.
|
|
44
|
+
value: The source value of this cell data — either
|
|
45
|
+
source code or formatted text.
|
|
46
|
+
language_id: The language identifier of the source
|
|
47
|
+
value of this cell data.
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
model_config = ConfigDict(extra="forbid", populate_by_name=True)
|
|
51
|
+
|
|
52
|
+
kind: NotebookCellKind
|
|
53
|
+
value: str
|
|
54
|
+
language_id: NotebookCellLanguage = Field(alias="languageId")
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class NotebookData(BaseModel):
|
|
58
|
+
"""Raw representation of a notebook.
|
|
59
|
+
|
|
60
|
+
Attributes:
|
|
61
|
+
cells: The cell data of this notebook.
|
|
62
|
+
"""
|
|
63
|
+
|
|
64
|
+
model_config = ConfigDict(extra="forbid")
|
|
65
|
+
|
|
66
|
+
cells: list[NotebookCellData]
|
|
67
|
+
|
|
68
|
+
@classmethod
|
|
69
|
+
def from_file(cls, path: Path) -> NotebookData:
|
|
70
|
+
"""Create a notebook from a file.
|
|
71
|
+
|
|
72
|
+
Args:
|
|
73
|
+
path: Path to the notebook file.
|
|
74
|
+
|
|
75
|
+
Returns:
|
|
76
|
+
A validated notebook data object.
|
|
77
|
+
|
|
78
|
+
Raises:
|
|
79
|
+
NotebookParseError: If the file contains invalid YAML or
|
|
80
|
+
does not conform to the notebook schema.
|
|
81
|
+
"""
|
|
82
|
+
try:
|
|
83
|
+
raw: Any = yaml.safe_load(path.read_text(encoding="utf-8"))
|
|
84
|
+
except yaml.YAMLError as e:
|
|
85
|
+
msg = f"Invalid YAML: {e}"
|
|
86
|
+
raise NotebookParseError(msg) from e
|
|
87
|
+
|
|
88
|
+
try:
|
|
89
|
+
return cls.model_validate(raw)
|
|
90
|
+
except ValidationError as e:
|
|
91
|
+
msg = f"Invalid notebook structure: {e}"
|
|
92
|
+
raise NotebookParseError(msg) from e
|
|
File without changes
|