Skip to main content

Yupdates Python SDK

Project description

Yupdates Python SDK

The Yupdates Python SDK lets you easily use the Yupdates API from your own software and scripts.

This is hosted on GitHub. There is also a Yupdates Rust SDK.

Requirements

The Python SDK has zero external dependencies. It is written so that you can easily drop it into your scripts, Lambda functions, and bigger projects without any dependency needs or conflicts.

It requires Python 3.7 or higher.

You will need an API token from the application. Navigate to "Settings" and then "API".

The examples below start with read-only operations, so you can use the general, read-only token to get started.

Installation

Before running the following commands, we assume you have set up your environment (pyenv, virtualenv, etc.).

Install the SDK via pip.

$ pip install yupdates

Or, install from source:

$ git clone git://github.com/yupdates/yupdates-sdk-py.git
$ cd yupdates-sdk-py
$ pip install .

Set the API token environment variable:

$ set +o history
$ export YUPDATES_API_TOKEN="1a7814fc25:c38bb526..."
$ set -o history

Now test the connection and authentication. This will work from a Python shell or script:

from yupdates import yapi
print(yapi.ping())

If there is anything but a 200 response, it will throw an exception. Otherwise, this will print out the JSON response which is returned from the ping function deserialized into a Python dict.

The ping operation is helpful to run in the beginning of your scripts to make sure there are no setup issues.

Another way to use the SDK is to instantiate a client once and use it repeatedly:

from yupdates.client import yupdates_client
yup = yupdates_client()
print(yup.ping())

Read items from a feed

from yupdates import yapi

feed_id = '02fb24a4478462a4491067224b66d9a8b2338dada2737'
feed_items = yapi.read_items(feed_id)  # See client.py for optional parameters

for feed_item in feed_items:
    print(feed_item.title)  # See models.py and API docs for field descriptions

Write items to a feed

To write items, you cannot use the read-only API token anymore. Obtain a token with write privileges by adding an API input to a feed in the app, and set the YUPDATES_API_TOKEN environment variable as you did above.

from yupdates.client import yupdates_client
from yupdates.models import InputItem

yc = yupdates_client()
item = InputItem("a title", "some content", "https://www.example.com/something")
yc.new_items([item])

The API token is feed-specific, which is why there is no other configuration needed. You make one configuration (the API token) and Yupdates figures out the rest on the server side.

That is for convenience, but it also means there's only one permission to reason about, and a small blast radius if it's exposed. The token is authorized to add items to one, single feed, and it cannot do anything else (not even read items). You're not dropping a master key into a cronjob script or Lambda function or wherever it's going to run.

In the future, it will be possible to obtain a token with wider writer privileges, so you can add items to multiple feeds.

Getting help

You can create a GitHub issue on this repository for bugs and feature requests.

The fastest way to get help is to create a support ticket from the Yupdates application. Or email support@yupdates.com. Especially if you need help that is not specific to this SDK, or if you would like more hands-on setup and troubleshooting advice.

Conventions

This library follows the Numpy docstring conventions.

License

The SDK is distributed under the MIT license, please see LICENSE for more information.

This covers the source code and examples, but it does not cover related items like the Yupdates logo or API documentation which is not hosted here.

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

yupdates-0.1.1.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yupdates-0.1.1-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file yupdates-0.1.1.tar.gz.

File metadata

  • Download URL: yupdates-0.1.1.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.15

File hashes

Hashes for yupdates-0.1.1.tar.gz
Algorithm Hash digest
SHA256 82f02533887579f7a1944beb4c907f1304c9b0d21ec64adcd715c054d39d426d
MD5 aee81e41aadb1efc7db02b4b5043783f
BLAKE2b-256 92eb6dc3de3ce9f106f7aa2834155159e7be1f5fbd95e5fd3a281c13d80d7ea9

See more details on using hashes here.

File details

Details for the file yupdates-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: yupdates-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.15

File hashes

Hashes for yupdates-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 847c3cca3d7df194b3e967be3c88f841bdc91255624235fc54d74c5ef5192bf4
MD5 c5ef145441662221c390d5f551737b45
BLAKE2b-256 74013fd92e58900a59a963bac0fdc3995669c536883131029dae6a0eb115e663

See more details on using hashes here.

Supported by

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