Skip to main content

pyfetch-mimic

  • This is a simple module that mimics pyodide.http.pyfetch to make local development for shinylive projects easier. It may work with pyodide in general, but that use case hasn't been tested.
  • For more information on Shinylive for Python, and general information on how to use additional third party libraries (like this one), see: https://shiny.posit.co/py/docs/shinylive.html

Install

  • PyPI: pip install pyfetch-mimic
  • Vendoring:
    • Copy pyfetch_mimic.py into your own project

How to use

  • Include the following conditional import statement at the beginning of the module that will use http.pyfetch:
    import sys
    if "pyodide" in sys.modules:
        from pyodide import http
    else:
        from pyfetch_mimic import http
    
  • Use http.pyfetch as usual
  • NOTE: This is a work in progress and does not support all pyodide.http.pyfetch functionality yet. I use this in my own production work, and the functionality that currently exists is simply the functionality that I need. If there is a need for additional functionality, please open an issue or pull request.

pyfetch examples

  • These should all work with python pyodide.http.pyfetch and pyfetch_mimic.http.pyfetch
# Download, save extracted file to local virtual fs
import sys
if "pyodide" in sys.modules:
    from pyodide import http
else:
    from pyfetch_mimic import http

async def sample():
    response = await http.pyfetch("https://some_url/myfiles.zip")
    await response.unpack_archive()
# Download text file to local virtual fs, load into pandas
import pandas as pd
import sys
if "pyodide" in sys.modules:
    from pyodide import http
else:
    from pyfetch_mimic import http

async def sample():    
    response = await http.pyfetch(url())
    with open("test.json", mode="wb") as file:
        file.write(await response.bytes())
    df = pd.read_json("test.json")
# Download text file into BytesIO memory buffer, load into pandas
from io import BytesIO
import sys
import pandas as pd
if "pyodide" in sys.modules:
    from pyodide import http
else:
    from pyfetch_mimic import http

async def sample():
    response = await http.pyfetch("<URL>")
    buf = BytesIO(await response.bytes())
    df = pd.read_json(buf)

Testing

Install Test Dependencies

  • pip install -e '.[tests]'

Run regular tests (verifies test endpoints and tests pyfetch-mimic)

  • activate venv: source .venv/bin/activate
  • start fastapi app: python3 src_test_webserver/main.py
  • run pytest: pytest -vv -x test

Run pyodide tests with pyfetch calls written identical to pyfetch-mimc

Manually

  • activate venv and start test fastapi app using step above
  • export shinylive app: shinylive export ./test/tests_shinylive ./src_test_webserver/shinyapps
  • open shinylive app in edit mode: http://localhost8000/apps/edit/
  • Click "Run tests"
  • If all function names at the bottom are followed by "passed", then everything should be ok

Using Robot Framework

  • activate venv
  • export shinylive app: shinylive export ./test/tests_shinylive ./src_test_webserver/shinyapps
  • run robot: robot test/robot_tests/

Metadata

Release files for pyfetch-mimic 2024.6.14

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyfetch-mimic 2024.6.14
File Size Uploaded
pyfetch_mimic-2024.6.14.tar.gz 5.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyfetch-mimic 2024.6.14
File Interpreter ABI Platform
pyfetch_mimic-2024.6.14-py3-none-any.whl Python 3 none any Details

Total release size: 10.4 kB

Release files / pyfetch_mimic-2024.6.14.tar.gz

Download URL pyfetch_mimic-2024.6.14.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
50724d3b7757218547e6375f31eb5e9e1740580a21c00951abb55eaccecb1265
BLAKE2b-256 checksum
How to use checksums
9802beebe3c3766ed3cff6094551921f077b51dcf2ac6bdc9f5df7dd15c79b89
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.0.0 CPython/3.12.4

Release files / pyfetch_mimic-2024.6.14-py3-none-any.whl

Download URL pyfetch_mimic-2024.6.14-py3-none-any.whl
Size 4.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
18b4357c2345b14af540bd79f21fab74025a794d89d0fd1fe8e80bf0fb94cc44
BLAKE2b-256 checksum
How to use checksums
b981f4e462d59809cb67ad5a8bcead0a351f163524eb749087ba0ceadf6ec239
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.0.0 CPython/3.12.4

Release history Release notifications | RSS feed

This release

2024.6.14 This release

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page