Skip to content

Commit

Permalink
Merge pull request #23 from shroominic/v0.2
Browse files Browse the repository at this point in the history
👾📦 codeboxapi - v0.2
  • Loading branch information
shroominic authored Oct 30, 2024
2 parents 669c17b + 341394c commit 71f3dd7
Show file tree
Hide file tree
Showing 50 changed files with 2,198 additions and 2,066 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/auto-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: 🔁 Pytest ⏳x60

on:
schedule:
- cron: "0 * * * *"
- cron: "*/60 * * * *"

jobs:
test:
Expand All @@ -14,9 +14,7 @@ jobs:
with:
enable_cache: true
cache_prefix: "venv-codeboxapi"
- name: Sync rye
run: rye sync
- name: Run Pytest
- run: rye sync
- run: rye run pytest
env:
CODEBOX_API_KEY: ${{ secrets.CODEBOX_API_KEY }}
run: rye run pytest
18 changes: 9 additions & 9 deletions .github/workflows/code-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ name: ☑️ CodeCheck
on: [push]

jobs:
pre-commit:
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11']
runs-on: ubuntu-latest
steps:
pre-commit:
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: eifinger/setup-rye@v1
with:
enable-cache: true
cache-prefix: 'venv-codeboxapi'
cache-prefix: "venv-codeboxapi"
- name: pin version
run: rye pin ${{ matrix.python-version }}
- name: Sync rye
run: rye sync
- name: Run pre-commit
run: rye run pre-commit run --all-files
- name: Run ruff
run: rye run ruff check
- name: Run tests
env:
CODEBOX_API_KEY: ${{ secrets.CODEBOX_API_KEY }}
Expand Down
23 changes: 0 additions & 23 deletions .pre-commit-config.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

14 changes: 14 additions & 0 deletions .vscode/tasks.json
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"
}
}
]
}
20 changes: 20 additions & 0 deletions Dockerfile
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"]
3 changes: 2 additions & 1 deletion docs/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
The configuration settings are encapsulated within the `CodeBoxSettings` class, which inherits from Pydantic's `BaseSettings` class.

`codeboxapi/config.py`

```python
class CodeBoxSettings(BaseSettings):
...
Expand All @@ -22,7 +23,7 @@ class CodeBoxSettings(BaseSettings):

### CodeBox API Settings

- `CODEBOX_API_KEY: Optional[str] = None`
- `CODEBOX_API_KEY: str | None = None`
The API key for CodeBox.

- `CODEBOX_BASE_URL: str = "https://codeboxapi.com/api/v1"`
Expand Down
38 changes: 38 additions & 0 deletions examples/async_example.py
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())
44 changes: 0 additions & 44 deletions examples/async_file_io.py

This file was deleted.

72 changes: 0 additions & 72 deletions examples/async_plot_dataset.py

This file was deleted.

37 changes: 0 additions & 37 deletions examples/big_upload.py

This file was deleted.

38 changes: 38 additions & 0 deletions examples/big_upload_from_url.py
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 added examples/custom_factory.py.todo
Empty file.
Loading

0 comments on commit 71f3dd7

Please sign in to comment.