npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@iansinnott/notion-cli

v0.5.0

Published

A CLI for the official Notion API

Downloads

3

Readme

notion-cli

A command line interface for the public Notion API.

Highly experimental. Did you check the __tests__ dir yet? Good, don't. It won't lend you confidence in this code.

Ethos

Provide a light wrapper around the Notion SDK / API. If the API can do it it should be possible to do it with this command line tool.

That being said, its still a work in progress. Not all endpoints are supported. Namely, as of this commit, functionality is mostly concerned with reading and transforming data, rather than writing data.

Install

You first need an integration token set in your environment as NOTION_TOKEN=secret_....

yarn global add @iansinnott/notion-cli

Or using NPM:

npm i -g @iansinnott/notion-cli

Or call directly with NPX:

npx @iansinnott/notion-cli --help

Specify the token in-line:

NOTION_TOKEN='secret_abc' npx @iansinnott/notion-cli --help

Examples

# Default formatting is a list. List everything (limited to the default page size)
notion-cli search 

# The raw json
notion-cli search --format json

# Use the json for pipe-ing. Here's an example using jq to view all the URLs from the raw search output
notion-cli search --format json | jq '.results | map(.url)'

# Or store the output for inspection
notion-cli search --format json > search_results.json

# Find something specific (by title)
notion-cli search --query "something interesting" 

# List your pages
notion-cli pages list

# List your databases
notion-cli databases list

# Get a block
notion-cli blocks get "<block id>"

# Get a block and its child blocks
notion-cli blocks get "<block id>" --with_children

# (Experimental) Try to coerce a block's content to plain text. Unsupported block types are omitted
notion-cli blocks get "<block id>" --with_children --format plain_text

CSV to Notion Database

Another experimental feature. You can create a database from a CSV file and also sync CSVs to a database.

# Create a database from a CSV file. The database title will be "Book Database"
# and the column named "title" in the CSV will be used as the title column in
# Notion. If you're unsure of your page ID you can view your pages using
# `notion-cli pages list`.
csv import --input ~/my/books.csv --parent_page_id <page_id> --delimiter "," --title "Book Database" --title_column "title"

# Now import all the data. This is the second step in the two-step process. This
# may take a while, depending on how many rows your CSV has.
csv sync --input ~/my/books.csv  --database_id "<database id from last command>" --delimiter ","

Importing a CSV is a two step process, as shown above, However, once the database is created you can run the csv sync command idempotently. For example, if you generate a CSV file once a day you can also add a cron job to csv sync that file into Notion.

Usage

--help to get help.

notion-cli <command>

Commands:
  notion-cli search     Search objects accessible to your token. Leave query
                        empty to return everything.
                        Results are paginated. Use the --start_cursor flag to
                        fetch more.
  notion-cli databases  Interact with individual databases. If you want to
                        list databases use the `search` command.
  notion-cli pages      Interact with individual pages. If you want to list
                        pages use the `search` command.
  notion-cli blocks     Interact with block objects
  notion-cli users      Interact with user objects
  notion-cli status     Check the status of your environment.

Options:
      --version  Show version number                                   [boolean]
  -f, --format         [choices: "json", "list", "plain_text"] [default: "json"]
      --verbose                                       [boolean] [default: false]
      --help     Show help                                             [boolean]

Not enough non-option arguments: got 0, need at least 1