tortoise-extensions 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. tortoise_extensions-0.0.1/.github/workflows/CI.yaml +13 -0
  2. tortoise_extensions-0.0.1/.github/workflows/quality.yaml +35 -0
  3. tortoise_extensions-0.0.1/.github/workflows/release.yaml +102 -0
  4. tortoise_extensions-0.0.1/.gitignore +69 -0
  5. tortoise_extensions-0.0.1/LICENSE +15 -0
  6. tortoise_extensions-0.0.1/PKG-INFO +148 -0
  7. tortoise_extensions-0.0.1/README.md +117 -0
  8. tortoise_extensions-0.0.1/docs/api.md +33 -0
  9. tortoise_extensions-0.0.1/docs/contributing.md +28 -0
  10. tortoise_extensions-0.0.1/docs/index.md +37 -0
  11. tortoise_extensions-0.0.1/docs/usage.md +90 -0
  12. tortoise_extensions-0.0.1/licensor-config.yaml +5 -0
  13. tortoise_extensions-0.0.1/pdm.lock +946 -0
  14. tortoise_extensions-0.0.1/pyproject.toml +154 -0
  15. tortoise_extensions-0.0.1/renovate.json +18 -0
  16. tortoise_extensions-0.0.1/src/tortoise_extensions/__init__.py +10 -0
  17. tortoise_extensions-0.0.1/src/tortoise_extensions/_version.py +24 -0
  18. tortoise_extensions-0.0.1/src/tortoise_extensions/py.typed +0 -0
  19. tortoise_extensions-0.0.1/src/tortoise_extensions/pydantic.py +74 -0
  20. tortoise_extensions-0.0.1/src/tortoise_extensions/s3.py +279 -0
  21. tortoise_extensions-0.0.1/src/tortoise_extensions/uuid6.py +74 -0
  22. tortoise_extensions-0.0.1/tests/__init__.py +2 -0
  23. tortoise_extensions-0.0.1/tests/conftest.py +28 -0
  24. tortoise_extensions-0.0.1/tests/models.py +44 -0
  25. tortoise_extensions-0.0.1/tests/test_pydantic_field.py +54 -0
  26. tortoise_extensions-0.0.1/tests/test_s3_field.py +138 -0
  27. tortoise_extensions-0.0.1/tests/test_uuid6_field.py +66 -0
  28. tortoise_extensions-0.0.1/zensical.toml +61 -0
