-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from shroominic/v0.2
👾📦 codeboxapi - v0.2
- Loading branch information
Showing
50 changed files
with
2,198 additions
and
2,066 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"type": "shell", | ||
"command": "bash ./scripts/dev-setup.sh", | ||
"group": "build", | ||
"label": "dev-setup", | ||
"runOptions": { | ||
"runOn": "default" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
FROM ghcr.io/astral-sh/uv as uv | ||
|
||
FROM --platform=amd64 python:3.11-slim as build | ||
|
||
ENV VIRTUAL_ENV=/.venv PATH="/.venv/bin:$PATH" | ||
|
||
COPY --from=uv /uv /uv | ||
COPY README.md pyproject.toml src / | ||
|
||
RUN --mount=type=cache,target=/root/.cache/uv \ | ||
--mount=from=uv,source=/uv,target=/uv \ | ||
/uv venv /.venv && /uv pip install -e .[all] \ | ||
&& rm -rf README.md pyproject.toml src | ||
|
||
# FROM --platform=amd64 python:3.11-slim as runtime | ||
|
||
ENV PORT=8069 | ||
EXPOSE $PORT | ||
|
||
CMD ["/.venv/bin/python", "-m", "codeboxapi.api"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from codeboxapi import CodeBox | ||
|
||
codebox = CodeBox() | ||
|
||
|
||
async def async_examples(): | ||
# 1. Async Code Execution | ||
result = await codebox.aexec("print('Async Hello!')") | ||
print(result.text) | ||
|
||
# 2. Async File Operations | ||
await codebox.aupload("async_file.txt", b"Async content") | ||
|
||
downloaded = await codebox.adownload("async_file.txt") | ||
print("File content:", downloaded.get_content()) | ||
|
||
# 3. All Sync Methods are also available Async | ||
await codebox.ainstall("requests") | ||
|
||
# 4. Async Streaming | ||
async for chunk in codebox.astream_exec(""" | ||
for i in range(3): | ||
print(f"Async chunk {i}") | ||
import time | ||
time.sleep(1) | ||
"""): | ||
print(chunk.content, end="") | ||
|
||
# 5. Async Streaming Download | ||
async for chunk in codebox.astream_download("async_file.txt"): | ||
assert isinstance(chunk, bytes) | ||
print(chunk.decode()) | ||
|
||
|
||
if __name__ == "__main__": | ||
import asyncio | ||
|
||
asyncio.run(async_examples()) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from codeboxapi import CodeBox | ||
|
||
|
||
def url_upload(codebox: CodeBox, url: str) -> None: | ||
codebox.exec( | ||
""" | ||
import requests | ||
def download_file_from_url(url: str) -> None: | ||
response = requests.get(url, stream=True) | ||
response.raise_for_status() | ||
file_name = url.split('/')[-1] | ||
with open('./' + file_name, 'wb') as file: | ||
for chunk in response.iter_content(chunk_size=8192): | ||
if chunk: | ||
file.write(chunk) | ||
""" | ||
) | ||
print(codebox.exec(f"download_file_from_url('{url}')")) | ||
|
||
|
||
codebox = CodeBox() | ||
|
||
url_upload( | ||
codebox, | ||
"https://codeboxapistorage.blob.core.windows.net/bucket/data-test.arrow", | ||
) | ||
print(codebox.list_files()) | ||
|
||
url_upload( | ||
codebox, | ||
"https://codeboxapistorage.blob.core.windows.net/bucket/data-train.arrow", | ||
) | ||
print(codebox.list_files()) | ||
|
||
codebox.exec("import os") | ||
print(codebox.exec("print(os.listdir())")) | ||
print(codebox.exec("print([(f, os.path.getsize(f)) for f in os.listdir('.')])")) |
Empty file.
Oops, something went wrong.