Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ dist/
*.pyc
.coverage
coverage.xml
# Zensical
# App
/site/
/test*.*
6 changes: 6 additions & 0 deletions docs/assets/css/extra.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* Fix content shift on scrollbar */
@supports (scrollbar-gutter: stable) {
html {
scrollbar-gutter: stable;
}
}
7 changes: 2 additions & 5 deletions docs/assets/js/external-links.js → docs/assets/js/extra.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Open External Links in New Tab

// noinspection JSUnresolvedReference,JSIgnoredPromiseFromCall
document$.subscribe(documentLoaded)

function documentLoaded() {
document$.subscribe(function () {
// console.log('documentLoaded:', globalThis.location)
for (const el of document.querySelectorAll('a')) {
// console.log('el.host:', el.host)
Expand All @@ -12,4 +9,4 @@ function documentLoaded() {
el.rel = 'noopener'
}
}
}
})
120 changes: 58 additions & 62 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,27 @@ To see the help use the `[COMMAND] -h` flag.
??? abstract "Global Help Output: `npmstat -h`"

```text
usage: npmstat [-h] [-C] [-V] [command] ...

example: npmstat stats @cssnr/vitepress-swiper

positional arguments:
[command]
info get package info
stats get download stats

options:
-h, --help show this help message and exit
-C, --clear-cache clear the request cache and exit
-V, --version show the package version and exit
Usage: npmstat [OPTIONS] COMMAND [ARGS]...

NPM Stat CLI

Example: npmstat -v stats @cssnr/vitepress-swiper

┌─ Options ──────────────────────────────────────────────────────────┐
│ --verbose -v Verbose Output (jq safe). │
│ --version -V Show App Version. │
│ --clear-cache -C Clear Request Cache. │
│ --install-completion Install completion for the │
│ current shell. │
│ --show-completion Show completion for the │
│ current shell, to copy it or │
│ customize the installation. │
│ --help -h Show this message and exit. │
└─────────────────────────────────────────────────────────────────────┘
┌─ Commands ─────────────────────────────────────────────────────────┐
│ info Get Package Information. │
│ stats Get Package Download Stats. │
└─────────────────────────────────────────────────────────────────────┘
```

