Skip to main content

Adds `Series.aiohttp.get_text()` and `Series.aiohttp.get_json()` to pandas Series objects.

Project description

pandas aiohttp plugin

Adds the functions Series.aiohttp.get_text() and Series.aiohttp.get_json() to pandas Series objects.

1. Usage Notes

Both get_text() and get_json() support the parameters limit:int=100 and ssl:bool=True which limit concurrent connections and enable or disable SSL verification, respectively. More features may be supported in the future.

2. Examples

The following examples assume that you are running in a Jupyter notebook.

If you are running in a regular python environment, you will need to use the asyncio.run() function to run the code. See the last example.

2.1. Series.aiohttp.get_text()

import pandas as pd
import pandas_aiohttp
# The next line is only needed if you want to prevent your IDE from highlighting as "unused import"
assert pandas_aiohttp

post_urls = pd.Series([
    "https://jsonplaceholder.typicode.com/posts/1",
    "https://jsonplaceholder.typicode.com/posts/2",
])

data = await post_urls.aiohttp.get_text()
0    {\n  "userId": 1,\n  "id": 1,\n  "title": "sun...
1    {\n  "userId": 1,\n  "id": 2,\n  "title": "qui...
dtype: object

2.2. Series.aiohttp.get_json()

A more common usage pattern;

import pandas as pd
import pandas_aiohttp

# create an example data frame:
frame = pd.DataFrame(
    columns=["A", "B"],
    data =[
        ["XY",23],
        ["YZ", 34],
        ["ZX", 45]
    ]
)

# Build a series of urls from the dataframe columns,
# and assign to a new column named "data":
frame["data"] = await (
    "https://httpbin.org/get"
    +"?A="+frame["A"]
    +"&B="+frame["B"].astype(str)
).aiohttp.get_json()

result
0    {'args': {'A': 'XY', 'B': '23'}, 'headers': {'...
1    {'args': {'A': 'YZ', 'B': '34'}, 'headers': {'...
2    {'args': {'A': 'ZX', 'B': '45'}, 'headers': {'...
dtype: object

2.3. Manual Async Runtime

If you are running in a regular python environment, you will need to use the asyncio.run() function to run the code.

import pandas as pd
import pandas_aiohttp
import asyncio

post_urls = pd.Series([
    "https://jsonplaceholder.typicode.com/posts/1",
    "https://jsonplaceholder.typicode.com/posts/2",
])

async def main():
    data = await post_urls.aiohttp.get_text()
    print(data)

asyncio.run(main())

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

pandas_aiohttp-0.1.0.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

pandas_aiohttp-0.1.0-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file pandas_aiohttp-0.1.0.tar.gz.

File metadata

  • Download URL: pandas_aiohttp-0.1.0.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.8

File hashes

Hashes for pandas_aiohttp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 45a6a7d2603061345b262fed70208cd3463567aa038da528c4c821d91fc00657
MD5 2bcf8a4f4b68edc2c384762a2aa94bd5
BLAKE2b-256 0f30f19fe25bb7bceb7827d0300493a0cad014fe10e3ed8b7188c46440fe29b1

See more details on using hashes here.

Provenance

File details

Details for the file pandas_aiohttp-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pandas_aiohttp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a27d35e1c7d7b345178a415d74bf5e045ea10547b9e49d52c332ee79b0112ffb
MD5 4e6a589c1c24a36a4856d8afe342841c
BLAKE2b-256 a293ba064c13a899eea08dfa3840b4c1db99e2c63e07a3bdaba49ce8df946cee

See more details on using hashes here.

Provenance

Supported by

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