Skip to content

Commit 62026e2

Browse files
committed
**Changed:** Documentation - Add UTF-8 headers to the Python code snippets shown.
1 parent e3fc5c3 commit 62026e2

File tree

8 files changed

+62
-23
lines changed

8 files changed

+62
-23
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
## Releases
22

3-
- **Changed:** Enable more `ruff` rules and pass all checks
4-
- **Changed:** Docstrings - Enable all `sphinx-linter` rules and pass all checks
3+
- **Changed:** Documentation - Add UTF-8 headers to the Python code snippets shown.
4+
- **Changed:** Enable more `ruff` rules and pass all checks.
5+
- **Changed:** Docstrings - Enable all `sphinx-linter` rules and pass all checks.
56
- **Fixed:** Tests - Delay the closing of the `http_server` fixture socket to ensure that the thread closes properly.
67

78
### v1.3.21 (2025-11-04)

docs/dump.md

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
Dump JSON Lines (jsonl) files incrementally, supporting both uncompressed and compressed formats and allowing
44
custom serialization and opener callbacks.
55

6-
#### Dump the data to an uncompressed file at the specified path.
6+
#### Dump the data to an uncompressed file at the specified path
77

88
```python
9+
# -*- coding: utf-8 -*-
10+
911
import jsonl
1012

1113
data = [
@@ -16,13 +18,15 @@ data = [
1618
jsonl.dump(data, "file.jsonl")
1719
```
1820

19-
#### Dump the data to a compressed file at the specified path.
21+
#### Dump the data to a compressed file at the specified path
2022

2123
!!! note
2224
Supported compression formats are: **gzip (.gz), bzip2 (.bz2), xz (.xz)**
2325
If a file extension is not provided or is unrecognized, the file will be assumed to be uncompressed.
2426

2527
```python
28+
# -*- coding: utf-8 -*-
29+
2630
import jsonl
2731

2832
data = [
@@ -43,9 +47,11 @@ jsonl.dump(data, "file.jsonl.xz")
4347
jsonl.dump(data, "file.jsonl.foo")
4448
```
4549

46-
#### Dump the data to the already opened file.
50+
#### Dump the data to the already opened file
4751

4852
```python
53+
# -*- coding: utf-8 -*-
54+
4955
import gzip
5056

5157
import jsonl
@@ -64,9 +70,11 @@ with gzip.open("file.jsonl.gz", mode="wb") as fd:
6470
jsonl.dump(data, fd, text_mode=False)
6571
```
6672

67-
#### Append the data to the end of the existing file.
73+
#### Append the data to the end of the existing file
6874

6975
```python
76+
# -*- coding: utf-8 -*-
77+
7078
import gzip
7179

7280
import jsonl
@@ -85,13 +93,14 @@ with open("file.jsonl", mode="at", encoding="utf-8") as fp:
8593
jsonl.dump(data, fp, text_mode=True)
8694
```
8795

88-
#### Dump the data to a custom file object.
96+
#### Dump the data to a custom file object
8997

9098
!!! tip
9199
Use this feature when you need to write the data to a custom file object.
92100
The custom file object must have a `write` or `writelines` method.
93101

94102
```python
103+
# -*- coding: utf-8 -*-
95104

96105
import jsonl
97106

@@ -122,19 +131,21 @@ jsonl.dump(data, MyCustomFile1(), text_mode=True)
122131
jsonl.dump(data, MyCustomFile2(), text_mode=True)
123132
```
124133

125-
#### Dump data with a custom serialization.
134+
#### Dump data with a custom serialization
126135

127136
The `json_dumps` parameter allows for custom serialization and must take a Python object and return a
128137
JSON-formatted string.
129138

130139
The following example shows how to use the `json_dumps` parameter to serialize data with the `orjson` and `ujson `
131140
libraries. Make sure to install these libraries to run the example.
132141

133-
```console
142+
```bash
134143
pip install orjson ujson # Ignore this command if these libraries are already installed.
135144
```
136145

137146
```python
147+
# -*- coding: utf-8 -*-
148+
138149
import orjson
139150
import ujson
140151

docs/dump_archive.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
**Example usage:**
1616

1717
```python
18+
# -*- coding: utf-8 -*-
19+
1820
import jsonl
1921

2022
data = [

docs/dump_fork.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ This example creates individual JSON Lines files for each player, storing their
1313

1414

1515
```python
16+
# -*- coding: utf-8 -*-
17+
1618
import jsonl
1719

1820

@@ -54,11 +56,13 @@ jsonl.dump_fork(generate_win_data())
5456
This example demonstrates how to dump data using different JSON libraries.
5557
You can install `orjson` and `ujson` to run the following example.
5658

57-
```console
59+
```bash
5860
pip install orjson ujson # Ignore this command if these libraries are already installed.
5961
```
6062

6163
```python
64+
# -*- coding: utf-8 -*-
65+
6266
import orjson
6367
import ujson
6468
import jsonl

docs/dumps.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
##### Serialize an iterable into a JSON Lines formatted string.
1+
##### Serialize an iterable into a JSON Lines formatted string
22

33
```python
4+
# -*- coding: utf-8 -*-
5+
46
import jsonl
57

68
data = ({'foo': 1}, {'bar': 2})

docs/load.md

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ It also allows loading from URLs and `urllib` requests.
1212
If a file extension is not provided or is not recognized, the compression format will be automatically detected by reading the file's **"magic number."**
1313

1414
If the detection fails, the file is considered uncompressed.
15-
```
1615

17-
#### Load an uncompressed file given a path.
16+
#### Load an uncompressed file given a path
1817

