Skip to main content

A simple python implementation of RStudio's pins package to work with RStudio Connect

Project description

pins

A simple package to pin and retrieve pinned data from RStudio Connect.

Read more about pins on the offical R implementation's website

This project is not affiliated with RStudio.

v1.0 Pins API

This package currently only supports one operation with the official pins 1.0 API, Reading a pinned csv from RStudio Connect.

The legacy API for this package is still available. See below for more details.

Reading a pin on RStudio Connect

import the appropriate sub-module.

import pins.connect as pins

Then use the pin_read() function to read csv data pinned to Connect directly into a pandas dataframe.

pins.pin_read("<CONNECT_SERVER_URL>", "<CONNECT_API_KEY>", "<USER_NAME/PIN_NAME>")

Alternatively, you can return a dict of the pin metadata, by using the meta_only=True parameter.

For instance:

>>> pins.pin_read("https://connect.example.com.rstudio.com/rsc", 
... os.getenv("CONNECT_API_KEY"), 
... "mark.sellors/palmer_penguins",
... meta_only=True)
{'file': 'palmer_penguins.csv', 'file_size': '17299', 
'pin_hash': '809e9def88e78114', 'type': 'csv',
'title': "'palmer_penguins: a pinned 344 x 8 data frame'",
'description': '~', 'created': '20211029T120018Z', 'api_version': '1.0'}

Here's a complete example:

>>> import os
>>> import pins.connect as pins
>>> pins.pin_read("https://colorado.rstudio.com/rsc", 
... os.getenv("COLORADO_API_KEY"), "mark.sellors/palmer_penguins")
       species     island  bill_length_mm  ...  body_mass_g     sex  year
0       Adelie  Torgersen            39.1  ...       3750.0    male  2007
1       Adelie  Torgersen            39.5  ...       3800.0  female  2007
2       Adelie  Torgersen            40.3  ...       3250.0  female  2007
3       Adelie  Torgersen             NaN  ...          NaN     NaN  2007
4       Adelie  Torgersen            36.7  ...       3450.0  female  2007
..         ...        ...             ...  ...          ...     ...   ...
339  Chinstrap      Dream            55.8  ...       4000.0    male  2009
340  Chinstrap      Dream            43.5  ...       3400.0  female  2009
341  Chinstrap      Dream            49.6  ...       3775.0    male  2009
342  Chinstrap      Dream            50.8  ...       4100.0    male  2009
343  Chinstrap      Dream            50.2  ...       3775.0  female  2009

[344 rows x 8 columns]
>>> 

Legacy functions

This functionality is deprecated and will be removed in a future version. Please move to the v1.0 functionality if possible.

Make a pin on RStudio Connect.

pin_rsconnect(data, pin_name, pretty_pin_name, connect_server, api_key)

Parameters:

  • data: any object that has a to_json method (eg. pandas DataFrame)
  • pin_name (str): name of pin, only alphanumeric and underscores
  • pretty_pin_name (str): display name of pin
  • connect_server (str): RStudio Connect server address e.g. https://connect.example.com/
  • api_key (str): API key of a user on RStudio Connect

Returns:

  • Url of content

Get data from a python pin on RStudio Connect

pin_get_rsconnect(url, api_key):

Parameters:

  • url (str) content solo URL on Connect (NOT dashboard URL)
  • api_key (str): API key of a user on RStudio Connect

Returns:

  • JSON version of pin

Try it out

import panads
import pins

mydata = {'col1': [1, 2], 'col2': [3, 4]}
df = pd.DataFrame(data=mydata)

# pin the data to connect
pin = pins.pin_rsconnect(
    data = df, 
    pin_name = "my_pin_7788", 
    pretty_pin_name = "Python Pin", 
    connect_server = connect_server, 
    api_key = api_key
)

# retrieve the pinned data
pins.pin_get_rsconnect(pin['content_url'], api_key = api_key)

License

This package is released under an MIT license and was created by Alex Gold and Mark Sellors.

"RStudio" and "RStudio Connect" are trademarks of RStudio, PBC.

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

pins-0.1.3.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

pins-0.1.3-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file pins-0.1.3.tar.gz.

File metadata

  • Download URL: pins-0.1.3.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.7

File hashes

Hashes for pins-0.1.3.tar.gz
Algorithm Hash digest
SHA256 bc0cc3d25cc676ef8b2ce644dc769180ec02f3a015a22bdf0dfcc42512f4b1a0
MD5 796260ed206f4ebae8abfc6a36617a7c
BLAKE2b-256 5132fe6ef4267479d12e956341d7a72e430b4b4ecf61decd65379d0a42704255

See more details on using hashes here.

File details

Details for the file pins-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: pins-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.7

File hashes

Hashes for pins-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 44b4f4e8fdf3621041094e73785d896a1e1ee784124a78d80193f58f4d1e9506
MD5 61907612aa478fb0d832113bdf83b161
BLAKE2b-256 acb3429c85cca10a9aa4056b35a0161fd073e0d0d2e161562febe2468980a9b5

See more details on using hashes here.

Supported by

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