Skip to content

Commit 07f0500

Browse files
committed
Add fist version of a TrailBase Python client including tests and CI setup
1 parent 39acdf9 commit 07f0500

File tree

16 files changed

+893
-7
lines changed

16 files changed

+893
-7
lines changed

.github/workflows/test.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,10 @@ jobs:
3636
with:
3737
toolchain: stable
3838
default: true
39-
- uses: actions/setup-python@v3
39+
- uses: actions/setup-python@v5
40+
with:
41+
python-version: '3.13'
42+
- name: Poetry install
43+
run: |
44+
pipx install poetry && poetry -C client/trailbase-py install
4045
- uses: pre-commit/[email protected]

.pre-commit-config.yaml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ repos:
7979

8080
- id: build_website
8181
name: Build Website
82-
entry: sh -c 'cd docs && pnpm i && pnpm build'
82+
entry: sh -c 'cd docs && pnpm build'
8383
language: system
8484
types: [file]
8585
files: .*\.(js|mjs|cjs|ts|jsx|tsx|astro)$
@@ -126,3 +126,28 @@ repos:
126126
types: [file]
127127
files: .*\.(cs|csproj)$
128128
pass_filenames: false
129+
130+
### Python client
131+
- id: python_format
132+
name: Python format
133+
entry: poetry -C client/trailbase-py run black client/trailbase-py --check
134+
language: system
135+
types: [file]
136+
files: .*\.(py)$
137+
pass_filenames: false
138+
139+
- id: python_check
140+
name: Python check
141+
entry: poetry -C client/trailbase-py run pyright client/trailbase-py
142+
language: system
143+
types: [file]
144+
files: .*\.(py)$
145+
pass_filenames: false
146+
147+
- id: python_test
148+
name: Python test
149+
entry: poetry -C client/trailbase-py run pytest
150+
language: system
151+
types: [file]
152+
files: .*\.(py)$
153+
pass_filenames: false

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ format:
88
cargo +nightly fmt; \
99
dart format client/trailbase-dart/ examples/blog/flutter/; \
1010
txtpbfmt `find . -regex ".*.textproto"`; \
11-
dotnet format client/trailbase-dotnet
11+
dotnet format client/trailbase-dotnet; \
12+
poetry -C client/trailbase-py run black client/trailbase-py
1213

1314
check:
1415
pnpm -r check; \
1516
cargo clippy --workspace --no-deps; \
1617
dart analyze client/trailbase-dart examples/blog/flutter; \
17-
dotnet format client/trailbase-dotnet --verify-no-changes
18+
dotnet format client/trailbase-dotnet --verify-no-changes; \
19+
poetry -C client/trailbase-py run pyright
1820

1921
docker:
2022
docker build . -t trailbase/trailbase

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ Moreover, client packages and containers are available via:
6464
- [JavaScript/Typescript client](https://www.npmjs.com/package/trailbase)
6565
- [Dart/Flutter client](https://pub.dev/packages/trailbase)
6666
- [C#/.Net](https://www.nuget.org/packages/TrailBase/)
67+
- [Python](https://github.com/trailbaseio/trailbase/tree/main/client/trailbase-py)
6768

6869
## Running
6970

client/trailbase-dart/test/trailbase_test.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,14 @@ Future<void> main() async {
149149
expect(RecordId.uuid(record.id) == ids[0], isTrue);
150150

151151
expect(record.textNotNull, messages[0]);
152+
153+
final updatedMessage = 'dart client updated test 0: ${now}';
154+
await api.update(ids[0], {'text_not_null': updatedMessage});
155+
final updatedRecord = SimpleStrict.fromJson(await api.read(ids[0]));
156+
expect(updatedRecord.textNotNull, updatedMessage);
157+
158+
await api.delete(ids[0]);
159+
expect(() async => await api.read(ids[0]), throwsException);
152160
});
153161
});
154162
}

client/trailbase-dotnet/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# TrailBase client library for .NET and MAUI
1+
# TrailBase Client Library for .NET and MAUI
22

33
TrailBase is a [blazingly](https://trailbase.io/reference/benchmarks/) fast,
44
single-file, open-source application server with type-safe APIs, built-in

client/trailbase-py/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
**/__pycache__/
2+
poetry.lock

client/trailbase-py/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# TrailBase Client for Python
2+
3+
TrailBase is a [blazingly](https://trailbase.io/reference/benchmarks/) fast,
4+
single-file, open-source application server with type-safe APIs, built-in
5+
JS/ES6/TS Runtime, Auth, and Admin UI built on Rust+SQLite+V8.
6+
7+
For more context, documentation, and an online demo, check out our website
8+
[trailbase.io](https://trailbase.io).

client/trailbase-py/poetry.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[virtualenvs]
2+
in-project = true
3+
create = true

client/trailbase-py/pyproject.toml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[tool.poetry]
2+
name = "trailbase"
3+
version = "0.1.0"
4+
description = ""
5+
authors = ["TrailBase <[email protected]>"]
6+
readme = "README.md"
7+
8+
[tool.poetry.dependencies]
9+
python = "^3.12"
10+
httpx = "^0.27.2"
11+
pyjwt = "^2.10.0"
12+
cryptography = "^43.0.3"
13+
14+
[tool.poetry.group.dev.dependencies]
15+
pytest = "^8.3.3"
16+
black = "^24.10.0"
17+
pyright = "^1.1.389"
18+
19+
[build-system]
20+
requires = ["poetry-core"]
21+
build-backend = "poetry.core.masonry.api"
22+
23+
[tool.black]
24+
line-length = 108
25+
26+
[tool.pyright]
27+
venvPath = "."
28+
venv = ".venv"

0 commit comments

Comments
 (0)