How Pinboard.py maps to the Pinboard API
masterpb.one.two.three() will trigger a request to https://api.pinboard.in/v1/one/two/three. This allows developers to use the library as a direct proxy for any Pinboard API endpoint.repository·master·Indexed 43 days ago
https://github.com/lionheart/pinboard.pyA Python wrapper and command-line utility for the Pinboard.in API. It allows users to programmatically manage bookmarks, tags, and notes. The library provides a one-to-one mapping with the Pinboard API, including a CLI for adding, deleting, and retrieving bookmarks, as well as managing account metadata like RSS keys and API tokens.
pb.one.two.three() will trigger a request to https://api.pinboard.in/v1/one/two/three. This allows developers to use the library as a direct proxy for any Pinboard API endpoint.Pinboard.py maps one-to-one with the Pinboard API. Because the Pinboard API follows the legacy Delicious API naming conventions, the field names in this library may seem counter-intuitive:
description in the library corresponds to the Title of the bookmark.extended in the library corresponds to the Description of the bookmark.This mapping is maintained to ensure consistency with the underlying Pinboard API.
Install Pinboard.py via pip depending on your Python version.
For Python 3 or above:
pip install "pinboard>=2.0"For Python 2.7:
pip install "pinboard>=1.0,<2.0"The pinboard command-line utility requires your Pinboard API token. It looks for credentials in the following order:
~/.pinboardrc configuration file.PINBOARD_TOKEN environment variable.You can force the interactive login process by running pinboard login.
$ pinboard login
Enter your Pinboard API token: username:XXXXX
Saved Pinboard credentials to ~/.pinboardrcTo use the library, import pinboard and instantiate the Pinboard class using your API token. You can find your token on the Pinboard password page.
import pinboard
pb = pinboard.Pinboard('API_TOKEN')import pinboard
pb = pinboard.Pinboard('API_TOKEN')The pinboard command-line utility requires your Pinboard API token. It attempts to find the token in the following order:
~/.pinboardrc configuration file.PINBOARD_TOKEN environment variable.You can explicitly trigger the interactive login process by running pinboard login.
$ pinboard login
Enter your Pinboard API token: username:XXXXX
Saved Pinboard credentials to ~/.pinboardrcYou can containerize the pinboard CLI using Docker.
1. Build the image:
Navigate to the bin directory of the repository and build the image.
2. Run the container:
Pass the PINBOARD_TOKEN environment variable to the container using the -e flag.
# Build
$ cd <path_to_pinboard>/bin
$ docker build -t pinboard .
# Run
$ export PINBOARD_TOKEN=<your_pinboard_token>
$ docker run -ti -e PINBOARD_TOKEN pinboard bookmarks --count 10$ cd <path_to_pinboard>/bin
$ docker build -t pinboard .
$ export PINBOARD_TOKEN=<your_pinboard_token>
$ docker run -ti -e PINBOARD_TOKEN pinboard bookmarks --count 10To use the CLI, you must provide a Pinboard API token. You can authenticate in two ways:
login command. The CLI will prompt you to enter your API token and will save it to ~/.pinboardrc for future use.PINBOARD_TOKEN environment variable.If no token is found in the environment or the config file, the CLI will prompt you for one.
pinboard loginBy default, pinboard.py returns parsed JSON objects. If you need the raw response object (e.g., to read the raw body), pass parse_response=False to any method call.
response = pb.tags.get(parse_response=False)
print(response.read())response = pb.tags.get(parse_response=False)The pb.tags object allows you to manage your Pinboard tags.
pb.posts.suggest(url='...') to get popular or recommended tags for a specific URL.pb.tags.get() returns a list of Tag objects containing the name and the count of how many times they are used.pb.tags.delete(tag='...') removes a tag from your account.pb.tags.rename(old='...', new='...') changes an existing tag name.# Suggest tags
pb.posts.suggest(url="https://pinboard.in")
# Get all tags
pb.tags.get()
# Delete a tag
pb.tags.delete(tag="zynga")
# Rename a tag
pb.tags.rename(old='ppython', new='python')The pb.posts object provides methods to interact with your bookmarks.
Use pb.posts.add() with parameters like url, description, extended, tags, shared, and toread.
pb.posts.add(url="http://google.com/", description="A Great Search Engine", extended="This is a description!", tags=["search", "tools"], shared=True, toread=False)To update a bookmark, first retrieve it using pb.posts.get(url=...). You can then modify attributes directly on the Bookmark object and call .save().
Note on field names: To maintain consistency with the Pinboard API, description refers to the bookmark's title, and extended refers to the bookmark's description.
# 1. Retrieve
bookmark = pb.posts.get(url='http://google.com/')['posts'][0]
# 2. Modify attributes
bookmark.description = "Google is pretty awesome"
bookmark.tags = ["search", "searching"]
# 3. Save changes
bookmark.save()Updating the creation time:
If you want to update the bookmark's creation date (time) as well, you must pass update_time=True to the .save() method.
import datetime
bookmark.time = datetime.datetime.now() - datetime.timedelta(days=5)
bookmark.save(update_time=True)pb.posts.delete(url="http://google.com/")pb.posts.get(url="...") returns a dictionary containing the date and a list of matching posts.pb.posts.get(dt=datetime.date.today()) returns posts for a specific day.pb.posts.recent(tag=["tag1", "tag2"]) returns recent bookmarks, optionally filtered by tags.pb.posts.all(tag=["tag"], start=0, results=100, fromdt=datetime_obj) returns all bookmarks in your account with optional filtering.pb.posts.dates(tag=["tag"]) returns a dictionary mapping dates to the number of posts on those dates.bookmark = pb.posts.get(url='http://google.com/')['posts'][0]
bookmark.description = "New Title"
bookmark.save()The following positional arguments are available for the pinboard command:
add: posts/adddelete: posts/deleteget: posts/getrecent: posts/recentdates: posts/datesbookmarks: posts/allsuggest-tags: posts/suggesttags: tags/getdelete-tag: tags/deleterename-tag: tags/renamenotes: notes/listnote: notes/IDrss-key: user/secretapi-token: user/api_tokenlogin: interactive login{login,last-update,add,delete,get,recent,dates,bookmarks,suggest-tags,tags,delete-tag,rename-tag,notes,note,rss-key,api-token}