AnyEnv
Overview
AnyEnv provides a unified interface for executing code across different environments - local, subprocess, Docker containers, remote sandboxes, and more. Choose the right execution environment for your needs without changing your code.
Getting Started
HTTP Downloads
AnyEnv provides a unified interface for HTTP requests that works across different environments (including PyOdide):
from anyenv import get, post, download, get_json, get_text, get_bytes
# Simple GET request
response = await get("https://api.example.com/data")
print(response.status_code, response.text)
# Get JSON data directly
data = await get_json("https://api.example.com/users")
print(data) # Parsed JSON object
# Get text content
text = await get_text("https://example.com/page.html")
# Get binary data
data = await get_bytes("https://example.com/image.png")
# Download files
await download("https://example.com/file.zip", "local_file.zip")
# POST requests
response = await post("https://api.example.com/create", json={"name": "test"})
# POST JSON data directly
result = await post_json("https://api.example.com/api", {"key": "value"})
Synchronous Versions
All async functions have synchronous counterparts:
from anyenv import get_sync, get_json_sync, download_sync
# Synchronous versions (useful in non-async contexts)
response = get_sync("https://api.example.com/data")
data = get_json_sync("https://api.example.com/users")
download_sync("https://example.com/file.zip", "local_file.zip")
Error Handling
from anyenv import get, HttpError, RequestError, ResponseError
try:
response = await get("https://api.example.com/data")
except RequestError as e:
print(f"Request failed: {e}")
except ResponseError as e:
print(f"Server error: {e}")
except HttpError as e:
print(f"HTTP error: {e}")
Package Installation
Programmatically install Python packages across environments:
from anyenv import install, install_sync
# Install packages asynchronously
await install("requests")
await install(["numpy", "pandas"])
await install("package>=1.0.0")
# Synchronous installation
install_sync("matplotlib")
install_sync(["scipy", "sklearn"])
# Install with specific options
await install("package", upgrade=True, user=True)
Async Utilities
Utilities for running async/sync code and managing concurrency:
from anyenv import run_sync, run_sync_in_thread, gather, call_and_gather
# Run async function from sync context
result = run_sync(async_function())
# Run sync function in thread from async context
result = await run_sync_in_thread(sync_function, arg1, arg2)
# Enhanced gather with better error handling
results = await gather(async_func1(), async_func2(), async_func3(), return_exceptions=True)
# Call function and gather results
func_results = await call_and_gather(
my_function,
[arg1, arg2, arg3], # Arguments to call function with
max_workers=5,
)
Threading and Concurrency
Manage concurrent operations with ThreadGroup and spawners:
from anyenv import ThreadGroup, function_spawner, method_spawner
# ThreadGroup for managing multiple concurrent operations
async with ThreadGroup() as group:
# Add functions to run concurrently
group.spawn(some_function, arg1, arg2)
group.spawn(another_function, arg3)
# Wait for all to complete
results = await group.gather()
# Function spawner for reusable concurrent execution
spawner = function_spawner(my_function, max_workers=10)
results = await spawner([arg1, arg2, arg3, arg4])
# Method spawner for object methods
obj_spawner = method_spawner(my_object.method, max_workers=5)
results = await obj_spawner([data1, data2, data3])
Testing Utilities
Tools for testing and development:
from anyenv import open_in_playground
# Open interactive playground for testing (where supported)
await open_in_playground(locals())
Backend Selection
Choose HTTP backends based on environment:
from anyenv import get_backend, HttpBackend
# Get the best available backend for current environment
backend = get_backend()
# Use specific backend
backend = get_backend("httpx") # or "urllib", "requests"
response = await backend.get("https://example.com")
Environment Compatibility
All functionality automatically adapts to the execution environment:
- PyOdide: Uses browser-compatible implementations
- Standard Python: Uses optimal libraries (httpx, etc.)
- Limited environments: Falls back to stdlib implementations
- Async contexts: Provides async implementations
- Sync contexts: Provides synchronous alternatives
This ensures your code works consistently across web browsers, Jupyter notebooks, serverless functions, and traditional Python environments.
Metadata
Release files for anyenv 2.0.18
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| anyenv-2.0.18.tar.gz | 105.5 kB | With provenance | Details for anyenv-2.0.18.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| anyenv-2.0.18-py3-none-any.whl | Python 3 | none | any | Details for anyenv-2.0.18-py3-none-any.whl |
Total release size: 266.5 kB
Release files / anyenv-2.0.18.tar.gz
| Download URL | anyenv-2.0.18.tar.gz |
|---|---|
| Size | 105.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b0e83decc0b5cb2a375bc43a697b05a889290b672ff615c0bd6561c9768b68d1
|
|
BLAKE2b-256 checksum How to use checksums |
39dff841f6a484996d33c84443a10823b534d5adab4d9caf999fab3ac9830fe5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.
Transparency logRelease files / anyenv-2.0.18-py3-none-any.whl
| Download URL | anyenv-2.0.18-py3-none-any.whl |
|---|---|
| Size | 161.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
53f9c29ef61cc99aa11b2f8257be64d9053d92d46f20f32e8954dbdb0681d019
|
|
BLAKE2b-256 checksum How to use checksums |
ded4bfbb5dd2eff5354a90197d3a2c85e8ab3428af7b7f582ae1d0c51a182d50
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.
Transparency logSecurity for anyenv 2.0.18
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for anyenv-2.0.18.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.