sliceview 0.1.0__py3-none-any.whl

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,153 @@
1
+ Metadata-Version: 2.4
2
+ Name: sliceview
3
+ Version: 0.1.0
4
+ Summary: Zero-copy, composable slice views for Python sequences
5
+ Project-URL: Homepage, https://github.com/julianofischer/sliceview
6
+ Project-URL: Bug Tracker, https://github.com/julianofischer/sliceview/issues
7
+ Project-URL: Discussions, https://discuss.python.org/t/slice-views-for-python-sequences/103531
8
+ Author-email: Juliano Fischer Naves <julianofischer@gmail.com>
9
+ License: MIT
10
+ License-File: LICENSE
11
+ Keywords: memory,performance,sequence,slice,view,zero-copy
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Topic :: Software Development :: Libraries
22
+ Classifier: Topic :: Utilities
23
+ Requires-Python: >=3.9
24
+ Provides-Extra: dev
25
+ Requires-Dist: pytest-cov; extra == 'dev'
26
+ Requires-Dist: pytest>=7.0; extra == 'dev'
27
+ Description-Content-Type: text/markdown
28
+
29
+ # sliceview
30
+
31
+ **Zero-copy, composable slice views for Python sequences.**
32
+
33
+ `sliceview` lets you work with windows into lists, tuples, strings, or any
34
+ `Sequence` without copying the underlying data. It is the proof-of-concept
35
+ library accompanying the Python discussion on
36
+ [Slice Views for Python Sequences](https://discuss.python.org/t/slice-views-for-python-sequences/103531).
37
+
38
+ ```python
39
+ from sliceview import sliceview
40
+
41
+ data = list(range(1_000_000))
42
+
43
+ # O(1) — no copy
44
+ window = sliceview(data)[50_000:60_000]
45
+
46
+ # Compose slices — still O(1), still no copy
47
+ every_third = sliceview(data)[::3][100:200]
48
+
49
+ # In-place windowed update
50
+ sv = sliceview(data)
51
+ sv[0:5] = [10, 20, 30, 40, 50]
52
+
53
+ # Sliding window without creating new objects
54
+ view = sliceview(data, 0, 1000)
55
+ for _ in range(10):
56
+ process(view)
57
+ view.advance(1000)
58
+ ```
59
+
60
+ ## Why?
61
+
62
+ In Python today, `seq[a:b]` copies the data. For large pipelines — text
63
+ processing, audio, genomics, sorting algorithms — those copies dominate
64
+ both time and memory. `memoryview` solves this for *bytes-like* objects;
65
+ `sliceview` targets *generic* sequences of Python objects.
66
+
67
+ Inspired by Go slices, NumPy views, and `memoryview`.
68
+
69
+ ## Installation
70
+
71
+ ```bash
72
+ pip install sliceview
73
+ ```
74
+
75
+ ## Features
76
+
77
+ | Feature | Details |
78
+ |---|---|
79
+ | **Zero-copy slicing** | `sv[a:b:c]` returns a new `sliceview` in O(1) |
80
+ | **Composable** | `sv[2:][::3][5:10]` chains correctly with no intermediate copies |
81
+ | **Live view** | Mutations to the base are immediately visible through the view |
82
+ | **Write-through** | `sv[i] = x` and `sv[a:b] = iterable` forward to the base |
83
+ | **Sliding window** | `sv.advance(n)` shifts the window in-place — no new object |
84
+ | **Any sequence** | Works with `list`, `tuple`, `str`, `array`, or your own type |
85
+
86
+ ## API
87
+
88
+ ### `sliceview(base, start=None, stop=None, step=None)`
89
+
90
+ Create a view over `base`. `start` may be a `slice` object.
91
+
92
+ ```python
93
+ sv = sliceview(my_list) # full view
94
+ sv = sliceview(my_list, 10, 20) # [10:20]
95
+ sv = sliceview(my_list, slice(10, 20, 2)) # [10:20:2]
96
+ ```
97
+
98
+ ### Indexing and slicing
99
+
100
+ ```python
101
+ sv[i] # element access — maps to base[start + i*step]
102
+ sv[a:b:c] # returns a new sliceview (O(1))
103
+ sv[i] = x # write-through to the base
104
+ sv[a:b] = it # slice assignment (delegates to base)
105
+ ```
106
+
107
+ ### `sv.advance(n) -> self`
108
+
109
+ Shift the view's window forward by `n` index positions (negative to retreat).
110
+ Returns `self` for chaining. Useful for sliding-window algorithms:
111
+
112
+ ```python
113
+ view = sliceview(samples, 0, window_size)
114
+ while True:
115
+ result = process(view)
116
+ if view.advance(window_size)._start >= len(samples):
117
+ break
118
+ ```
119
+
120
+ ### `sv.tolist()` / `sv.copy()`
121
+
122
+ Materialise the view as a new `list` (explicit copy).
123
+
124
+ ### `sv.base`
125
+
126
+ The underlying sequence the view points into.
127
+
128
+ ## Semantics
129
+
130
+ - **`len(sv)`** reflects the *current* base length, so appending to the base
131
+ is immediately visible.
132
+ - **`sv[:]`** returns a new `sliceview` pointing at the same base — O(1).
133
+ - **Hashing**: `sliceview` is intentionally unhashable.
134
+ - **Equality**: compares element-wise to any `Sequence`.
135
+ - **Immutable bases**: `sv[i] = x` raises `TypeError` if the base does not
136
+ support `__setitem__`.
137
+
138
+ ## Design notes and open questions
139
+
140
+ This library implements the core proposal from the
141
+ [Python discussion](https://discuss.python.org/t/slice-views-for-python-sequences/103531).
142
+ Deliberately left out to keep the scope focused:
143
+
144
+ - `view()` builtin shortcut (consensus in the thread was it's unnecessary)
145
+ - `__sliceview__` dunder (motivation unclear until adoption data exists)
146
+ - Multidimensional views (NumPy is the right tool for that)
147
+ - ABC / Protocol additions to `collections.abc`
148
+
149
+ Feedback welcome — please open an issue or join the discussion thread.
150
+
151
+ ## License
152
+
153
+ MIT
@@ -0,0 +1,4 @@
1
+ sliceview-0.1.0.dist-info/METADATA,sha256=QjGuRRpfC1O9Jg3ojQMQekWSEDSn2m-Mfo3nDJCbMdE,4981
2
+ sliceview-0.1.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
3
+ sliceview-0.1.0.dist-info/licenses/LICENSE,sha256=YLaR9KAHSR8-GGGii9qagbhN44bbozVaa4DQU44Bru0,1078
4
+ sliceview-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.29.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Juliano Fischer Naves
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.