Skip to main content

Python interface to your NPM and package.json.

Project description

https://github.com/inveniosoftware/pynpm/workflows/CI/badge.svg https://img.shields.io/coveralls/inveniosoftware/pynpm.svg https://img.shields.io/github/tag/inveniosoftware/pynpm.svg https://img.shields.io/pypi/dm/pynpm.svg https://img.shields.io/github/license/inveniosoftware/pynpm.svg

Python interface to your NPM and package.json.

Further documentation is available on https://pynpm.readthedocs.io/.

Installation

PyNPM is on PyPI so all you need is:

$ pip install pynpm

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'])

Trouble shooting

Windows user may face the following error when running the NPM command:

[WinError 2] The system cannot find the file specified

It means supbrossess is unable to run the specific command. To fix this issue, use the shell=True option uppon class initialization:

pkg = NPMPackage('path/to/package.json', shell=True)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pynpm-0.3.1.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pynpm-0.3.1-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file pynpm-0.3.1.tar.gz.

File metadata

  • Download URL: pynpm-0.3.1.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for pynpm-0.3.1.tar.gz
Algorithm Hash digest
SHA256 8c73383b10bf5b57d96a8026619f386e1b81f30b71e125186716af2046332833
MD5 7bbfebe7548d773b162956ad8c0d8b7a
BLAKE2b-256 2e8df0b57a89849f8548c73722bb296dae2ca01f0ab20c1aa58ee55a7fc67db4

See more details on using hashes here.

File details

Details for the file pynpm-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: pynpm-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for pynpm-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 88b5bce96d8aa287b74d9ad8858d319dde36ce83b334bceeb956aef90af44eed
MD5 7b83bc5268b2d86bf5222e14552981e8
BLAKE2b-256 5a4c606420c327e81f951b78b18688c2db6055e6f197acf067e8a4b5339f98cd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page