Skip to content

Commit 71f3dd7

Browse files
authored
Merge pull request #23 from shroominic/v0.2
👾📦 codeboxapi - v0.2
2 parents 669c17b + 341394c commit 71f3dd7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2198
-2066
lines changed

.github/workflows/auto-tests.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: 🔁 Pytest ⏳x60
22

33
on:
44
schedule:
5-
- cron: "0 * * * *"
5+
- cron: "*/60 * * * *"
66

77
jobs:
88
test:
@@ -14,9 +14,7 @@ jobs:
1414
with:
1515
enable_cache: true
1616
cache_prefix: "venv-codeboxapi"
17-
- name: Sync rye
18-
run: rye sync
19-
- name: Run Pytest
17+
- run: rye sync
18+
- run: rye run pytest
2019
env:
2120
CODEBOX_API_KEY: ${{ secrets.CODEBOX_API_KEY }}
22-
run: rye run pytest

.github/workflows/code-check.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@ name: ☑️ CodeCheck
33
on: [push]
44

55
jobs:
6-
pre-commit:
7-
strategy:
8-
matrix:
9-
python-version: ['3.9', '3.10', '3.11']
10-
runs-on: ubuntu-latest
11-
steps:
6+
pre-commit:
7+
strategy:
8+
matrix:
9+
python-version: ["3.9", "3.10", "3.11"]
10+
runs-on: ubuntu-latest
11+
steps:
1212
- uses: actions/checkout@v2
1313
- uses: eifinger/setup-rye@v1
1414
with:
1515
enable-cache: true
16-
cache-prefix: 'venv-codeboxapi'
16+
cache-prefix: "venv-codeboxapi"
1717
- name: pin version
1818
run: rye pin ${{ matrix.python-version }}
1919
- name: Sync rye
2020
run: rye sync
21-
- name: Run pre-commit
22-
run: rye run pre-commit run --all-files
21+
- name: Run ruff
22+
run: rye run ruff check
2323
- name: Run tests
2424
env:
2525
CODEBOX_API_KEY: ${{ secrets.CODEBOX_API_KEY }}

.pre-commit-config.yaml

Lines changed: 0 additions & 23 deletions
This file was deleted.

.vscode/settings.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

.vscode/tasks.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"type": "shell",
6+
"command": "bash ./scripts/dev-setup.sh",
7+
"group": "build",
8+
"label": "dev-setup",
9+
"runOptions": {
10+
"runOn": "default"
11+
}
12+
}
13+
]
14+
}

Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM ghcr.io/astral-sh/uv as uv
2+
3+
FROM --platform=amd64 python:3.11-slim as build
4+
5+
ENV VIRTUAL_ENV=/.venv PATH="/.venv/bin:$PATH"
6+
7+
COPY --from=uv /uv /uv
8+
COPY README.md pyproject.toml src /
9+
10+
RUN --mount=type=cache,target=/root/.cache/uv \
11+
--mount=from=uv,source=/uv,target=/uv \
12+
/uv venv /.venv && /uv pip install -e .[all] \
13+
&& rm -rf README.md pyproject.toml src
14+
15+
# FROM --platform=amd64 python:3.11-slim as runtime
16+
17+
ENV PORT=8069
18+
EXPOSE $PORT
19+
20+
CMD ["/.venv/bin/python", "-m", "codeboxapi.api"]

docs/settings.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
The configuration settings are encapsulated within the `CodeBoxSettings` class, which inherits from Pydantic's `BaseSettings` class.
66

77
`codeboxapi/config.py`
8+
89
```python
910
class CodeBoxSettings(BaseSettings):
1011
...
@@ -22,7 +23,7 @@ class CodeBoxSettings(BaseSettings):
2223

2324
### CodeBox API Settings
2425

25-
- `CODEBOX_API_KEY: Optional[str] = None`
26+
- `CODEBOX_API_KEY: str | None = None`
2627
The API key for CodeBox.
2728

2829
- `CODEBOX_BASE_URL: str = "https://codeboxapi.com/api/v1"`

examples/async_example.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from codeboxapi import CodeBox
2+
3+
codebox = CodeBox()
4+
5+
6+
async def async_examples():
7+
# 1. Async Code Execution
8+
result = await codebox.aexec("print('Async Hello!')")
9+
print(result.text)
10+
11+
# 2. Async File Operations
12+
await codebox.aupload("async_file.txt", b"Async content")
13+
14+
downloaded = await codebox.adownload("async_file.txt")
15+
print("File content:", downloaded.get_content())
16+
17+
# 3. All Sync Methods are also available Async
18+
await codebox.ainstall("requests")
19+
20+
# 4. Async Streaming
21+
async for chunk in codebox.astream_exec("""
22+
for i in range(3):
23+
print(f"Async chunk {i}")
24+
import time
25+
time.sleep(1)
26+
"""):
27+
print(chunk.content, end="")
28+
29+
# 5. Async Streaming Download
30+
async for chunk in codebox.astream_download("async_file.txt"):
31+
assert isinstance(chunk, bytes)
32+
print(chunk.decode())
33+
34+
35+
if __name__ == "__main__":
36+
import asyncio
37+
38+
asyncio.run(async_examples())

examples/async_file_io.py

Lines changed: 0 additions & 44 deletions
This file was deleted.

examples/async_plot_dataset.py

Lines changed: 0 additions & 72 deletions
This file was deleted.

examples/big_upload.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

examples/big_upload_from_url.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from codeboxapi import CodeBox
2+
3+
4+
def url_upload(codebox: CodeBox, url: str) -> None:
5+
codebox.exec(
6+
"""
7+
import requests
8+
9+
def download_file_from_url(url: str) -> None:
10+
response = requests.get(url, stream=True)
11+
response.raise_for_status()
12+
file_name = url.split('/')[-1]
13+
with open('./' + file_name, 'wb') as file:
14+
for chunk in response.iter_content(chunk_size=8192):
15+
if chunk:
16+
file.write(chunk)
17+
"""
18+
)
19+
print(codebox.exec(f"download_file_from_url('{url}')"))
20+
21+
22+
codebox = CodeBox()
23+
24+
url_upload(
25+
codebox,
26+
"https://codeboxapistorage.blob.core.windows.net/bucket/data-test.arrow",
27+
)
28+
print(codebox.list_files())
29+
30+
url_upload(
31+
codebox,
32+
"https://codeboxapistorage.blob.core.windows.net/bucket/data-train.arrow",
33+
)
34+
print(codebox.list_files())
35+
36+
codebox.exec("import os")
37+
print(codebox.exec("print(os.listdir())"))
38+
print(codebox.exec("print([(f, os.path.getsize(f)) for f in os.listdir('.')])"))

examples/custom_factory.py.todo

Whitespace-only changes.

0 commit comments

Comments
 (0)