Skip to content

Dependencies & Networking

This content is for v1.1.2. Switch to the latest version for up-to-date documentation.

ZKite applications can integrate pure-Python packages from PyPI and perform verified HTTPS network communication.


In ZKite 1.1.2, declare dependencies in requirements.txt or pyproject.toml:

1. Using requirements.txt (Standard pip Projects)

Section titled “1. Using requirements.txt (Standard pip Projects)”

For standard pip projects, create a requirements.txt in your project root with one package per line:

requirements.txt
# Pinned third-party dependencies
requests==2.32.5
pydantic==2.8.2
  • Blank lines and # comments are supported.
  • Pip options (such as --index-url), recursive -r includes, and line continuations are not supported.
  • No pyproject.toml is required for pip projects.

2. Using pyproject.toml (uv or Package Managers)

Section titled “2. Using pyproject.toml (uv or Package Managers)”

For uv or other package managers, declare dependencies under [project].dependencies:

pyproject.toml
[project]
name = "my-zkite-app"
version = "0.1.0"
dependencies = [
"requests==2.32.5",
]

No dependency list is needed in app.json. Its legacy dependencies array is merged with a deprecation notice; it does not override pyproject.toml dependencies. Requirements from requirements.txt are also merged; avoid conflicting constraints. ZKite does not currently consume uv lockfiles, so use pinned requirements when exact versions matter.


Android-Aware Dependency Markers & Extras (New in 1.1.2)

Section titled “Android-Aware Dependency Markers & Extras (New in 1.1.2)”

When evaluating environment markers and package extras, ZKite’s dependency resolver targets the Android mobile environment, not your development host OS:

  • Target Architectures: ARM64 evaluates to aarch64; x86_64 evaluates to x86_64.
  • Runtime Version: Python marker versions match the bundled mobile CPython engine (3.14.6 in this release).
  • Package Extras: Tracked separately for each dependency. A false marker skips that dependency; a true marker resolves and validates it normally.
  • Release Baseline: Android release markers use the minimum SDK baseline; device-specific kernel/build values are unavailable.
  • Fail-Fast Safety: Applicable dependencies requiring unsupported native C-extensions still fail clearly at build time rather than failing on device at runtime.

Running a Pure-Python ASGI Server (New in 1.1.2)

Section titled “Running a Pure-Python ASGI Server (New in 1.1.2)”

With ZKite 1.1.2, you can bundle lightweight embedded servers such as Starlette and Uvicorn directly inside your Android app:

pyproject.toml
[project]
name = "my-zkite-app"
version = "0.1.0"
dependencies = [
"starlette==1.8.0",
"uvicorn==0.54.0",
"zkite>=1.1.1",
]

Configure Uvicorn to run on its pure-Python networking stack with asyncio and h11:

import uvicorn
config = uvicorn.Config(
app, # Your ASGI Starlette application
host="0.0.0.0",
port=8767,
loop="asyncio",
http="h11",
lifespan="off",
)

Both zkite dev and production builds share the unified dependency resolver:

  • Live Updates: Editing requirements.txt or pyproject.toml while zkite dev is running refreshes the package set, resolves transitive requirements, transfers new packages to the connected Android device, and reloads the preview live.
  • Automatic Removal: Uninstalled packages are cleanly deleted from managed device files.
  • Resilient Failure Handling: Invalid dependency constraints report an error to your terminal while keeping the existing app state running on device.
  • Dependency Caching (.zkite/dev-dependencies): Resolved package sets are cached locally under .zkite/dev-dependencies. Ordinary source edits reuse the installed package set in milliseconds.
  • Refreshing Unpinned Packages: To force a re-resolution, stop zkite dev, remove .zkite/dev-dependencies, and restart.


To enable network access on Android, declare the INTERNET permission under android in app.json:

app.json
{
"android": {
"permissions": ["INTERNET"]
}
}
  • New projects scaffolded with zkite new include this permission by default.
  • If your application is completely offline, remove "INTERNET" from permissions.

Making Nonblocking HTTPS Requests with Task (New in 1.1.2)

Section titled “Making Nonblocking HTTPS Requests with Task (New in 1.1.2)”

Use the module-level Task API to run blocking HTTP requests outside the UI thread with built-in loading and error states:

import json
from urllib.request import urlopen
from zkite import Button, Column, Task, Text
fetch_weather = Task()
def query_api(city: str):
with urlopen(f"https://api.example.com/weather?city={city}", timeout=10) as resp:
return json.loads(resp.read())
def view():
return Column(
"flex-1 p-6 gap-4 bg-slate-900",
Button(
"p-4 bg-orange-600 rounded-xl",
"Fetch Weather",
on_tap=lambda: fetch_weather.start(query_api, "Tokyo"),
disabled=fetch_weather.loading,
),
Text("text-white text-xl", f"Result: {fetch_weather.data}" if fetch_weather.data else "No data"),
Text("text-red-400", str(fetch_weather.error) if fetch_weather.error else ""),
)

Standard Library Pruning (--no-prune-stdlib)

Section titled “Standard Library Pruning (--no-prune-stdlib)”

ZKite analyzes your code and prunes unused modules from the Python standard library to keep mobile APK sizes minimal.

If your code or a dependency relies on dynamic runtime imports via importlib that static analysis cannot discover, pass --no-prune-stdlib:

Terminal window
zkite run --no-prune-stdlib
zkite build apk --no-prune-stdlib