@@ -0,0 +1,13 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: ["master"]
6
+ pull_request:
7
+ branches: ["master"]
8
+
9
+ jobs:
10
+ quality:
11
+ uses: ./.github/workflows/quality.yaml
12
+ permissions:
13
+ contents: read
@@ -0,0 +1,35 @@
1
+ name: Quality Checks
2
+
3
+ on:
4
+ workflow_call:
5
+ workflow_dispatch:
6
+
7
+ jobs:
8
+ quality:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
12
+
13
+ - name: Setup PDM
14
+ uses: pdm-project/setup-pdm@544d7237314ee09c256785bd360f6b30add38b37 # v4.6
15
+ with:
16
+ cache: true
17
+ python-version-file: "pyproject.toml"
18
+
19
+ - name: Install dependencies
20
+ run: pdm install --frozen-lockfile -G dev -G test -G docs
21
+
22
+ - name: Format Check
23
+ run: pdm run format:check
24
+
25
+ - name: Lint Check
26
+ run: pdm run lint
27
+
28
+ - name: Type Check
29
+ run: pdm run typecheck
30
+
31
+ - name: Tests
32
+ run: pdm run tests
33
+
34
+ - name: Build docs
35
+ run: pdm run docs:build
@@ -0,0 +1,102 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ tags: ["v*.*.*"]
6
+
7
+ jobs:
8
+ quality:
9
+ uses: ./.github/workflows/quality.yaml
10
+ permissions:
11
+ contents: read
12
+
13
+ get-version:
14
+ name: Get Version
15
+ runs-on: ubuntu-latest
16
+ outputs:
17
+ version: ${{ steps.version.outputs.version }}
18
+ steps:
19
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
20
+ with:
21
+ fetch-depth: 0
22
+
23
+ - name: Setup PDM
24
+ uses: pdm-project/setup-pdm@544d7237314ee09c256785bd360f6b30add38b37 # v4.6
25
+ with:
26
+ cache: true
27
+ python-version-file: "pyproject.toml"
28
+
29
+ - name: Install dependencies
30
+ run: pdm install --frozen-lockfile
31
+
32
+ - name: Build package
33
+ run: pdm build
34
+
35
+ - name: Get version
36
+ id: version
37
+ run: |
38
+ VERSION=$(pdm run python -c "from tortoise_extensions._version import __version__; print(__version__)")
39
+ echo "version=$VERSION" >> "$GITHUB_OUTPUT"
40
+
41
+ publish:
42
+ name: Publish
43
+ runs-on: ubuntu-latest
44
+ needs: [quality, get-version]
45
+ permissions:
46
+ id-token: write
47
+ contents: read
48
+ environment:
49
+ name: pypi
50
+ url: https://pypi.org/project/tortoise-extensions/${{ needs.get-version.outputs.version }}/
51
+ steps:
52
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
53
+ with:
54
+ fetch-depth: 0
55
+
56
+ - name: Setup PDM
57
+ uses: pdm-project/setup-pdm@544d7237314ee09c256785bd360f6b30add38b37 # v4.6
58
+ with:
59
+ cache: true
60
+ python-version-file: "pyproject.toml"
61
+
62
+ - name: Install dependencies
63
+ run: pdm install --frozen-lockfile
64
+
65
+ - name: Build and Publish
66
+ run: pdm publish
67
+
68
+ deploy-docs:
69
+ needs: [quality, publish]
70
+ name: Deploy docs
71
+ permissions:
72
+ contents: read
73
+ pages: write
74
+ id-token: write
75
+ environment:
76
+ name: github-pages
77
+ url: ${{ steps.deployment.outputs.page_url }}
78
+ runs-on: ubuntu-latest
79
+ steps:
80
+ - uses: actions/configure-pages@45bfe0192ca1faeb007ade9deae92b16b8254a0d # v6
81
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
82
+
83
+ - name: Setup PDM
84
+ uses: pdm-project/setup-pdm@544d7237314ee09c256785bd360f6b30add38b37 # v4.6
85
+ with:
86
+ cache: true
87
+ python-version-file: "pyproject.toml"
88
+
89
+ - name: Install dependencies
90
+ run: pdm install --frozen-lockfile -G dev -G test -G docs
91
+
92
+ - name: Build docs
93
+ run: pdm run docs:build
94
+
95
+ - name: Upload docs
96
+ uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5
97
+ with:
98
+ path: site
99
+
100
+ - name: Deploy docs
101
+ uses: actions/deploy-pages@368f82528645a54fb793d4d04e342629a3f51346 # v5.0.1
102
+ id: deployment
@@ -0,0 +1,69 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # Unit test / coverage reports
30
+ htmlcov/
31
+ .tox/
32
+ .nox/
33
+ .coverage
34
+ .coverage.*
35
+ .cache
36
+ nosetests.xml
37
+ coverage.xml
38
+ *.cover
39
+ *.py.cover
40
+ .hypothesis/
41
+ .pytest_cache/
42
+ cover/
43
+
44
+ # pdm
45
+ .pdm-python
46
+ .pdm-build/
47
+ src/tortoise_extensions/_version.py
48
+
49
+ # Environments
50
+ .env
51
+ .envrc
52
+ .venv
53
+ env/
54
+ venv/
55
+ ENV/
56
+ env.bak/
57
+ venv.bak/
58
+
59
+ # Ruff
60
+ .ruff_cache/
61
+
62
+ # PyPI configuration file
63
+ .pypirc
64
+
65
+ # IDE
66
+ .idea/
67
+ .vscode/
68
+
69
+ /site/
@@ -0,0 +1,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2026 NiceBots.xyz
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14
+ OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
+ PERFORMANCE OF THIS SOFTWARE.
@@ -0,0 +1,148 @@
1
+ Metadata-Version: 2.5
2
+ Name: tortoise-extensions
3
+ Version: 0.0.1
4
+ Summary: Extension field types for Tortoise ORM
5
+ Project-URL: Documentation, https://docs.nicebots.xyz/tortoise-extensions/
6
+ Project-URL: Repository, https://github.com/nicebots-xyz/tortoise-extensions
7
+ Project-URL: Issues, https://github.com/nicebots-xyz/tortoise-extensions/issues
8
+ Project-URL: Source Archive, https://github.com/nicebots-xyz/tortoise-extensions/archive/be1848c93a01c69d6ccce132b5820ad41b5337ee.zip
9
+ Author-email: Paillat-dev <me@paillat.dev>
10
+ License-Expression: ISC
11
+ License-File: LICENSE
12
+ Keywords: fields,orm,pydantic,s3,tortoise,uuid6
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: ISC License (ISCL)
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Typing :: Typed
21
+ Requires-Python: <3.15,>=3.12
22
+ Requires-Dist: tortoise-orm<1.0.0,>=0.25.4
23
+ Provides-Extra: pydantic
24
+ Requires-Dist: pydantic~=2.0; extra == 'pydantic'
25
+ Provides-Extra: s3
26
+ Requires-Dist: obstore~=0.12.1; extra == 's3'
27
+ Requires-Dist: uuid6>=2024.0.0; (python_version < '3.14') and extra == 's3'
28
+ Provides-Extra: uuid6
29
+ Requires-Dist: uuid6>=2024.0.0; extra == 'uuid6'
30
+ Description-Content-Type: text/markdown
31
+
32
+ <!--
33
+ SPDX-License-Identifier: ISC
34
+ Copyright: 2026 NiceBots.xyz
35
+ -->
36
+ # tortoise-extensions
37
+
38
+ Optional extension field types for [Tortoise ORM](https://tortoise.github.io/). This package targets **Tortoise ORM 0.25.4 and later, but before 1.0** — Tortoise 1.x is not supported yet.
39
+
40
+ ## Install
41
+
42
+ Base package (requires Tortoise ORM in the supported range):
43
+
44
+ ```bash
45
+ pip install tortoise-extensions
46
+ ```
47
+
48
+ Optional extras:
49
+
50
+ ```bash
51
+ pip install tortoise-extensions[pydantic]
52
+ pip install tortoise-extensions[uuid6]
53
+ pip install tortoise-extensions[s3]
54
+ pip install tortoise-extensions[pydantic,uuid6,s3]
55
+ ```
56
+
57
+ ## Usage
58
+
59
+ ### Pydantic JSON (`pydantic` extra)
60
+
61
+ ```python
62
+ from pydantic import BaseModel
63
+ from tortoise.models import Model
64
+
65
+ from tortoise_extensions.pydantic import PydanticJSONField
66
+
67
+
68
+ class Settings(BaseModel):
69
+ theme: str = "dark"
70
+
71
+
72
+ class AppConfig(Model):
73
+ settings: PydanticJSONField[Settings] = PydanticJSONField(Settings, default=Settings)
74
+
75
+ class Meta:
76
+ table = "app_configs"
77
+ ```
78
+
79
+ `PydanticJSONField` round-trips through your Pydantic model: it accepts dicts from PostgreSQL JSONB, JSON strings from SQLite, and serializes models with `model_dump(mode="json")` on save.
80
+
81
+ ### UUID v6+ (`uuid6` extra)
82
+
83
+ ```python
84
+ from tortoise.models import Model
85
+
86
+ from tortoise_extensions.uuid6 import FutureUUIDField
87
+
88
+
89
+ class Item(Model):
90
+ id: FutureUUIDField = FutureUUIDField(primary_key=True)
91
+
92
+ class Meta:
93
+ table = "items"
94
+ ```
95
+
96
+ Primary keys without an explicit `default` receive a UUID7 from the [`uuid6`](https://pypi.org/project/uuid6/) package. PostgreSQL uses the native `UUID` column type; other backends store `CHAR(36)`.
97
+
98
+ ### S3 objects (`s3` extra)
99
+
100
+ ```python
101
+ from tortoise.models import Model
102
+
103
+ from tortoise_extensions.s3 import S3Field
104
+
105
+
106
+ class Attachment(Model):
107
+ file = S3Field(null=True)
108
+
109
+ class Meta:
110
+ table = "attachments"
111
+ ```
112
+
113
+ The column stores an object key and loads as an `S3Object` handle (`read`, `write`, `delete`, `get_or_write`, ...) backed by [`obstore`](https://pypi.org/project/obstore/). Storages are registered per Tortoise app with `init_storages`, each with its own `ssl` setting. See the [usage docs](https://docs.nicebots.xyz/tortoise-extensions/usage/) for details.
114
+
115
+ ## Contributing a new extension
116
+
117
+ 1. **Open an issue first** — describe the field behavior, SQL types per backend, which Tortoise versions you need, and the proposed optional-extra name (e.g. `pip install tortoise-extensions[myextra]`).
118
+ 2. After maintainers agree on the design, open a PR that includes:
119
+ - Implementation in `src/tortoise_extensions/<module>.py`
120
+ - Tests under `tests/`
121
+ - An entry in `[project.optional-dependencies]` if the field needs third-party packages
122
+ - README and docs updates for the new field
123
+ - ISC SPDX headers on new files (`licensor-config.yaml` applies)
124
+ 3. Run `pdm run quality` locally before pushing.
125
+
126
+ ## Documentation
127
+
128
+ Published at [docs.nicebots.xyz/tortoise-extensions](https://docs.nicebots.xyz/tortoise-extensions/).
129
+
130
+ ```bash
131
+ pdm install -G docs
132
+ pdm run docs:build
133
+ pdm run docs:preview
134
+ pdm run docs:dev
135
+ ```
136
+
137
+ ## Development
138
+
139
+ ```bash
140
+ pdm install -G dev -G test -G docs
141
+ pdm run quality
142
+ ```
143
+
144
+ Public APIs use [Google-style docstrings](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings); `ruff` enforces this via `convention = "google"`.
145
+
146
+ ## License
147
+
148
+ ISC.
@@ -0,0 +1,117 @@
1
+ <!--
2
+ SPDX-License-Identifier: ISC
3
+ Copyright: 2026 NiceBots.xyz
4
+ -->
5
+ # tortoise-extensions
6
+
7
+ Optional extension field types for [Tortoise ORM](https://tortoise.github.io/). This package targets **Tortoise ORM 0.25.4 and later, but before 1.0** — Tortoise 1.x is not supported yet.
8
+
9
+ ## Install
10
+
11
+ Base package (requires Tortoise ORM in the supported range):
12
+
13
+ ```bash
14
+ pip install tortoise-extensions
15
+ ```
16
+
17
+ Optional extras:
18
+
19
+ ```bash
20
+ pip install tortoise-extensions[pydantic]
21
+ pip install tortoise-extensions[uuid6]
22
+ pip install tortoise-extensions[s3]
23
+ pip install tortoise-extensions[pydantic,uuid6,s3]
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ ### Pydantic JSON (`pydantic` extra)
29
+
30
+ ```python
31
+ from pydantic import BaseModel
32
+ from tortoise.models import Model
33
+
34
+ from tortoise_extensions.pydantic import PydanticJSONField
35
+
36
+
37
+ class Settings(BaseModel):
38
+ theme: str = "dark"
39
+
40
+
41
+ class AppConfig(Model):
42
+ settings: PydanticJSONField[Settings] = PydanticJSONField(Settings, default=Settings)
43
+
44
+ class Meta:
45
+ table = "app_configs"
46
+ ```
47
+
48
+ `PydanticJSONField` round-trips through your Pydantic model: it accepts dicts from PostgreSQL JSONB, JSON strings from SQLite, and serializes models with `model_dump(mode="json")` on save.
49
+
50
+ ### UUID v6+ (`uuid6` extra)
51
+
52
+ ```python
53
+ from tortoise.models import Model
54
+
55
+ from tortoise_extensions.uuid6 import FutureUUIDField
56
+
57
+
58
+ class Item(Model):
59
+ id: FutureUUIDField = FutureUUIDField(primary_key=True)
60
+
61
+ class Meta:
62
+ table = "items"
63
+ ```
64
+
65
+ Primary keys without an explicit `default` receive a UUID7 from the [`uuid6`](https://pypi.org/project/uuid6/) package. PostgreSQL uses the native `UUID` column type; other backends store `CHAR(36)`.
66
+
67
+ ### S3 objects (`s3` extra)
68
+
69
+ ```python
70
+ from tortoise.models import Model
71
+
72
+ from tortoise_extensions.s3 import S3Field
73
+
74
+
75
+ class Attachment(Model):
76
+ file = S3Field(null=True)
77
+
78
+ class Meta:
79
+ table = "attachments"
80
+ ```
81
+
82
+ The column stores an object key and loads as an `S3Object` handle (`read`, `write`, `delete`, `get_or_write`, ...) backed by [`obstore`](https://pypi.org/project/obstore/). Storages are registered per Tortoise app with `init_storages`, each with its own `ssl` setting. See the [usage docs](https://docs.nicebots.xyz/tortoise-extensions/usage/) for details.
83
+
84
+ ## Contributing a new extension
85
+
86
+ 1. **Open an issue first** — describe the field behavior, SQL types per backend, which Tortoise versions you need, and the proposed optional-extra name (e.g. `pip install tortoise-extensions[myextra]`).
87
+ 2. After maintainers agree on the design, open a PR that includes:
88
+ - Implementation in `src/tortoise_extensions/<module>.py`
89
+ - Tests under `tests/`
90
+ - An entry in `[project.optional-dependencies]` if the field needs third-party packages
91
+ - README and docs updates for the new field
92
+ - ISC SPDX headers on new files (`licensor-config.yaml` applies)
93
+ 3. Run `pdm run quality` locally before pushing.
94
+
95
+ ## Documentation
96
+
97
+ Published at [docs.nicebots.xyz/tortoise-extensions](https://docs.nicebots.xyz/tortoise-extensions/).
98
+
99
+ ```bash
100
+ pdm install -G docs
101
+ pdm run docs:build
102
+ pdm run docs:preview
103
+ pdm run docs:dev
104
+ ```
105
+
106
+ ## Development
107
+
108
+ ```bash
109
+ pdm install -G dev -G test -G docs
110
+ pdm run quality
111
+ ```
112
+
113
+ Public APIs use [Google-style docstrings](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings); `ruff` enforces this via `convention = "google"`.
114
+
115
+ ## License
116
+
117
+ ISC.
@@ -0,0 +1,33 @@
1
+ <!--
2
+ SPDX-License-Identifier: ISC
3
+ Copyright: 2026 NiceBots.xyz
4
+ -->
5
+ # API Reference
6
+
7
+ ## Pydantic
8
+
9
+ ::: tortoise_extensions.pydantic
10
+ options:
11
+ members:
12
+ - PydanticJSONField
13
+ show_submodules: false
14
+
15
+ ## UUID6
16
+
17
+ ::: tortoise_extensions.uuid6
18
+ options:
19
+ members:
20
+ - FutureUUIDField
21
+ show_submodules: false
22
+
23
+ ## S3
24
+
25
+ ::: tortoise_extensions.s3
26
+ options:
27
+ members:
28
+ - S3Field
29
+ - S3Object
30
+ - S3Storage
31
+ - init_storages
32
+ - get_store
33
+ show_submodules: false
@@ -0,0 +1,28 @@
1
+ <!--
2
+ SPDX-License-Identifier: ISC
3
+ Copyright: 2026 NiceBots.xyz
4
+ -->
5
+ # Contributing
6
+
7
+ ## Proposing a new extension
8
+
9
+ 1. Open an issue describing the field behavior, SQL types per backend, Tortoise version requirements, and the proposed optional-extra name.
10
+ 2. Wait for maintainer feedback before starting implementation.
11
+
12
+ ## Pull requests
13
+
14
+ Include:
15
+
16
+ - Implementation in `src/tortoise_extensions/<module>.py`
17
+ - Google-style docstrings on public APIs
18
+ - Tests under `tests/`
19
+ - Optional dependency entry in `pyproject.toml` when third-party packages are required
20
+ - Updates to `docs/usage.md` and `docs/api.md` when user-facing behavior changes
21
+
22
+ Run the quality gate locally:
23
+
24
+ ```bash
25
+ pdm install -G dev -G test -G docs
26
+ pdm run quality
27
+ pdm run docs:build
28
+ ```
@@ -0,0 +1,37 @@
1
+ <!--
2
+ SPDX-License-Identifier: ISC
3
+ Copyright: 2026 NiceBots.xyz
4
+ -->
5
+ # tortoise-extensions
6
+
7
+ `tortoise-extensions` provides optional Tortoise ORM field types as install extras.
8
+
9
+ Supported Tortoise ORM versions: **0.25.4 and later, but before 1.0**. Tortoise 1.x is not supported yet.
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ pip install tortoise-extensions[pydantic,uuid6]
15
+ ```
16
+
17
+ See [Usage](usage.md) for field-specific setup.
18
+
19
+ ## Quick example
20
+
21
+ ```python
22
+ from pydantic import BaseModel
23
+ from tortoise.models import Model
24
+
25
+ from tortoise_extensions.pydantic import PydanticJSONField
26
+
27
+
28
+ class Settings(BaseModel):
29
+ theme: str = "dark"
30
+
31
+
32
+ class AppConfig(Model):
33
+ settings: PydanticJSONField[Settings] = PydanticJSONField(Settings, default=Settings)
34
+
35
+ class Meta:
36
+ table = "app_configs"
37
+ ```
@@ -0,0 +1,90 @@
1
+ <!--
2
+ SPDX-License-Identifier: ISC
3
+ Copyright: 2026 NiceBots.xyz
4
+ -->
5
+ # Usage
6
+
7
+ Install the base package plus the extras you need:
8
+
9
+ ```bash
10
+ pip install tortoise-extensions[pydantic]
11
+ pip install tortoise-extensions[uuid6]
12
+ pip install tortoise-extensions[s3]
13
+ pip install tortoise-extensions[pydantic,uuid6,s3]
14
+ ```
15
+
16
+ ## Pydantic JSON field
17
+
18
+ Requires the `pydantic` extra.
19
+
20
+ ```python
21
+ from pydantic import BaseModel
22
+ from tortoise.models import Model
23
+
24
+ from tortoise_extensions.pydantic import PydanticJSONField
25
+
26
+
27
+ class Settings(BaseModel):
28
+ theme: str = "dark"
29
+
30
+
31
+ class AppConfig(Model):
32
+ settings: PydanticJSONField[Settings] = PydanticJSONField(Settings, default=Settings)
33
+
34
+ class Meta:
35
+ table = "app_configs"
36
+ ```
37
+
38
+ `PydanticJSONField` validates JSON using your Pydantic model. It accepts dict values from PostgreSQL JSONB and JSON strings from SQLite.
39
+
40
+ ## UUID v6+ field
41
+
42
+ Requires the `uuid6` extra.
43
+
44
+ ```python
45
+ from tortoise.models import Model
46
+
47
+ from tortoise_extensions.uuid6 import FutureUUIDField
48
+
49
+
50
+ class Item(Model):
51
+ id: FutureUUIDField = FutureUUIDField(primary_key=True)
52
+
53
+ class Meta:
54
+ table = "items"
55
+ ```
56
+
57
+ Primary keys without an explicit `default` are assigned UUID7. PostgreSQL uses the native `UUID` column type; other backends use `CHAR(36)`.
58
+
59
+ ## S3 field
60
+
61
+ Requires the `s3` extra.
62
+
63
+ ```python
64
+ from tortoise.models import Model
65
+
66
+ from tortoise_extensions.s3 import S3Field, S3Storage, init_storages
67
+
68
+
69
+ class Attachment(Model):
70
+ file = S3Field(null=True)
71
+ thumb = S3Field(storage="cdn", null=True)
72
+
73
+
74
+ init_storages(
75
+ {
76
+ "models": S3Storage(endpoint="s3.example.com", bucket="main", access_key="...", secret_key="..."),
77
+ "cdn": S3Storage(endpoint="minio:9000", bucket="cdn", access_key="...", secret_key="...", ssl=False),
78
+ }
79
+ )
80
+
81
+ record = await Attachment.create()
82
+ await record.file.write(b"hello")
83
+ await record.save()
84
+
85
+ data = await record.file.read()
86
+ thumb = await record.thumb.get_or_write(render_thumbnail)
87
+ await record.save()
88
+ ```
89
+
90
+ The column stores the object key (`VARCHAR(1024)`) and loads as an `S3Object` handle backed by [`obstore`](https://pypi.org/project/obstore/).
@@ -0,0 +1,5 @@
1
+ # SPDX-License-Identifier: ISC
2
+ # Copyright: 2026 NiceBots.xyz
3
+ holder: NiceBots.xyz
4
+ spdx: ISC
5
+ year: 2026