https://github.com/pb-/pyclo
Immutable manipulation of Python data structures, Clojure style
https://github.com/pb-/pyclo
clojure immutability immutable python
Last synced: 7 months ago
JSON representation
Immutable manipulation of Python data structures, Clojure style
- Host: GitHub
- URL: https://github.com/pb-/pyclo
- Owner: pb-
- Created: 2019-10-05T20:02:01.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-08T10:55:25.000Z (about 3 years ago)
- Last Synced: 2025-06-09T13:20:05.736Z (7 months ago)
- Topics: clojure, immutability, immutable, python
- Language: Python
- Size: 36.1 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# pyclo
Pyclo is a collection of functions for Python named after the Clojure standard library to perform the equivalent operation of the respective Clojure function.
Install with
```
pip install pyclo
```
## Rationale
While immutability is neither idiomatic nor common in Python, it is still beneficial to implement the concept through engineering discipline. However, soon one will find oneself writing the same constructs over and over again, and even though these expressions are fairly succinct, it is much nicer to refer to them by name. The goal of this library is to provide a collection of functions that promote immutable manipulation of standard Python data structures as a concept without strictly enforcing it.
They say that there are only two hard problems in software engineering, one of them being naming. Clojure is chosen as a source of inspiration for these functions because the author of this library considers Clojure's naming the gold standard.
## Reference
```
from pyclo import *
```
- `dissoc(dict, *keys)` - return a shallow copy of `dict` without specified `keys`.
- `select_keys(dict, *keys)` - return a shallow copy of `dict` only containing `keys`.
- `get_in(dict, keys, default=None)` - look up a sequence of keys in a nested dict.
## Guarantees
Pyclo's functions never modify their arguments. However, they don't create deep copies, either. This is a practical performance trade off and puts the library user in charge of mutation hygiene.
## Development
```
make test
make lint
make upload # upload to Pypi
```