To enable tab-completion follow the [Autocomplete](#autocomplete) instructions.
Expand All @@ -55,44 +63,46 @@ You can also view the [Examples](#examples) below.
Get package information. Without a `version` all versions are returned.

```text
usage: npmstat info [-h] [-i N] [-p] [-f] [-v] package [version]

positional arguments:
package Package name
version Package version

options:
-h, --help show this help message and exit

global options:
-i, --indent N indent level of json, default: 2
-p, --purge purge cache for this request
-f, --force-purge force purge for this request
-v, --verbose enable verbose command output
Get Package Information.

┌─ Arguments ────────────────────────────────────────────────────────┐
│ * package TEXT NPM Package Name. [required] │
│ version [VERSION] Package Version │
└─────────────────────────────────────────────────────────────────────┘
┌─ Options ──────────────────────────────────────────────────────────┐
│ --indent -i INTEGER JSON Indent. [default: 2] │
│ --purge -p Purge Cache for Request. │
│ --force-purge -f Force Purge for Request. │
│ --help -h Show this message and exit. │
└─────────────────────────────────────────────────────────────────────┘
```

!!! tip "In the terminal output is scaled and displays properly."

### stats

Get package stats for a `period`. The default is `last-day`.

```text
usage: npmstat stats [-h] [-i N] [-p] [-f] [-v] [-r] package [period]

positional arguments:
package Package name
period Stats period

options:
-h, --help show this help message and exit
-r, --range show a range vs cumulative

global options:
-i, --indent N indent level of json, default: 2
-p, --purge purge cache for this request
-f, --force-purge force purge for this request
-v, --verbose enable verbose command output
Usage: npmstat stats [OPTIONS] PACKAGE [PERIOD]

Get Package Download Stats.

┌─ Arguments ────────────────────────────────────────────────────────┐
│ * package TEXT NPM Package Name. [required] │
│ period [PERIOD] Stats Period. [default: last-day] │
└─────────────────────────────────────────────────────────────────────┘
┌─ Options ──────────────────────────────────────────────────────────┐
│ --range -r Get Range. │
│ --indent -i INTEGER JSON Indent. [default: 2] │
│ --purge -p Purge Cache for Request. │
│ --force-purge -f Force Purge for Request. │
│ --help -h Show this message and exit. │
└─────────────────────────────────────────────────────────────────────┘
```

!!! tip "In the terminal output is scaled and displays properly."

**Period Options**

To print individual stats for each day use the `-r` flag.
Expand Down Expand Up @@ -193,31 +203,17 @@ Reference: https://github.com/npm/registry/blob/main/docs/download-counts.md

## Autocomplete :lucide-flask-conical:{ title="Experimental Feature" }

Bash/Zsh, Windows, and Fish support tab auto-complete for arguments.

After [installing](index.md#install) run one of the following commands.
Shell autocomplete support is provided by [click](https://github.com/pallets/click).

=== "Bash/Zsh"
After [installing](index.md#install) run the following command.

```shell
activate-global-python-argcomplete
```

=== "Windows"

```shell
register-python-argcomplete --shell powershell npmstat | Out-String | Invoke-Expression
```

=== "Fish"

```shell
register-python-argcomplete --shell fish my-awesome-script | source
```
```shell
npmstat --install-completion
```

Then restart your shell.

Reference: https://kislyuk.github.io/argcomplete/#activating-global-completion
Reference: https://click.palletsprojects.com/en/stable/shell-completion/

 

Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ npmstat stats @cssnr/vitepress-swiper
```python
from npmstat import api

downloads = api.get_downloads('@cssnr/vitepress-swiper')
downloads = api.get_downloads("@cssnr/vitepress-swiper")
print(downloads.json())
```

Expand Down
16 changes: 6 additions & 10 deletions docs/module.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ You can import the module directly.
```python
import npmstat

r = npmstat.get_package('@cssnr/vitepress-swiper')
print(f'cached: {r.from_cache}')
r = npmstat.get_package("@cssnr/vitepress-swiper")
print(f"{r.from_cache=}")
print(r.json())
```

Expand All @@ -19,21 +19,17 @@ Or import the api directly.
```python
from npmstat import api


r = api.get_downloads('@cssnr/vitepress-swiper', 'last-week')
print(f'cached: {r.from_cache}')
r = api.get_downloads("@cssnr/vitepress-swiper", "last-week")
print(f"{r.from_cache=}")
print(r.json())


api.session.cache.clear()
print('cache cleared')
print("cache cleared")
```

For more details see the [api.py](https://github.com/cssnr/npmstat/blob/master/src/npmstat/api.py) source code.

!!! warning

This API is incomplete and expected to change in the future.
!!! warning "This API is incomplete and may change in the future."

 

Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ classifiers = [
"Typing :: Typed",
]
dependencies = [
"argcomplete>=3,<4",
"requests>=2,<3",
"requests-cache>=1,<2",
"typer>=0.20.0",
]
dynamic = ["version"]

Expand All @@ -30,7 +30,7 @@ Homepage = "https://cssnr.com/"
Issues = "https://github.com/cssnr/npmstat/issues"

[project.scripts]
npmstat = "npmstat.cli:main"
npmstat = "npmstat.cli:app"

[dependency-groups]
dev = [
Expand All @@ -44,6 +44,7 @@ dev = [
"ruff>=0.14.7",
"tombi>=0.7.3",
"ty>=0.0.1a30",
"typer>=0.20.0",
"types-requests>=2.32.4.20250913",
"validate-pyproject[all]>=0.24.1",
]
Expand Down
Loading