py-civitai-api 0.1.0__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.
- py_civitai_api-0.1.0/PKG-INFO +103 -0
- py_civitai_api-0.1.0/README.md +65 -0
- py_civitai_api-0.1.0/pyproject.toml +100 -0
- py_civitai_api-0.1.0/src/civitai_api/__init__.py +83 -0
- py_civitai_api-0.1.0/src/civitai_api/_internal/__init__.py +0 -0
- py_civitai_api-0.1.0/src/civitai_api/_internal/base_client.py +488 -0
- py_civitai_api-0.1.0/src/civitai_api/_internal/client.py +164 -0
- py_civitai_api-0.1.0/src/civitai_api/_internal/config.py +55 -0
- py_civitai_api-0.1.0/src/civitai_api/_internal/exceptions.py +138 -0
- py_civitai_api-0.1.0/src/civitai_api/_internal/oauth2.py +542 -0
- py_civitai_api-0.1.0/src/civitai_api/_internal/pagination.py +213 -0
- py_civitai_api-0.1.0/src/civitai_api/_internal/resource.py +34 -0
- py_civitai_api-0.1.0/src/civitai_api/_internal/types.py +44 -0
- py_civitai_api-0.1.0/src/civitai_api/_internal/utils.py +20 -0
- py_civitai_api-0.1.0/src/civitai_api/cli/__init__.py +1 -0
- py_civitai_api-0.1.0/src/civitai_api/cli/main.py +507 -0
- py_civitai_api-0.1.0/src/civitai_api/py.typed +0 -0
- py_civitai_api-0.1.0/src/civitai_api/resources/__init__.py +29 -0
- py_civitai_api-0.1.0/src/civitai_api/resources/creators.py +77 -0
- py_civitai_api-0.1.0/src/civitai_api/resources/enums.py +31 -0
- py_civitai_api-0.1.0/src/civitai_api/resources/images.py +126 -0
- py_civitai_api-0.1.0/src/civitai_api/resources/model_versions.py +90 -0
- py_civitai_api-0.1.0/src/civitai_api/resources/models.py +228 -0
- py_civitai_api-0.1.0/src/civitai_api/resources/tags.py +77 -0
- py_civitai_api-0.1.0/src/civitai_api/resources/users.py +54 -0
- py_civitai_api-0.1.0/src/civitai_api/resources/vault.py +103 -0
- py_civitai_api-0.1.0/src/civitai_api/types/__init__.py +53 -0
- py_civitai_api-0.1.0/src/civitai_api/types/_base.py +20 -0
- py_civitai_api-0.1.0/src/civitai_api/types/creator.py +14 -0
- py_civitai_api-0.1.0/src/civitai_api/types/enums.py +105 -0
- py_civitai_api-0.1.0/src/civitai_api/types/image.py +43 -0
- py_civitai_api-0.1.0/src/civitai_api/types/model.py +114 -0
- py_civitai_api-0.1.0/src/civitai_api/types/tag.py +13 -0
- py_civitai_api-0.1.0/src/civitai_api/types/user.py +23 -0
- py_civitai_api-0.1.0/src/civitai_api/types/vault.py +27 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: py-civitai-api
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Unofficial Python client for the CivitAI API (sync + async)
|
|
5
|
+
Keywords: civitai,api,sdk,stable-diffusion,ai,image-generation
|
|
6
|
+
License: MIT
|
|
7
|
+
Classifier: Intended Audience :: Developers
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
10
|
+
Classifier: Typing :: Typed
|
|
11
|
+
Requires-Dist: httpx>=0.28
|
|
12
|
+
Requires-Dist: pydantic>=2.13
|
|
13
|
+
Requires-Dist: typing-extensions>=4.15
|
|
14
|
+
Requires-Dist: typer>=0.26.7 ; extra == 'cli'
|
|
15
|
+
Requires-Dist: rich>=15 ; extra == 'cli'
|
|
16
|
+
Requires-Dist: jmespath>=1.1 ; extra == 'cli'
|
|
17
|
+
Requires-Dist: pytest>=9 ; extra == 'dev'
|
|
18
|
+
Requires-Dist: pytest-asyncio>=1.4 ; extra == 'dev'
|
|
19
|
+
Requires-Dist: pytest-cov>=7.1.0 ; extra == 'dev'
|
|
20
|
+
Requires-Dist: respx>=0.23 ; extra == 'dev'
|
|
21
|
+
Requires-Dist: ruff>=0.15.15 ; extra == 'dev'
|
|
22
|
+
Requires-Dist: poethepoet>=0.46 ; extra == 'dev'
|
|
23
|
+
Requires-Dist: mypy>=2.1.0 ; extra == 'dev'
|
|
24
|
+
Requires-Dist: types-jmespath>=1.1 ; extra == 'dev'
|
|
25
|
+
Requires-Dist: typer>=0.26.7 ; extra == 'dev'
|
|
26
|
+
Requires-Dist: jmespath>=1.1 ; extra == 'dev'
|
|
27
|
+
Requires-Dist: sphinx>=8 ; extra == 'docs'
|
|
28
|
+
Requires-Dist: furo>=2024 ; extra == 'docs'
|
|
29
|
+
Requires-Dist: myst-parser>=4 ; extra == 'docs'
|
|
30
|
+
Requires-Python: >=3.12
|
|
31
|
+
Project-URL: Homepage, https://github.com/mcriley821/civitai-api
|
|
32
|
+
Project-URL: Repository, https://github.com/mcriley821/civitai-api
|
|
33
|
+
Project-URL: Bug Tracker, https://github.com/mcriley821/civitai-api/issues
|
|
34
|
+
Provides-Extra: cli
|
|
35
|
+
Provides-Extra: dev
|
|
36
|
+
Provides-Extra: docs
|
|
37
|
+
Description-Content-Type: text/markdown
|
|
38
|
+
|
|
39
|
+
# civitai-api
|
|
40
|
+
|
|
41
|
+
[](https://github.com/mcriley821/civitai-api/actions/workflows/ci.yml)
|
|
42
|
+
|
|
43
|
+
[](https://codecov.io/gh/mcriley821/civitai-api)
|
|
44
|
+
|
|
45
|
+
Unofficial Python client for the [CivitAI API](https://developer.civitai.com/site/) — sync and async.
|
|
46
|
+
|
|
47
|
+
## Install
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pip install py-civitai-api
|
|
51
|
+
|
|
52
|
+
# with CLI
|
|
53
|
+
pip install "py-civitai-api[cli]"
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Quick start
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
from civitai_api import CivitAI
|
|
60
|
+
|
|
61
|
+
# api key or CIVITAI_API_KEY env var
|
|
62
|
+
with CivitAI(api_key="...") as client:
|
|
63
|
+
for model in client.models.list(query="dreamshaper", limit=5).auto_paging_iter():
|
|
64
|
+
print(model.name, model.id)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Async
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
import asyncio
|
|
71
|
+
from civitai_api import AsyncCivitAI
|
|
72
|
+
|
|
73
|
+
async def main():
|
|
74
|
+
async with AsyncCivitAI() as client:
|
|
75
|
+
version = await client.model_versions.retrieve(12345)
|
|
76
|
+
print(version.name)
|
|
77
|
+
|
|
78
|
+
asyncio.run(main())
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### CLI
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
civitai auth login
|
|
85
|
+
civitai models list --query dreamshaper --limit 5
|
|
86
|
+
civitai models get 12345
|
|
87
|
+
civitai images list --model-id 12345
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Development
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
git clone https://github.com/mcriley821/civitai-api
|
|
94
|
+
cd civitai-api
|
|
95
|
+
uv sync --extra dev
|
|
96
|
+
uv run poe install-hooks # install pre-commit hook (runs lint + typecheck + test)
|
|
97
|
+
uv run poe check # lint + typecheck + test
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Note
|
|
101
|
+
|
|
102
|
+
Built with AI assistance ([Claude](https://claude.ai), Anthropic). All code is reviewed by the author.
|
|
103
|
+
Not affiliated with or endorsed by CivitAI.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# civitai-api
|
|
2
|
+
|
|
3
|
+
[](https://github.com/mcriley821/civitai-api/actions/workflows/ci.yml)
|
|
4
|
+
|
|
5
|
+
[](https://codecov.io/gh/mcriley821/civitai-api)
|
|
6
|
+
|
|
7
|
+
Unofficial Python client for the [CivitAI API](https://developer.civitai.com/site/) — sync and async.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install py-civitai-api
|
|
13
|
+
|
|
14
|
+
# with CLI
|
|
15
|
+
pip install "py-civitai-api[cli]"
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Quick start
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
from civitai_api import CivitAI
|
|
22
|
+
|
|
23
|
+
# api key or CIVITAI_API_KEY env var
|
|
24
|
+
with CivitAI(api_key="...") as client:
|
|
25
|
+
for model in client.models.list(query="dreamshaper", limit=5).auto_paging_iter():
|
|
26
|
+
print(model.name, model.id)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Async
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
import asyncio
|
|
33
|
+
from civitai_api import AsyncCivitAI
|
|
34
|
+
|
|
35
|
+
async def main():
|
|
36
|
+
async with AsyncCivitAI() as client:
|
|
37
|
+
version = await client.model_versions.retrieve(12345)
|
|
38
|
+
print(version.name)
|
|
39
|
+
|
|
40
|
+
asyncio.run(main())
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### CLI
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
civitai auth login
|
|
47
|
+
civitai models list --query dreamshaper --limit 5
|
|
48
|
+
civitai models get 12345
|
|
49
|
+
civitai images list --model-id 12345
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Development
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
git clone https://github.com/mcriley821/civitai-api
|
|
56
|
+
cd civitai-api
|
|
57
|
+
uv sync --extra dev
|
|
58
|
+
uv run poe install-hooks # install pre-commit hook (runs lint + typecheck + test)
|
|
59
|
+
uv run poe check # lint + typecheck + test
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Note
|
|
63
|
+
|
|
64
|
+
Built with AI assistance ([Claude](https://claude.ai), Anthropic). All code is reviewed by the author.
|
|
65
|
+
Not affiliated with or endorsed by CivitAI.
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["uv_build>=0.11.19,<0.12"]
|
|
3
|
+
build-backend = "uv_build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "py-civitai-api"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Unofficial Python client for the CivitAI API (sync + async)"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { text = "MIT" }
|
|
11
|
+
requires-python = ">=3.12"
|
|
12
|
+
keywords = ["civitai", "api", "sdk", "stable-diffusion", "ai", "image-generation"]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Intended Audience :: Developers",
|
|
15
|
+
"License :: OSI Approved :: MIT License",
|
|
16
|
+
"Programming Language :: Python :: 3.12",
|
|
17
|
+
"Typing :: Typed",
|
|
18
|
+
]
|
|
19
|
+
dependencies = [
|
|
20
|
+
"httpx>=0.28",
|
|
21
|
+
"pydantic>=2.13",
|
|
22
|
+
"typing-extensions>=4.15",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
[project.optional-dependencies]
|
|
26
|
+
cli = ["typer>=0.26.7", "rich>=15", "jmespath>=1.1"]
|
|
27
|
+
dev = [
|
|
28
|
+
"pytest>=9",
|
|
29
|
+
"pytest-asyncio>=1.4",
|
|
30
|
+
"pytest-cov>=7.1.0",
|
|
31
|
+
"respx>=0.23",
|
|
32
|
+
"ruff>=0.15.15",
|
|
33
|
+
"poethepoet>=0.46",
|
|
34
|
+
"mypy>=2.1.0",
|
|
35
|
+
"types-jmespath>=1.1",
|
|
36
|
+
"typer>=0.26.7",
|
|
37
|
+
"jmespath>=1.1",
|
|
38
|
+
]
|
|
39
|
+
docs = [
|
|
40
|
+
"sphinx>=8",
|
|
41
|
+
"furo>=2024",
|
|
42
|
+
"myst-parser>=4",
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
[project.scripts]
|
|
46
|
+
civitai = "civitai_api.cli.main:app"
|
|
47
|
+
|
|
48
|
+
[project.urls]
|
|
49
|
+
Homepage = "https://github.com/mcriley821/civitai-api"
|
|
50
|
+
Repository = "https://github.com/mcriley821/civitai-api"
|
|
51
|
+
"Bug Tracker" = "https://github.com/mcriley821/civitai-api/issues"
|
|
52
|
+
|
|
53
|
+
[tool.uv]
|
|
54
|
+
package = true
|
|
55
|
+
|
|
56
|
+
[tool.uv.build-backend]
|
|
57
|
+
module-name = "civitai_api"
|
|
58
|
+
|
|
59
|
+
[tool.ruff]
|
|
60
|
+
src = ["src"]
|
|
61
|
+
line-length = 120
|
|
62
|
+
target-version = "py312"
|
|
63
|
+
|
|
64
|
+
[tool.ruff.lint]
|
|
65
|
+
select = ["ALL"]
|
|
66
|
+
ignore = ["PLR0913", "COM812"]
|
|
67
|
+
|
|
68
|
+
[tool.ruff.lint.pydocstyle]
|
|
69
|
+
convention = "pep257"
|
|
70
|
+
|
|
71
|
+
[tool.ruff.lint.per-file-ignores]
|
|
72
|
+
"tests/**" = ["S101", "S106"]
|
|
73
|
+
|
|
74
|
+
[tool.ruff.format]
|
|
75
|
+
docstring-code-format = true
|
|
76
|
+
|
|
77
|
+
[tool.mypy]
|
|
78
|
+
python_version = "3.12"
|
|
79
|
+
strict = true
|
|
80
|
+
ignore_missing_imports = false
|
|
81
|
+
|
|
82
|
+
[tool.pytest.ini_options]
|
|
83
|
+
asyncio_mode = "auto"
|
|
84
|
+
testpaths = ["tests"]
|
|
85
|
+
|
|
86
|
+
[tool.poe.tasks]
|
|
87
|
+
lint = "ruff check src tests"
|
|
88
|
+
format = "ruff format src tests"
|
|
89
|
+
typecheck = "mypy src"
|
|
90
|
+
test = "pytest tests/"
|
|
91
|
+
coverage = "pytest --cov-report=term-missing --cov=civitai_api tests/"
|
|
92
|
+
coverage-ci = "pytest --cov-report=xml --cov=civitai_api --cov-branch tests/"
|
|
93
|
+
install-hooks = "cp scripts/pre-commit .git/hooks/pre-commit"
|
|
94
|
+
docs = "sphinx-build -b html docs/source docs/build/html"
|
|
95
|
+
|
|
96
|
+
[tool.poe.tasks.docs-clean]
|
|
97
|
+
shell = "rm -rf docs/build"
|
|
98
|
+
|
|
99
|
+
[tool.poe.tasks.check]
|
|
100
|
+
sequence = ["lint", "typecheck", "test"]
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"""civitai_api — unofficial Python client for the CivitAI API."""
|
|
2
|
+
|
|
3
|
+
from importlib.metadata import version as get_version
|
|
4
|
+
|
|
5
|
+
__version__ = get_version("py-civitai-api")
|
|
6
|
+
|
|
7
|
+
from ._internal.client import AsyncCivitAI, CivitAI
|
|
8
|
+
from ._internal.exceptions import (
|
|
9
|
+
APIConnectionError,
|
|
10
|
+
APIError,
|
|
11
|
+
APITimeoutError,
|
|
12
|
+
AuthenticationError,
|
|
13
|
+
CivitAIError,
|
|
14
|
+
InternalServerError,
|
|
15
|
+
NotFoundError,
|
|
16
|
+
PermissionDeniedError,
|
|
17
|
+
RateLimitError,
|
|
18
|
+
)
|
|
19
|
+
from ._internal.oauth2 import (
|
|
20
|
+
FileTokenStore,
|
|
21
|
+
MemoryTokenStore,
|
|
22
|
+
OAuth2Config,
|
|
23
|
+
OAuth2Token,
|
|
24
|
+
Scope,
|
|
25
|
+
run_pkce_flow,
|
|
26
|
+
)
|
|
27
|
+
from ._internal.types import NULL
|
|
28
|
+
from .types import (
|
|
29
|
+
Creator,
|
|
30
|
+
Image,
|
|
31
|
+
ImageMeta,
|
|
32
|
+
ImageTag,
|
|
33
|
+
Me,
|
|
34
|
+
Model,
|
|
35
|
+
ModelFile,
|
|
36
|
+
ModelImage,
|
|
37
|
+
ModelStats,
|
|
38
|
+
ModelVersion,
|
|
39
|
+
ModelVersionFile,
|
|
40
|
+
ModelVersionStats,
|
|
41
|
+
Tag,
|
|
42
|
+
User,
|
|
43
|
+
VaultItem,
|
|
44
|
+
VaultStatus,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
__all__ = [
|
|
48
|
+
"NULL",
|
|
49
|
+
"APIConnectionError",
|
|
50
|
+
"APIError",
|
|
51
|
+
"APITimeoutError",
|
|
52
|
+
"AsyncCivitAI",
|
|
53
|
+
"AuthenticationError",
|
|
54
|
+
"CivitAI",
|
|
55
|
+
"CivitAIError",
|
|
56
|
+
"Creator",
|
|
57
|
+
"FileTokenStore",
|
|
58
|
+
"Image",
|
|
59
|
+
"ImageMeta",
|
|
60
|
+
"ImageTag",
|
|
61
|
+
"InternalServerError",
|
|
62
|
+
"Me",
|
|
63
|
+
"MemoryTokenStore",
|
|
64
|
+
"Model",
|
|
65
|
+
"ModelFile",
|
|
66
|
+
"ModelImage",
|
|
67
|
+
"ModelStats",
|
|
68
|
+
"ModelVersion",
|
|
69
|
+
"ModelVersionFile",
|
|
70
|
+
"ModelVersionStats",
|
|
71
|
+
"NotFoundError",
|
|
72
|
+
"OAuth2Config",
|
|
73
|
+
"OAuth2Token",
|
|
74
|
+
"PermissionDeniedError",
|
|
75
|
+
"RateLimitError",
|
|
76
|
+
"Scope",
|
|
77
|
+
"Tag",
|
|
78
|
+
"User",
|
|
79
|
+
"VaultItem",
|
|
80
|
+
"VaultStatus",
|
|
81
|
+
"__version__",
|
|
82
|
+
"run_pkce_flow",
|
|
83
|
+
]
|
|
File without changes
|