• Stars
    star
    342
  • Rank 123,683 (Top 3 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created over 10 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A full-featured Python wrapper (and command-line utility) for the Pinboard API. Built by the makers of Pushpin for Pinboard.

CI Status Version Versions

Pinboard.py is an easy-to-use and fully-functional Python wrapper and command-line utility for the Pinboard.in API.

Installation

Pinboard.py is available for download through the Python Package Index (PyPi). You can install it right away using pip or easy_install.

If you're using Python 3 or above:

pip install "pinboard>=2.0"

For Python 2.7:

pip install "pinboard>=1.0,<2.0"

Usage

To get started, you're going to need to get your Pinboard API token from the password page on the Pinboard website. Once you've got that, you're ready to go.

>>> import pinboard
>>> pb = pinboard.Pinboard('API_TOKEN')

Once you've done this, you can now use the pb object to make calls to the Pinboard API. Here are some examples:

Update

Returns the most recent time a bookmark was added, updated or deleted.

>>> pb.posts.update()
datetime.datetime(2014, 7, 27, 18, 11, 29)

Posts

Add a bookmark:

>>> pb.posts.add(url="http://google.com/", description="A Great Search Engine", \
        extended="This is a description!", tags=["search", "tools"], shared=True, \
        toread=False)
True

Update a bookmark:

# First, retrieve the bookmark you'd like to edit
>>> bookmark = pb.posts.get(url='http://google.com/')['posts'][0]
>>> bookmark
<Bookmark description="A Great Search Engine" url="google.com">

# You can now change description, extended, shared, toread, tags, or time directly with the bookmark object.
>>> bookmark.description = "Google is pretty awesome"
>>> bookmark.tags = ["search", "searching"]
>>> bookmark.save()
True

# If you want to update the bookmark creation date as well, you'll need to pass in `update_time=True` to the save method
>>> import datetime
>>> bookmark.time = datetime.datetime.now() - datetime.timedelta(days=5)
>>> bookmark.save(update_time=True)

Delete a bookmark:

>>> pb.posts.delete(url="http://google.com/")
True

Get one or more posts on a single day matching the parameters:

>>> pb.posts.get(url="http://google.com/")
{u'date': datetime.datetime(2014, 7, 25, 16, 35, 25),
 u'posts': [<Bookmark description="A Great Search Engine" url="google.com">],
 u'user': u'dlo'}

>>> import datetime
>>> pb.posts.get(dt=datetime.date.today())
{u'date': datetime.datetime(2014, 7, 25, 16, 35, 25),
 u'posts': [<Bookmark description="A Great Search Engine" url="google.com">,
  <Bookmark description="Smooth Scrolling | CSS-Tricks" url="css-tricks.com">,
  <Bookmark description="Apple "Frustrated" that "People Don't Want to Pay Anything" on Mobile, Says 'The Banner Saga' Developer | Touch Arcade" url="toucharcade.com">],
 u'user': u'dlo'}

Return all recent bookmarks (optionally filtering by tag):

>>> pb.posts.recent(tag=["programming", "python"])
{u'date': datetime.datetime(2014, 4, 28, 2, 7, 58),
 u'posts': [<Bookmark description="itunesfs 1.0.0.7 : Python Package Index" url="pypi.python.org">,
  <Bookmark description="mincss "Clears the junk out of your CSS" - Peterbe.com" url="www.peterbe.com">,
  <Bookmark description="Braintree Test Credit Card Account Numbers" url="www.braintreepayments.com">,
  <Bookmark description="Valued Lessons: Monads in Python (with nice syntax!)" url="www.valuedlessons.com">,
  <Bookmark description="Paste #EGY1XPQxQ2UPuT91SH83 at spacepaste" url="bpaste.net">,
  <Bookmark description="40 Random Letters and Numbers" url="gist.github.com">,
  <Bookmark description="PEP 3156 -- Asynchronous IO Support Rebooted" url="www.python.org">,
  <Bookmark description="Brython" url="www.brython.info">,
  <Bookmark description="Django REST framework" url="django-rest-framework.org">,
  <Bookmark description="mypy - A New Python Variant with Dynamic and Static Typing" url="www.mypy-lang.org">,
  <Bookmark description="Julython 2012" url="www.julython.org">,
  <Bookmark description="Stripe Blog: Exploring Python Using GDB" url="stripe.com">,
  <Bookmark description="Python FAQ: Descriptors - fuzzy notepad" url="me.veekun.com">,
  <Bookmark description="A Guide to Python's Magic Methods ยซ rafekettler.com" url="www.rafekettler.com">,
  <Bookmark description="Melopy" url="prezjordan.github.com">,
  <Bookmark description="litl/rauth" url="github.com">],
 u'user': u'dlo'}

Return a list of dates with the number of posts at each date:

>>> pb.posts.dates(tag=["programming", "python"])
{u'dates': {datetime.date(2008, 12, 5): 1,
  datetime.date(2008, 12, 6): 1,
  ...
  datetime.date(2014, 7, 24): 6,
  datetime.date(2014, 7, 25): 4},
 u'tag': u'programming+python',
 u'user': u'dlo'}

Get all bookmarks in your account:

>>> pb.posts.all()
[<Bookmark description="Of Princesses and Dragons" url="medium.com">
 <Bookmark description="A Great Search Engine" url="google.com">,
 ...
 <Bookmark description="Runner Econ 101 - StimHa" url="stimhack.com">,
 <Bookmark description="์„œ์ธ๊ตญ, ํƒ„ํƒ„ ๊ทผ์œก+ ํƒœํ‰์–‘ ์–ด๊นจโ€ฆ์–ด๋ถ€๋ฐ” ๋ถ€๋ฅธ๋‹ค : ๋„ค์ด" url="news.naver.com">]

You can also filter by tag, start, results, fromdt, or todt.

>>> import datetime
>>> five_days_ago = datetime.datetime.now() - datetime.timedelta(days=5)
>>> pb.posts.all(tag=["programming"], start=10, results=100, fromdt=five_days_ago)
[<Bookmark description="Of Princesses and Dragons" url="medium.com">
 <Bookmark description="A Great Search Engine" url="google.com">,
 ...
 <Bookmark description="Runner Econ 101 - StimHa" url="stimhack.com">,
 <Bookmark description="์„œ์ธ๊ตญ, ํƒ„ํƒ„ ๊ทผ์œก+ ํƒœํ‰์–‘ ์–ด๊นจโ€ฆ์–ด๋ถ€๋ฐ” ๋ถ€๋ฅธ๋‹ค : ๋„ค์ด" url="news.naver.com">]

Tags

Suggest tags for a given URL:

>>> pb.posts.suggest(url="https://pinboard.in")
[{u'popular': [u'pinboard']},
 {u'recommended': [u'bookmark',
   u'bookmarks',
   u'\uc815\ubcf4\ud1b5\uc2e0',
   u'pinboard',
   u'Unread',
   u'webservice']}]

Return all tags in your account along with the number of times they were used:

>>> pb.tags.get()
[<Tag name="absurd" count=1>,
<Tag name="accessibility" count=2>,
<Tag name="accounting" count=3>,
<Tag name="zen" count=1>,
<Tag name="zsh" count=1>,
<Tag name="zynga" count=1>]

Delete a tag:

>>> pb.tags.delete(tag="zynga")
True

Rename a tag:

>>> pb.tags.rename(old='ppython', new='python')
True

Miscellaneous

By default, pinboard.py will return parsed JSON objects. If you'd like the raw response object for a request, just pass in parse_response=False.

>>> response = pb.tags.get(parse_response=False)
>>> response
<addinfourl at 4396047680 whose fp = <socket._fileobject object at 0x105f79850>>
>>> response.read()
... your tags ...

Pinboard.py maps one-to-one with the Pinboard API (e.g., pb.one.two.three() will send a request to "https://api.pinboard.in/v1/one/two/three"). For more information on other methods and usage, please refer to the Pinboard API documentation.

One more note--you might have noticed that there is no "title" attribute for bookmarks. I promise you, there's a good reason for this! This has been done since the Pinboard API calls titles "descriptions" and descriptions "extended" (which, interestingly, was done to stay consistent with the Delicious API, which the Pinboard API was modeled after). In order to keep things minimally confusing, this library sticks to how the Pinboard API names these fields. Just remember--"description" means "title" and "extended" means "description".

Command Line

In addition to providing full Python-level support for the Pinboard API, pinboard.py also comes bundled with a handy command-line utility called "pinboard". Just type "pinboard -h" for a full list of supported commands. Your API token needs to be available to pinboard.py, and can be entered in several ways. Firstly pinboard.py will try to read the ~/.pinboardrc configuration file. If not present then it will try to read an environment variable called PINBOARD_TOKEN. Lastly it will show a shell prompt for the user to enter their token (you can immediately force the latter behavior by typing pinboard login).

All of the commands pre-process and indent the JSON output. If you would like to shoot the raw response data to stdout, just pass "--raw" before the subcommand (e.g., "pinboard --raw bookmarks").

Examples:

$ pinboard login
Enter your Pinboard API token: username:XXXXX
Saved Pinboard credentials to ~/.pinboardrc
$ pinboard suggest-tags --url http://pymotw.com/2/argparse/
[
    {
        "popular": [
            "python"
        ]
    },
    {
        "recommended": [
            "python",
            "argument",
            "parsing"
        ]
    }
]
$ pinboard get --date 7-13-2014
{
    "date": "2014-07-13T03:03:58Z",
    "posts": [
        {
            "extended": "",
            "hash": "e2311835eb0de6bff2595a9b1525bb98",
            "description": "Python 2.7.x and Python 3.x key differences",
            "tags": "python",
            "href": "http://sebastianraschka.com/Articles/2014_python_2_3_key_diff.html",
            "meta": "561d1f53791a8c50109393411f0301fc",
            "time": "2014-07-13T03:03:58Z",
            "shared": "yes",
            "toread": "no"
        },
        {
            "extended": "",
            "hash": "4abe28f70154bd35f84be73cec0c53ef",
            "description": "Miami, the great world city, is drowning while the powers that be look away | World news | The Observer",
            "tags": "",
            "href": "http://www.theguardian.com/world/2014/jul/11/miami-drowning-climate-change-deniers-sea-levels-rising",
            "meta": "2ca547789553ba9d3202a5cd3d367685",
            "time": "2014-07-13T02:53:54Z",
            "shared": "yes",
            "toread": "yes"
        }
    ],
    "user": "dlo"
}
$ pinboard --raw get --date 7/13/2014
{"date":"2014-07-13T03:03:58Z","user":"dlo","posts":[{"href":"http:\/\/sebastianraschka.com\/Articles\/2014_python_2_3_key_diff.html","description":"Python 2.7.x and Python 3.x key differences","extended":"","meta":"561d1f53791a8c50109393411f0301fc","hash":"e2311835eb0de6bff2595a9b1525bb98","time":"2014-07-13T03:03:58Z","shared":"yes","toread":"no","tags":"python"},{"href":"http:\/\/www.theguardian.com\/world\/2014\/jul\/11\/miami-drowning-climate-change-deniers-sea-levels-rising","description":"Miami, the great world city, is drowning while the powers that be look away | World news | The Observer","extended":"","meta":"2ca547789553ba9d3202a5cd3d367685","hash":"4abe28f70154bd35f84be73cec0c53ef","time":"2014-07-13T02:53:54Z","shared":"yes","toread":"yes","tags":""}]}

You can print a full list of pinboard commands by passing the "-h" flag.

$ pinboard -h
usage: pinboard [-h] [--raw]

                {login,last-update,add,delete,get,recent,dates,bookmarks,suggest-tags,tags,delete-tag,rename-tag,notes,note,rss-key,api-token}
                ...

positional arguments:
  {login,last-update,add,delete,get,recent,dates,bookmarks,suggest-tags,tags,delete-tag,rename-tag,notes,note,rss-key,api-token}
    add                 posts/add
    delete              posts/delete
    get                 posts/get
    recent              posts/recent
    dates               posts/dates
    bookmarks           posts/all
    suggest-tags        posts/suggest
    tags                tags/get
    delete-tag          tags/delete
    rename-tag          tags/rename
    notes               notes/list
    note                notes/ID
    rss-key             user/secret
    api-token           user/api_token

optional arguments:
  -h, --help            show this help message and exit
  --raw                 Print the raw data from the Pinboard API without any
                        formatting.

...or help for a specific subcommand by passing the subcommand and then the "-h" flag.

$ pinboard bookmarks -h
usage: pinboard bookmarks [-h] [--from_date FROM_DATE] [--to_date TO_DATE]
                          [--tags TAGS [TAGS ...]] [--count COUNT]
                          [--offset OFFSET]

optional arguments:
  -h, --help            show this help message and exit
  --from_date FROM_DATE
  --to_date TO_DATE
  --tags TAGS [TAGS ...]
  --count COUNT
  --offset OFFSET

Using the CLI in Docker

To build the CLI in Docker:

$ cd <path_to_pinboard>/bin
$ docker build -t pinboard .

To run the CLI in Docker after building:

$ export PINBOARD_TOKEN=<your_pinboard_token>
$ docker run -ti -e PINBOARD_TOKEN pinboard bookmarks --count 10

Support

If you like this library, you might want to check out Pushpin for Pinboard.

License License

Apache License, Version 2.0. See LICENSE for details.

More Repositories

1

bottlenose

A Python wrapper for the Amazon Product Advertising API.
Python
578
star
2

openradar-mirror

A mirror of radars pulled from http://openradar.me/.
Python
246
star
3

django-pyodbc

An ODBC-powered MS SQL Server DB backend for Django 1.4+
Python
203
star
4

git-bigstore

Bigstore is a Git extension that helps you track big files in your repositories.
Python
183
star
5

ConcentricProgressRingView

Fully customizable circular progress bar written in Swift.
Swift
143
star
6

LHSKeyboardAdjusting

An easy-to-use Objective-C protocol that automatically resizes / adjusts views when a keyboard appears on iOS.
Objective-C
100
star
7

ASPinboard

A modern, fast, and flexible Objective-C library for Pinboard.in.
Objective-C
83
star
8

TipJarViewController

Easy, drop-in tip jar for iOS apps.
Swift
78
star
9

requests-cloudkit

Apple CloudKit Python library.
Python
70
star
10

django-template

A battle-tested Django 2.1 project template with configurations for AWS, Heroku, App Engine, and Docker.
Python
64
star
11

in_app_purchase_receipt_verifier

A simple, one-click deploy web app to simplify the process of validating In-App Purchase receipts on the App Store.
Python
58
star
12

python-harvest

A Python wrapper for the Harvest time-tracking API.
Python
55
star
13

SuperLayout

SuperLayout is a Swift library that makes using Auto Layout a breeze.
Swift
52
star
14

django-on-appengine-archive

Jumpstart Django development on Google Appengine.
Python
49
star
15

pwnedpasswords

A Python Library and CLI for the Pwned Passwords v2 API
Python
47
star
16

KeyboardAdjuster

A Swift library that automatically resizes and adjusts views to scroll when a keyboard appears.
Swift
40
star
17

objectifier

Objectify your Python objects.
Python
37
star
18

TimeTracker-Linux

A Harvest client for Ubuntu Linux.
Python
21
star
19

Notchy

Notchy is an iOS app that makes pretty, shareable screenshots for the iPhone X and the iPhone XS.
Swift
20
star
20

LionheartExtensions

An invaluable collection of Swift extensions and utilities for iOS.
Swift
14
star
21

django-pwnedpasswords-validator

Django password validator that checks for passwords in known data breaches.
Python
13
star
22

python-onfleet

A full-featured Python wrapper for the Onfleet API.
Python
11
star
23

TableViewPopoverPresenting

Display popovers on taps over your table views cells. It was hard. Now it's easy.
Swift
9
star
24

QuickTableView

UITableView toolset for Swift.
Swift
9
star
25

python-leafly

Python
8
star
26

django-lionheart-helpers

A small collection of utilities for use with Django.
Python
8
star
27

django-statictastic

A Django app that makes it easy to sync static files to your storage backend of choice.
Python
8
star
28

python-restmapper

RestMapper takes the pain out of integrating with RESTful APIs.
Python
8
star
29

LionheartCurrencyTextField

A drop-in replacement for UITextField that displays currency values the way youโ€™d expect it to.
Swift
8
star
30

LHSFontSelectionViewController

Objective-C
7
star
31

WelcomeViewController

A welcome view in the style of Apple's built-in apps.
Swift
7
star
32

LHSColorPickerView

Objective-C
4
star
33

fastlane-plugin-submit_to_beta_app_review

A simple plugin that submits an iTunes Connect build to Beta App Review.
Ruby
4
star
34

Health-XML-Splitter

A macOS utility that splits Health XML files into smaller chunks.
Swift
4
star
35

pushpin-localizations

Translations for Pushpin, a Pinboard client for iOS.
Shell
3
star
36

LHSDelicious

An easy-to-use Objective-C wrapper for the Delicious API.
Objective-C
3
star
37

Xcode-Templates

Makefile
3
star
38

LHSCategoryCollection

A collection of helpful categories for use in iOS projects.
Objective-C
3
star
39

style-guide

2
star
40

LHSCategoriesFlowView

Objective-C
2
star
41

iOSTipsTricks

Objective-C
2
star
42

IAPReceiptVerifier

Companion iOS library to https://github.com/lionheart/in_app_purchase_receipt_verifier
Swift
2
star
43

LHSKippt

not much to see here, move along
Objective-C
2
star
44

milestonemaker

Just a quick and dirty script that creates weekly milestones in GitHub issues.
Python
2
star
45

UncommonCrypto

Pure Swift wrapper for CommonCrypto.
HTML
2
star
46

LHSDiigo

Objective-C
2
star
47

LionheartOtherAppsViewController

A view controller that showcases all the apps you currently have on the App Store.
Swift
2
star
48

LHSTableViewCells

A Pod that allows you to make tableViewCells without subclassing them
Objective-C
1
star
49

LHSTwitterFollowUtility

A utility that allows your users to follow a specific twitter account.
Objective-C
1
star
50

mixpanel-people-delete

A one-click Heroku app that resets your Mixpanel People usage.
Python
1
star
51

github-issues-tools

Python
1
star
52

LHSCustomTransitionCollection

A collection of custom transitions for use in iOS 7+
Objective-C
1
star
53

releasemaker

Python
1
star
54

LionheartAlamofireClient

A simple class that helps manage interaction with remote APIs using Alamofire.
Swift
1
star
55

LHSOtherAppsViewController

A view controller to show your users the other apps that you have developed.
Objective-C
1
star
56

lionheart-tumblr-theme

The Lionheart Software Tumblr Blog Theme
CSS
1
star