Skip to main content

PyShare - A Python Sharing library for DataFrames

Project description

PyShare: A Python Sharing library for DataFrames

This is a library for easy sharing of Python DataFrame objects. It's powered by DuckDB. ๐Ÿฆ†

How to install

pip install pyshare-lib

Example usage

import pandas as pd
from pyshare import Share

share = Share("apples", public=True)

df = pd.DataFrame({"tree_id": ["alice", "bob"], "bud_percentage": [42.1, 39.3]})
df.attrs = {"flavor": "sweet/sharp", "country": "The Netherlands"}
share["elstar"] = df

df = pd.DataFrame({"tree_id": ["charlie", "dora"], "bud_percentage": [93.1, 87.3]})
df.attrs = {"flavor": "tart", "country": "Australia"}
share["granny smith"] = df

share

Output:

Share(name="apples", path="md:_share/apples/2fb46588-de57-4a24-9e85-d8cf7ef78be1")
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚     name     โ”‚ column_count โ”‚ estimated_size โ”‚   flavor    โ”‚     country     โ”‚
โ”‚   varchar    โ”‚    int64     โ”‚     int64      โ”‚   varchar   โ”‚     varchar     โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ elstar       โ”‚            2 โ”‚              2 โ”‚ sweet/sharp โ”‚ The Netherlands โ”‚
โ”‚ granny smith โ”‚            2 โ”‚              2 โ”‚ tart        โ”‚ Australia       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
from pyshare import Share

share = Share(name="apples", path="md:_share/apples/2fb46588-de57-4a24-9e85-d8cf7ef78be1")
df = share.get(flavor="sweet/sharp")

df.attrs

Output:

Connecting in read-only mode
{'name': 'elstar', 'flavor': 'sweet/sharp', 'country': 'The Netherlands'}

Configuration

Each share creates a DuckDB database, either on your local machine or on MotherDuck. By default, your shares are saved under ~/.pyshare/data.

To override where local files are stored, set the environment variable PYSHARE_PATH.

To use MotherDuck, export your MotherDuck token to an environment variable MOTHERDUCK_TOKEN.

Fetching and updating data

You can easily find your dataframes by name or any of the attributes you specified:

# any one of these wll give you the elstar table
df = share["elstar"]
df = share.get(name="elstar")
df = share.get(flavor="sweet/sharp")
df = share.get(country="The Netherlands")

# this will get you the granny smith table
df = share["granny smith"]
df = share.get(country="Australia")

# get all matches for a field
for df in share.get_all(tree="large"):
    print(df.attrs)

# get a dataframe of all attributes
share.df()

You can update your dataframe like so, which won't update the attributes unless you specify df.attrs:

df = pd.DataFrame({"tree_id": ["alice", "bob", "eva"], "age": ["young", "old", "ancient"]})
share["elstar"] = df

To overwrite or update the attributes without updating the table, run:

# overwrite
share.attrs["elstar"] = {"parentage": ["Ingrid Marie", "Golden Delicious"]}

# update
share.attrs["elstar"]["parentage"] = ["Ingrid Marie", "Golden Delicious"]
share.attrs["elstar"].update({"parentage": ["Ingrid Marie", "Golden Delicious"]})

Happy sharing!

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

pyshare_lib-0.0.3.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

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

pyshare_lib-0.0.3-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file pyshare_lib-0.0.3.tar.gz.

File metadata

  • Download URL: pyshare_lib-0.0.3.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for pyshare_lib-0.0.3.tar.gz
Algorithm Hash digest
SHA256 03172e74a107ddac855a6fd8ad5b8220699aa2157d7c554cb831be2ddc9bdaad
MD5 318895e2a82d56481702ac28908f4080
BLAKE2b-256 1cbff6d65028ab85cdc94ff6177246c9284e17114ac3c7ca372633e8c218327f

See more details on using hashes here.

File details

Details for the file pyshare_lib-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: pyshare_lib-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for pyshare_lib-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5941047820c5312e932ec38222961391a7334f120000463308df1763dae9aa90
MD5 53d62bc311567fa31d850768bd72045c
BLAKE2b-256 a9cb23b2c550a65a16b5a98fdd8b685fad1fdc9a550a7bac9d2cc4bb2ddbe577

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