PyNPM¶
Python interface to your NPM and package.json.
Further documentation is available on https://pynpm.readthedocs.io/.
Usage¶
First point PyNPM to your package.json
:
from pynpm import NPMPackage
pkg = NPMPackage('path/to/package.json')
Now you can run e.g. npm install
from within Python:
pkg.install()
Arguments are also support so you can run e.g. npm run build --report
:
pkg.run_script('build', '--report')
Want to use yarn
instead?
from pynpm import YarnPackage
pkg = YarnPackage('path/to/package.json')
pkg.install()
By default NPM output is piped through and the function call will wait for NPM
to finish. If you want to silence the output or interact with process pass
wait=False
and you will get a subprocess.POpen object back:
p = pkg.install(wait=False)
p.wait()
By default you can run the following NPM commands:
build
init
install
link
run-script
start
stop
test
You can also run other NPM commands or restrict which commands you can run:
pkg = NPMPackage('path/to/package.json', commands=['install'])
API Reference¶
PyNPM is a small API to help you invoke NPM from inside Python.
-
class
pynpm.
NPMPackage
(filepath, npm_bin='npm', commands=None)[source]¶ API to an NPM
package.json
.Parameters: - filepath – Path to
package.json
or directory containing the file. - npm_bin – Path to NPM binary. Defaults to
npm
. - commands – List of allowed NPM commands to invoke.
Initialize package.
-
package_json
¶ Read
package.json
contents.
-
package_json_path
¶ Get
package.json
file path.
- filepath – Path to
Additional Notes¶
Notes on how to contribute, legal information and changes are here for the interested.