Skip to main content

Redivis python client library

Project description

Redivis Logo

redivis-python

Redivis client library for python!

Connect data on Redivis to the Python scientific stack, and script your data management tasks.

Beta disclaimer

This library is currently in beta testing. Many of the interfaces are nearing stability, but there may still be backwards-incompatible changes in the future.

Please report any issues or feature requests in the issue tracker.

Comprehensive documentation for this package is available at https://apidocs.redivis.com/client-libraries/redivis-python

Installation

pip install redivis

Authentication

If you are using this library within a Redivis notebook, you'll automatically be authenticated; you can ignore this section.

In order to authenticate with your Redivis account, you must first generate an API Token.

This API token must then be set as the REDIVIS_API_TOKEN environment variable before running your script. You can set the variable for your current session by running the following in your terminal:

export REDIVIS_API_TOKEN=YOUR_TOKEN

Interface

import redivis

query = redivis.query("""
    SELECT * FROM demo.cms_2014_medicare_data.home_health_agencies 
    LIMIT 10
""")

df = query.to_dataframe();

When referencing datasets, projects, and tables on Redivis, you should be familiar with the resource reference syntax.

Full reference for this package is available at https://apidocs.redivis.com/client-libraries/redivis-python/reference

Examples

Querying data

Execute a query

import redivis

# Perform a query on the Demo CMS Medicare data. Table at https://redivis.com/demo/datasets/1754/tables
query = redivis.query("""
    SELECT * FROM demo.cms_2014_medicare_data.home_health_agencies 
    WHERE state = 'CA'
""")

for row in query.list_rows():
    print(row['agency_name'])

# We can also use data frames
df = query.to_dataframe();
print(df)

Execute a scoped query

import redivis

# Perform a query on the Demo CMS Medicare data. Table at https://redivis.com/demo/datasets/1754/tablesd

# We don't need to include fully-qualified table names if we scope our query to the appropriate dataset or project

query = (
    redivis
    .organization("Demo")
    .dataset("CMS 2014 Medicare Data")
    .query("""
        SELECT provider_name, average_total_payments 
        FROM nursing_facilities
        INNER JOIN outpatient_charges USING (provider_id)
        WHERE state = 'CA'
    """)
)

for row in query.list_rows():
    print(row.agency_name)

# We can also use data frames
df = query.to_dataframe();
print(df)

Reading table data

table = (
    redivis
    .organization("Demo")
    .dataset("CMS 2014 Medicare Data")
    .table("Hospice providers")

# We can specify an optional limit argument to only load some of the records
for row in table.list_rows(limit=100):
    print(row)

df = table.to_dataframe(limit=100)
print(df)

Uploading data

Create a new dataset

import redivis

dataset = redivis.user("your-username").dataset("some dataset")

# Could also create a dataset under an organization:
# dataset = redivis.organization("Demo organization").dataset("some dataset")


# public_access_level can be one of ('none', 'overview', 'metadata', 'sample', 'data')
dataset.create(public_access_level="overview")

Create a table and upload data

import redivis

dataset = redivis.user("your-username").dataset("some dataset")

# Create a table on the dataset. Datasets may have multiple tables
# Merge strategy (append or replace) will affect whether future updates
#    are appended to or replace the existing table. This can also be modified at a later point.

table = (
    dataset
    .table("Table name")
    .create(description="Some description", upload_merge_strategy="replace")
)

# Upload a file to the table. You can upload multiple files to any table, and they'll be appended together

with open("path/to/file", "rb") as f:
    table.create_upload(name="tiny.csv", type="delimited", data=f)

Release a new version

import redivis

dataset = redivis.organization("Demo").dataset("some dataset")
dataset.release()

Update an existing dataset

import redivis

dataset = redivis.user("your-username").dataset("some dataset")

# dataset.create_next_version will throw an error if a "next" version already exists,
# unless the ignore_if_exists argument is provided
dataset = dataset.create_next_version(ignore_if_exists=True)

# Upload new data to your table
with open("tiny.csv", "rb") as f:
    dataset.table("Table name").upload(name="tiny.csv", type="delimited", data=f)

dataset.release()

Contributing

Please report any issues or feature requests in the issue tracker — your feedback is much appreciated!

Project details


Release history Release notifications | RSS feed

This version

0.1.8

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

redivis-0.1.8.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

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

redivis-0.1.8-py2.py3-none-any.whl (21.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file redivis-0.1.8.tar.gz.

File metadata

  • Download URL: redivis-0.1.8.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for redivis-0.1.8.tar.gz
Algorithm Hash digest
SHA256 5f82aaa21e07e702b486c41df66b5560ebc2a3a7a915e36f793c5af85c188704
MD5 864441d4f6d2707ee812b1e6e6f96572
BLAKE2b-256 498a9a4283f2a28f0ab5c961f1867cf9077a81660c609d52afca8273ce600ade

See more details on using hashes here.

File details

Details for the file redivis-0.1.8-py2.py3-none-any.whl.

File metadata

  • Download URL: redivis-0.1.8-py2.py3-none-any.whl
  • Upload date:
  • Size: 21.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for redivis-0.1.8-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 23e4850804721083ac97aadccfd9bf284c12734eb51420278f120092b3a68f7c
MD5 1c14a547fa84a39d15f93adadf08e270
BLAKE2b-256 095185af8ef3f2b6e3edececf7928348a0fba4524747ff71669e342dd8e52f6a

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