1918
```python
19+
# -*- coding: utf-8 -*-
20+
2021
import jsonl
2122

2223
path = "file.jsonl"
@@ -35,11 +36,13 @@ iterator = jsonl.load(path)
3536
print(tuple(iterator))
3637
```
3738

38-
#### Load a compressed file given a path.
39+
#### Load a compressed file given a path
3940

4041
Check [note](#note-compression) for more details
4142

4243
```python
44+
# -*- coding: utf-8 -*-
45+
4346
import jsonl
4447

4548
path = "file.jsonl.gz" # gzip compressed file, but it can be ".bz2" or ".xz"
@@ -58,12 +61,14 @@ iterator = jsonl.load(path)
5861
print(tuple(iterator))
5962
```
6063

61-
#### Load a file from an open file object.
64+
#### Load a file from an open file object
6265

6366
!!! tip
6467
This is useful when you need to load a file from a custom source.
6568

6669
```python
70+
# -*- coding: utf-8 -*-
71+
6772
import jsonl
6873

6974
path = "file.jsonl"
@@ -83,12 +88,14 @@ with open(path) as fp:
8388
print(tuple(iterator))
8489
```
8590

86-
#### Load from a URL.
91+
#### Load from a URL
8792

8893
You can load a JSON Lines directly from a URL incrementally, if needed you can also create custom
8994
requests using `urllib.request.Request`.
9095

9196
```python
97+
# -*- coding: utf-8 -*-
98+
9299
import urllib.request
93100
import jsonl
94101

@@ -102,13 +109,15 @@ iterator = jsonl.load(req)
102109
print(tuple(iterator))
103110
```
104111

105-
#### Load a file containing broken lines.
112+
#### Load a file containing broken lines
106113

107114
!!! warning
108115
If the **broken** parameter is set to `False`, the function will raise an `Exception` when it encounters a broken line.
109116
If set to `True`, the function will skip the broken line, continue reading the file, and log a warning message.
110117

111118
```python
119+
# -*- coding: utf-8 -*-
120+
112121
import jsonl
113122

114123
# Create a file with broken JSON lines
@@ -124,12 +133,12 @@ print(tuple(iterator))
124133

125134
*Output:*
126135

127-
```console
136+
```text
128137
WARNING:root:Broken line at 2: Expecting ',' delimiter: line 2 column 1 (char 28)
129138
({'name': 'Gilbert', 'wins': [['straight', '7♣'], ['one pair', '10♥']]}, {'name': 'Richard', 'wins': []})
130139
```
131140

132-
#### Load a file using a custom deserialization.
141+
#### Load a file using a custom deserialization
133142

134143
The `json_loads` parameter allows for custom deserialization and must take a JSON-formatted
135144
string as input and return a Python object.
@@ -141,13 +150,15 @@ string as input and return a Python object.
141150
The following example demonstrates how to use the `json_loads` parameter to deserialize the data
142151
using the `orjson` and `ujson` libraries. Make sure to install these libraries to run the example.
143152

144-
```console
153+
```bash
145154
pip install orjson ujson # Ignore this command if these libraries are already installed.
146155
```
147156

148157
Now, you can use these libraries to load the JSON lines:
149158

150159
```python
160+
# -*- coding: utf-8 -*-
161+
151162
import orjson
152163
import ujson
153164

@@ -174,11 +185,13 @@ print(tuple(iterator1))
174185
print(tuple(iterator2))
175186
```
176187

177-
#### Load a file using a custom opener.
188+
#### Load a file using a custom opener
178189

179190
The `opener` parameter allows loading files from custom sources, such as a ZIP archive. Here’s how to use it:
180191

181192
```python
193+
# -*- coding: utf-8 -*-
194+
182195
import zipfile
183196

184197
import jsonl

docs/load_archive.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ Allows to load multiple JSON Lines **(.jsonl)** files incrementally from a **ZIP
88
- Filename filtering using Unix shell-style wildcards via `fnmatch`. Use a pattern (e.g., *.jsonl) to selectively load
99
only matching files within the archive.
1010
- Support for both compressed and uncompressed `.jsonl` files inside the archive. (e.g., `*.jsonl.gz` or `*.jsonl.bz2`
11-
or `*.jsonl.xz` **(Check [note](load.md#note-compression) for more details)**.
11+
or `*.jsonl.xz`) **Check [note](load.md#note-compression) for more details**.
1212
- Graceful handling of malformed or broken lines.
1313
- Optional custom deserialization and opener callbacks for advanced use cases.
1414

1515

1616
**Load from a local archive**
1717

1818
```python
19+
# -*- coding: utf-8 -*-
20+
1921
import jsonl
2022

2123
path = "path/to/archive.zip"
@@ -30,6 +32,8 @@ for filename, iterator in jsonl.load_archive(path):
3032
You can load the archive from a URL, if needed you can also create custom requests using `urllib.request.Request`.
3133

3234
```python
35+
# -*- coding: utf-8 -*-
36+
3337
import urllib.request
3438

3539
import jsonl
@@ -63,6 +67,8 @@ For more information, refer to the [fnmatch documentation](https://docs.python.o
6367

6468

6569
```python
70+
# -*- coding: utf-8 -*-
71+
6672
import jsonl
6773

6874
path = "path/to/archive.zip"

jsonl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def dumper(iterable, /, *, text_mode=True, json_dumps=None, **json_dumps_kwargs)
215215

216216

217217
def loader(stream, broken, /, *, json_loads=None, **json_loads_kwargs):
218-
"""Load a JSON Lines formatted stream into an iterable of Python objects."""
218+
"""Load a JSON Lines formatted stream into an object iterator."""
219219

220220
deserialize = functools.partial(json_loads or _default_json_loads, **json_loads_kwargs)
221221
for lineno, line in enumerate(stream, start=1):

0 commit comments

Comments
 (0)