Pyastack
Read this in 日本語.
Introduction
*A lightweight, thread-safe stack library that allows you to transparently manipulate mutable objects and immutable objects with the same interface. *
Main features
-
Transparent operation that does not make you aware of the type: It is possible to add and remove with the API without being aware of the type
-
Thread-safe atomic operation:
threading.RLockprevents conflict (data destruction) even in multi-threaded environments -
Low overhead memory optimization: Weight reduction of attribute management with
__slots__and high-speed batch operation using CPython native processing (push_many) -
Stack overflow prevention (Capacity guard): Prevent unintended memory waste and overflow
-
Zero external dependence (Pure Python): Works only in standard libraries
Project structure
Pyastack/
├── src/
│ └── pyastack/
│ ├── __init__.py # Package entry point (class exposure)
│ ├── stack.py # AtomicStack class body
│ └── py.typed # type hint compatible marker (empty file)
├── tests/
│ └── test_stack.py # Unit test (pytest)
│ └── data #test data
├──.gitignore
├── LICENSE # MIT License File
├── README.md # Document
└── pyproject.toml # Package build and meta information definition
Main API
| Method / Syntactic | Explanation | Computation |
| :--- | :--- | :--- |
| push(item) | Add an element to the end of the stack. When the upper limit is exceeded, OverflowError. | $O(1)$ |
| push_many(*items) | Lock multiple elements once and add them in bulk with C-level processing. | $O(K)$ |
| pop() | Remove and delete the element at the end of the stack. Empty time is IndexError. | $O(1)$ |
| peek() | Confirm the last element (do not delete). Empty time is IndexError. | $O(1)$ |
| clear() | Empty the contents of the stack in place. | $O(1)$ |
| is_empty() | Determine whether the stack is empty. | $O(1)$ |
| is_full() | Determine whether the stack has reached the capacity limit. | $O(1)$ |
| len(stack) | Get the current number of stored elements. | $O(1)$ |
| stack[i] / stack[a:b]] | Inffix access and slice acquisition (__getitem__). | $O(1)$ / $O(K)$ |
| item in stack | Element existence determination (__contains__). | $O(N)$ |
| for x in stack: | Remove from the top of the stack to the bottom in order (LIFO inversion). | $O(N)$ |
Quick start
install pip
pip install pyastack
uv
uv add pyastack
upgrade
pip
pip install --upgrade pyastack
uv
uv add --upgrade pyastack
from pyastack import AtomicStack
if __name__ == '__main__':
# Initialize with a list (maximum capacity 10)
stack = AtomicStack([1, 2, 3], capacity=10)
# Push elements (single / bulk)
stack.push(4)
stack.push_many(5,6)
print(stack.peek()) # 6 (confirmation at the end)
print(stack.pop()) # 6 (remove the end)
print(len(stack)) # 5
print(3 in stack) # True (confirmation of existence)
from pyastack import AtomicStack
if __name__ == '__main__':
# Initialize with a string
char_stack = AtomicStack("hello", capacity=10)
char_stack.push("!")
print(str(char_stack)) # "hello!"
# Remove 1 character from the end
top_char=char_stack.pop()
print(top_char) # "!"
print(str(char_stack)) # "hello"
from pyastack import AtomicStack
if __name__ == '__main__':
stack = AtomicStack([10, 20, 30, 40])
# Reference and slice of subtitles
print(stack[-1]) # 40 (stack top)
print(stack[0]) # 10 (stack bottom)
print(stack[-2:]) # [30, 40]
# Iteration in stack order (LIFO: last in first out)
for item in stack:
print(item)
# Output:
#40
#30
#20
#10
import threading
from pyastack import AtomicStack
stack = AtomicStack([], capacity=1000)
def worker():
for i in range(100):
stack.push(i)
threads = [threading.Thread(target=worker) for _ in range(10)]
for t in threads:
t.start()
for t in threads:
t.join()
print(len(stack)) # Exactly 1000 without competition
Metadata
Release files for pyastack 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyastack-0.1.2.tar.gz | 51.1 kB | Without provenance | Details for pyastack-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyastack-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for pyastack-0.1.2-py3-none-any.whl |
Total release size: 58.3 kB
Release files / pyastack-0.1.2.tar.gz
| Download URL | pyastack-0.1.2.tar.gz |
|---|---|
| Size | 51.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e499976e7b7b6a26f10d227b05c8a53510d3accb6f4390ec3dd355650bf772f3
|
|
BLAKE2b-256 checksum How to use checksums |
d3d20ee3faee60cf5a3afa0f8b926dc83195b6df69d7574fc0c6308653d85fcf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.2
|
Release files / pyastack-0.1.2-py3-none-any.whl
| Download URL | pyastack-0.1.2-py3-none-any.whl |
|---|---|
| Size | 7.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2bef90c35ddafe292b376dcde07bd69e6380c130f82ad68b329c8a791812af96
|
|
BLAKE2b-256 checksum How to use checksums |
2bf8cb6752ba02f5cac2c48a179186f17797d43f9ce5d6beb3aac1b5fb0b0cf2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.2
|
Security for pyastack 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.