knife is a powerful Python multitool loosely inspired by Underscore.js but remixed for maximum pythonicity.
knife concentrates power that is normally dispersed across the entire Python universe in one convenient shrink-wrapped package.
Vitals
knife works with CPython 2.6, 2.7, 3.1. and 3.2 and PyPy 1.8.
knife documentation is at http://readthedocs.org/docs/knife/en/latest/ or http://packages.python.org/knife/
Installation
Install knife with pip…:
$ pip install knife [... possibly exciting stuff happening ...] Successfully installed knife
…or easy_install…:
$ easy_install knife [... possibly exciting stuff happening ...] Finished processing dependencies for knife
…or old school by downloading knife from http://pypi.python.org/pypi/knife/:
$ python setup.py install [... possibly exciting stuff happening ...] Finished processing dependencies for knife
Development
Public repository: https://bitbucket.org/lcrees/knife.
Mirror: https://github.com/lcrees/knife/
Issue tracker: https://bitbucket.org/lcrees/knife/issues
License: BSD
3 second knife
Things go in:
>>> from knife import __ >>> gauntlet = __(5, 4, 3, 2, 1)
Things get knifed:
>>> gauntlet.initial().rest().slice(1, 2).last() knife.lazy.lazyknife ([IN: ([3]) => WORK: ([]) => HOLD: ([]) => OUT: ([3])])
Things come out:
>>> gauntlet.get() 3
Slightly more knife
knife has 40 plus methods that can be chained into pipelines…
contrived example:
>>> __(5, 4, 3, 2, 1).initial().rest().slice(1, 2).last().get() 3
…or used object-oriented style.
contrived example:
>>> from knife import knife >>> oo = knife(5, 4, 3, 2, 1) >>> oo.initial() knife.active.activeknife ([IN: ([5, 4, 3, 2, 1]) => WORK: ([]) => HOLD: ([]) => OUT: ([5, 4, 3, 2])]) >>> oo.rest() knife.active.activeknife ([IN: ([5, 4, 3, 2]) => WORK: ([]) => HOLD: ([]) => OUT: ([4, 3, 2])]) >>> oo.slice(1, 2) knife.active.activeknife ([IN: ([4, 3, 2]) => WORK: ([]) => HOLD: ([]) => OUT: ([3])]) >>> oo.last() knife.active.activeknife ([IN: ([3]) => WORK: ([]) => HOLD: ([]) => OUT: ([3])]) >>> oo.get() 3
A knife object can roll its current state back to previous states like snapshots of immediately preceding operations, a baseline snapshot, or even a snapshot of the original arguments.
contrived example:
>>> undone = __(1, 2, 3).prepend(1, 2, 3, 4, 5, 6) >>> undone.peek() [1, 2, 3, 4, 5, 6, 1, 2, 3] >>> undone.append(1).undo().peek() [1, 2, 3, 4, 5, 6, 1, 2, 3] >>> undone.append(1).append(2).undo(2).peek() [1, 2, 3, 4, 5, 6, 1, 2, 3] >>> undone.snapshot().append(1).append(2).baseline().peek() [1, 2, 3, 4, 5, 6, 1, 2, 3] >>> undone.original().peek() [1, 2, 3]
knife objects come in two flavors: active and lazy. active.knife objects evaluate the result of calling a method immediately after the call. Calling the same method with a lazy.knife object only yields results when it is iterated over or knife.lazy.lazyknife.get is called to get results.
knife.lazy.lazyknife combines all knife methods in one class:
>>> from knife import lazyknife
It can be imported under its dunderscore (knife.__) alias.
>>> from knife import __
knife.active.activeknife also combines every knife method in one combo knife class:
>>> from knife import activeknife
It can be imported under its knife.knife alias:
>>> from knife import knife
knife methods are available in more focused classes that group related methods together. These classes can also be chained into pipelines.
contrived example:
>>> from knife.active import mathknife, reduceknife >>> one = mathknife(10, 5, 100, 2, 1000) >>> two = reduceknife() >>> one.minmax().pipe(two).merge().back().min().get() 2 >>> one.original().minmax().pipe(two).merge().back().max().get() 1000 >>> one.original().minmax().pipe(two).merge().back().sum().get() 1002
Metadata
Release files for knife 0.5.11
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distributions (sdists)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| knife-0.5.11.zip | 31.5 kB | Without provenance | Details | |
| knife-0.5.11.tar.gz | 23.9 kB | Without provenance | Details |
Release files / knife-0.5.11.zip
| Download URL | knife-0.5.11.zip |
|---|---|
| Size | 31.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6630d52e6e1eb04defce69555d627cd87935cddb0b332d1ed4e09b53cb4746e0
|
|
BLAKE2b-256 checksum How to use checksums |
8f44f6b867f97dd24115b3166c5542ddec71801132d0986772d7578158acb8fb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / knife-0.5.11.tar.gz
| Download URL | knife-0.5.11.tar.gz |
|---|---|
| Size | 23.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
32c66084d18da2ace634d8239b3227ef46652b0ac5394a196cdc32ec0a8fa9ea
|
|
BLAKE2b-256 checksum How to use checksums |
c24cdd4c07b0c5911b2b4cbb3cf7795f7d18ed76ec46ba40da85d9b73be3dd4e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for knife 0.5.11
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.