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)

Changes

Version 0.3.0 (released 2025-02-20)

  • Add PNPMPackage

Version 0.2.0 (released 2023-11-27)

  • Added shell argument.

  • Package structure update.

  • Added black formatting.

  • Dropped Python 3.6 support.

Version 0.1.2 (released 2020-05-06)

  • Deprecated Python versions lower than 3.6.0. Now supporting 3.6.0 and 3.7.0.

Version 0.1.1 (released 2017-05-16)

  • Fix problem with testing click CLI output.

Version 0.1.0 (released 2017-05-12)

  • Initial public release.

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.0.tar.gz (18.2 kB view details)

Uploaded Source

Built Distribution

pynpm-0.3.0-py2.py3-none-any.whl (6.3 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: pynpm-0.3.0.tar.gz
  • Upload date:
  • Size: 18.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for pynpm-0.3.0.tar.gz
Algorithm Hash digest
SHA256 a69fcaac33e8521ea779484ca78d60e38046b18a0f329d9cd96848e3e0952d26
MD5 b7762841d2e90f0a1da69a2c60143a17
BLAKE2b-256 eff09208f411486a55414915ee572ab6a01bd4d568b866e2fbd709e43100a8fe

See more details on using hashes here.

File details

Details for the file pynpm-0.3.0-py2.py3-none-any.whl.

File metadata

  • Download URL: pynpm-0.3.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for pynpm-0.3.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5c0319ffba489ff87badc67ddedf6ee60cc4ade220c36b1b47f4b16a8a3e62a7
MD5 2e05ed65b39583992521a9e503e7e3f2
BLAKE2b-256 0ae46c83230d1112252ec7dff979e858f6ba3182cb863fbf0d17b3cd97f1ff2b

See more details on using hashes here.

Supported by

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