Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "1.1.0"
".": "1.1.1"
}
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# Changelog

## 1.1.1 (2024-11-28)

Full Changelog: [v1.1.0...v1.1.1](https://github.com/lumalabs/lumaai-python/compare/v1.1.0...v1.1.1)

### Chores

* **internal:** codegen related update ([#54](https://github.com/lumalabs/lumaai-python/issues/54)) ([e799eff](https://github.com/lumalabs/lumaai-python/commit/e799efff8b54359b6f065c704a283f336037c0b2))
* **internal:** exclude mypy from running on tests ([#55](https://github.com/lumalabs/lumaai-python/issues/55)) ([1f82733](https://github.com/lumalabs/lumaai-python/commit/1f827331631f05ebefabf372398536a75291b658))
* **internal:** fix compat model_dump method when warnings are passed ([#52](https://github.com/lumalabs/lumaai-python/issues/52)) ([38a854e](https://github.com/lumalabs/lumaai-python/commit/38a854ecee6fcf8373d0c024242b6949e5fb11b4))
* rebuild project due to codegen change ([#47](https://github.com/lumalabs/lumaai-python/issues/47)) ([e59029a](https://github.com/lumalabs/lumaai-python/commit/e59029af7a089ae322f230365309b76579a4e336))
* rebuild project due to codegen change ([#49](https://github.com/lumalabs/lumaai-python/issues/49)) ([9d05dc0](https://github.com/lumalabs/lumaai-python/commit/9d05dc05ba43a236d369c75926f199d31df17d46))
* rebuild project due to codegen change ([#50](https://github.com/lumalabs/lumaai-python/issues/50)) ([1951e9d](https://github.com/lumalabs/lumaai-python/commit/1951e9d82921d41675d32e4e0406fae05e4c20eb))
* rebuild project due to codegen change ([#51](https://github.com/lumalabs/lumaai-python/issues/51)) ([5b0dc70](https://github.com/lumalabs/lumaai-python/commit/5b0dc702a4394e9ae3d5d32c1c14066e091f1f28))


### Documentation

* add info log level to readme ([#53](https://github.com/lumalabs/lumaai-python/issues/53)) ([f7ba397](https://github.com/lumalabs/lumaai-python/commit/f7ba397b039b460ee377b6eddd5c5c6f2fa7487f))

## 1.1.0 (2024-10-08)

Full Changelog: [v1.0.2...v1.1.0](https://github.com/lumalabs/lumaai-python/compare/v1.0.2...v1.1.0)
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![PyPI version](https://img.shields.io/pypi/v/lumaai.svg)](https://pypi.org/project/lumaai/)

The LumaAI Python library provides convenient access to the LumaAI REST API from any Python 3.7+
The LumaAI Python library provides convenient access to the LumaAI REST API from any Python 3.8+
application. The library includes type definitions for all request params and response fields,
and offers both synchronous and asynchronous clients powered by [httpx](https://github.com/encode/httpx).

Expand All @@ -26,8 +26,7 @@ import os
from lumaai import LumaAI

client = LumaAI(
# This is the default and can be omitted
auth_token=os.environ.get("LUMAAI_API_KEY"),
auth_token=os.environ.get("LUMAAI_API_KEY"), # This is the default and can be omitted
)

generation = client.generations.create(
Expand All @@ -53,8 +52,7 @@ import asyncio
from lumaai import AsyncLumaAI

client = AsyncLumaAI(
# This is the default and can be omitted
auth_token=os.environ.get("LUMAAI_API_KEY"),
auth_token=os.environ.get("LUMAAI_API_KEY"), # This is the default and can be omitted
)


Expand Down Expand Up @@ -188,12 +186,14 @@ Note that requests that time out are [retried twice by default](#retries).

We use the standard library [`logging`](https://docs.python.org/3/library/logging.html) module.

You can enable logging by setting the environment variable `LUMAAI_LOG` to `debug`.
You can enable logging by setting the environment variable `LUMAAI_LOG` to `info`.

```shell
$ export LUMAAI_LOG=debug
$ export LUMAAI_LOG=info
```

Or to `debug` for more verbose logging.

### How to tell whether `None` means `null` or missing

In an API response, a field may be explicitly `null`, or missing entirely; in either case, its value is `None` in this library. You can differentiate the two cases with `.model_fields_set`:
Expand Down Expand Up @@ -340,7 +340,7 @@ print(lumaai.__version__)

## Requirements

Python 3.7 or higher.
Python 3.8 or higher.

## Contributing

Expand Down
5 changes: 4 additions & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ show_error_codes = True
# Exclude _files.py because mypy isn't smart enough to apply
# the correct type narrowing and as this is an internal module
# it's fine to just use Pyright.
exclude = ^(src/lumaai/_files\.py|_dev/.*\.py)$
#
# We also exclude our `tests` as mypy doesn't always infer
# types correctly and Pyright will still catch any type errors.
exclude = ^(src/lumaai/_files\.py|_dev/.*\.py|tests/.*)$

strict_equality = True
implicit_reexport = True
Expand Down
17 changes: 6 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "lumaai"
version = "1.1.0"
version = "1.1.1"
description = "The official Python library for the lumaai API"
dynamic = ["readme"]
license = "Apache-2.0"
Expand All @@ -14,13 +14,11 @@ dependencies = [
"anyio>=3.5.0, <5",
"distro>=1.7.0, <2",
"sniffio",
"cached-property; python_version < '3.8'",
]
requires-python = ">= 3.7"
requires-python = ">= 3.8"
classifiers = [
"Typing :: Typed",
"Intended Audience :: Developers",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
Expand Down Expand Up @@ -56,18 +54,19 @@ dev-dependencies = [
"dirty-equals>=0.6.0",
"importlib-metadata>=6.7.0",
"rich>=13.7.1",
"nest_asyncio==1.6.0"
]

[tool.rye.scripts]
format = { chain = [
"format:ruff",
"format:docs",
"fix:ruff",
# run formatting again to fix any inconsistencies when imports are stripped
"format:ruff",
]}
"format:black" = "black ."
"format:docs" = "python scripts/utils/ruffen-docs.py README.md api.md"
"format:ruff" = "ruff format"
"format:isort" = "isort ."

"lint" = { chain = [
"check:ruff",
Expand Down Expand Up @@ -125,10 +124,6 @@ path = "README.md"
pattern = '\[(.+?)\]\(((?!https?://)\S+?)\)'
replacement = '[\1](https://github.com/lumalabs/lumaai-python/tree/main/\g<2>)'

[tool.black]
line-length = 120
target-version = ["py37"]

[tool.pytest.ini_options]
testpaths = ["tests"]
addopts = "--tb=short"
Expand All @@ -143,7 +138,7 @@ filterwarnings = [
# there are a couple of flags that are still disabled by
# default in strict mode as they are experimental and niche.
typeCheckingMode = "strict"
pythonVersion = "3.7"
pythonVersion = "3.8"

exclude = [
"_dev",
Expand Down
26 changes: 12 additions & 14 deletions requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ anyio==4.4.0
# via lumaai
argcomplete==3.1.2
# via nox
attrs==23.1.0
# via pytest
certifi==2023.7.22
# via httpcore
# via httpx
Expand All @@ -28,8 +26,9 @@ distlib==0.3.7
# via virtualenv
distro==1.8.0
# via lumaai
exceptiongroup==1.1.3
exceptiongroup==1.2.2
# via anyio
# via pytest
filelock==3.12.4
# via virtualenv
h11==0.14.0
Expand All @@ -49,9 +48,10 @@ markdown-it-py==3.0.0
# via rich
mdurl==0.1.2
# via markdown-it-py
mypy==1.11.2
mypy==1.13.0
mypy-extensions==1.0.0
# via mypy
nest-asyncio==1.6.0
nodeenv==1.8.0
# via pyright
nox==2023.4.22
Expand All @@ -60,27 +60,25 @@ packaging==23.2
# via pytest
platformdirs==3.11.0
# via virtualenv
pluggy==1.3.0
# via pytest
py==1.11.0
pluggy==1.5.0
# via pytest
pydantic==2.7.1
pydantic==2.9.2
# via lumaai
pydantic-core==2.18.2
pydantic-core==2.23.4
# via pydantic
pygments==2.18.0
# via rich
pyright==1.1.380
pytest==7.1.1
pytest==8.3.3
# via pytest-asyncio
pytest-asyncio==0.21.1
pytest-asyncio==0.24.0
python-dateutil==2.8.2
# via time-machine
pytz==2023.3.post1
# via dirty-equals
respx==0.20.2
rich==13.7.1
ruff==0.6.5
ruff==0.6.9
setuptools==68.2.2
# via nodeenv
six==1.16.0
Expand All @@ -90,10 +88,10 @@ sniffio==1.3.0
# via httpx
# via lumaai
time-machine==2.9.0
tomli==2.0.1
tomli==2.0.2
# via mypy
# via pytest
typing-extensions==4.8.0
typing-extensions==4.12.2
# via anyio
# via lumaai
# via mypy
Expand Down
8 changes: 4 additions & 4 deletions requirements.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ certifi==2023.7.22
# via httpx
distro==1.8.0
# via lumaai
exceptiongroup==1.1.3
exceptiongroup==1.2.2
# via anyio
h11==0.14.0
# via httpcore
Expand All @@ -30,15 +30,15 @@ httpx==0.25.2
idna==3.4
# via anyio
# via httpx
pydantic==2.7.1
pydantic==2.9.2
# via lumaai
pydantic-core==2.18.2
pydantic-core==2.23.4
# via pydantic
sniffio==1.3.0
# via anyio
# via httpx
# via lumaai
typing-extensions==4.8.0
typing-extensions==4.12.2
# via anyio
# via lumaai
# via pydantic
Expand Down
2 changes: 1 addition & 1 deletion src/lumaai/_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1575,7 +1575,7 @@ async def _request(
except Exception as err:
log.debug("Encountered Exception", exc_info=True)

if retries_taken > 0:
if remaining_retries > 0:
return await self._retry_request(
input_options,
cast_to,
Expand Down
16 changes: 8 additions & 8 deletions src/lumaai/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from typing import TYPE_CHECKING, Any, Union, Generic, TypeVar, Callable, cast, overload
from datetime import date, datetime
from typing_extensions import Self
from typing_extensions import Self, Literal

import pydantic
from pydantic.fields import FieldInfo
Expand Down Expand Up @@ -133,17 +133,20 @@ def model_json(model: pydantic.BaseModel, *, indent: int | None = None) -> str:
def model_dump(
model: pydantic.BaseModel,
*,
exclude: IncEx = None,
exclude: IncEx | None = None,
exclude_unset: bool = False,
exclude_defaults: bool = False,
warnings: bool = True,
mode: Literal["json", "python"] = "python",
) -> dict[str, Any]:
if PYDANTIC_V2:
if PYDANTIC_V2 or hasattr(model, "model_dump"):
return model.model_dump(
mode=mode,
exclude=exclude,
exclude_unset=exclude_unset,
exclude_defaults=exclude_defaults,
warnings=warnings,
# warnings are not supported in Pydantic v1
warnings=warnings if PYDANTIC_V2 else True,
)
return cast(
"dict[str, Any]",
Expand Down Expand Up @@ -211,9 +214,6 @@ def __set_name__(self, owner: type[Any], name: str) -> None: ...
# __set__ is not defined at runtime, but @cached_property is designed to be settable
def __set__(self, instance: object, value: _T) -> None: ...
else:
try:
from functools import cached_property as cached_property
except ImportError:
from cached_property import cached_property as cached_property
from functools import cached_property as cached_property

typed_cached_property = cached_property
19 changes: 11 additions & 8 deletions src/lumaai/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
PropertyInfo,
is_list,
is_given,
json_safe,
lru_cache,
is_mapping,
parse_date,
Expand Down Expand Up @@ -176,7 +177,7 @@ def __str__(self) -> str:
# Based on https://github.com/samuelcolvin/pydantic/issues/1168#issuecomment-817742836.
@classmethod
@override
def construct(
def construct( # pyright: ignore[reportIncompatibleMethodOverride]
cls: Type[ModelT],
_fields_set: set[str] | None = None,
**values: object,
Expand Down Expand Up @@ -248,8 +249,8 @@ def model_dump(
self,
*,
mode: Literal["json", "python"] | str = "python",
include: IncEx = None,
exclude: IncEx = None,
include: IncEx | None = None,
exclude: IncEx | None = None,
by_alias: bool = False,
exclude_unset: bool = False,
exclude_defaults: bool = False,
Expand Down Expand Up @@ -279,8 +280,8 @@ def model_dump(
Returns:
A dictionary representation of the model.
"""
if mode != "python":
raise ValueError("mode is only supported in Pydantic v2")
if mode not in {"json", "python"}:
raise ValueError("mode must be either 'json' or 'python'")
if round_trip != False:
raise ValueError("round_trip is only supported in Pydantic v2")
if warnings != True:
Expand All @@ -289,7 +290,7 @@ def model_dump(
raise ValueError("context is only supported in Pydantic v2")
if serialize_as_any != False:
raise ValueError("serialize_as_any is only supported in Pydantic v2")
return super().dict( # pyright: ignore[reportDeprecated]
dumped = super().dict( # pyright: ignore[reportDeprecated]
include=include,
exclude=exclude,
by_alias=by_alias,
Expand All @@ -298,13 +299,15 @@ def model_dump(
exclude_none=exclude_none,
)

return cast(dict[str, Any], json_safe(dumped)) if mode == "json" else dumped

@override
def model_dump_json(
self,
*,
indent: int | None = None,
include: IncEx = None,
exclude: IncEx = None,
include: IncEx | None = None,
exclude: IncEx | None = None,
by_alias: bool = False,
exclude_unset: bool = False,
exclude_defaults: bool = False,
Expand Down
Loading