Skip to content

[UCCORE-1899] Project api implementation - #352

Open
alxnik-uc wants to merge 11 commits into
feat/UCCORE-1899/oauth-supportfrom
feat/UCCORE-1899/project-api
Open

alxnik-uc wants to merge 11 commits into
feat/UCCORE-1899/oauth-supportfrom
feat/UCCORE-1899/project-api

Conversation

@alxnik-uc

Copy link
Copy Markdown
Contributor

Scope

  • Projects: list, count, get, create, update and delete. Updates change only the settings you
    pass.
  • Daily usage: all metrics at once, or traffic, storage or operations separately.
  • Content moderation thresholds: get and replace.
  • Reference lists: MIME types for MIME type filtering, and moderation categories.
  • Input checks before a request goes out, so mistakes fail early with a clear error.
  • Docs, HISTORY and the version bump to 7.1.0.

Out of scope

  • Secret key endpoints (/projects/{pub_key}/secrets/).
  • Partner authorization (/oauth/authorize/).
  • ucare CLI commands and Django integration for the Project API.
  • A link to an API reference, since the Project API has no public one.

Checklist

@alxnik-uc
alxnik-uc added this pull request to stack #353 November 10, 2026 15:51
@alxnik-uc
alxnik-uc force-pushed the feat/UCCORE-1899/project-api branch from 473c5dc to 87a82bc Compare November 10, 2026 16:15
@dmitry-mukhin

Copy link
Copy Markdown
Member

does this replace #348 ?

@alxnik-uc

Copy link
Copy Markdown
Contributor Author

does this replace #348 ?

@dmitry-mukhin Oops, actually I missed this and don't know that Denis has been already working on this. Otherwise, my implementation closer to what we want and more match to OAuth specification scopes (https://github.com/uploadcare/auth-server/pull/1)
OAuth token is not permitted to manage secret keys or partner authorizing redirect by scopes. I'll close #348, this PR replace it.

Comment thread pyuploadcare/api/project_entities.py Outdated


class UploadsFeature(Entity):
# In bytes, a multiple of a megabyte. `None` means the plan's maximum.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not clear should I pass 1 or 1000^2 to set one MB.
If it's 1000^2 and we only accept multiples, why not make it easier and accept MBs, not Bs.

@alxnik-uc alxnik-uc Nov 13, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Values ​​in the model are now explicitly defined in megabytes; they are converted to bytes before being sent to the API, and converted back to megabytes in the response. Users works with megabytes.

Using 10^6 instead of 1e-6 because of backend logic

Comment thread pyuploadcare/api/project_entities.py Outdated
# In bytes, a multiple of a megabyte. `None` means the plan's maximum.
filesize_limit: Optional[int] = Field(default=None, ge=0)
autostore: Optional[bool] = None
# In pixels, a multiple of 10^6. `None` means the default value.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Values ​​in the model are now explicitly defined in megapixels; they are converted to pixels before being sent to the API, and converted back to megapixels in the response. Users works with megapixels.

Comment thread pyuploadcare/api/project_api.py Outdated
Comment on lines +78 to +101
def _utc_date(name: str, value: datetime) -> date:
# The server counts days in UTC.
try:
aware = ensure_aware_datetime(value)
except ValueError:
raise InvalidParamError(
f"`{name}` must be a timezone-aware datetime, got {value!r}"
) from None
return aware.astimezone(timezone.utc).date()


def _to_date(name: str, value: DateLike) -> date:
# `datetime` is a subclass of `date`, so check it first.
if isinstance(value, datetime):
return _utc_date(name, value)
if isinstance(value, date):
return value
try:
return date.fromisoformat(value)
except (TypeError, ValueError):
raise InvalidParamError(
f"`{name}` must be a date or an ISO 8601 date string "
f"(YYYY-MM-DD), got {value!r}"
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like it's accidental that this lives under project_api, not more broad helpers. we already have some date helpers there.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reworked with using common helpers. Now accept datetime aware only (neither plain date type or string)

Comment thread HISTORY.md Outdated
Comment on lines +25 to +27
They are an exception to the 7.0 rule that rejects plain `date` objects, which covers inputs
that mean a point in time. A `datetime` there must be timezone-aware, as everywhere else, and
is converted to its UTC date.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TMI

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, this is useless information, removed this block

Comment thread docs/core_api.rst Outdated
Comment on lines +599 to +600
Project API
-----------

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like time to move it to a separate project_api doc.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, moved it to dedicated page

alxnik-uc and others added 11 commits November 13, 2026 17:55
Account-level APIs such as the Project API have no project key, which
would otherwise show up as `PyUploadcare/<version>/None`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ProjectAPIClient lists, counts, gets, creates, updates and deletes the
projects of an account. It is authorized with the OAuth access token
from UPLOADCARE_OAUTH_TOKEN by default; the public key goes in the URL.

Updates are partial: models send only explicitly set, writable fields,
since the server rejects any non-empty feature object the owner's plan
does not include. Request data and public keys are validated before a
request is made. Tests run the real HTTP client stack against a mocked
transport.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`get_usage()` returns daily traffic, storage and operations, and
`get_usage_metric()` one of them. The dates take a day: a `date` or a
YYYY-MM-DD string. A datetime must be timezone-aware and becomes its
UTC date, since the server counts days in UTC.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`get_moderation_thresholds()` and `set_moderation_thresholds()`, which
replaces all thresholds of a project. Thresholds are validated locally:
0 to 100 with up to two decimal places, unique per category and file
type.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`list_mime_types()` gives the values `mime_type_filtering` accepts,
and `list_moderation_categories()` the category ids moderation
thresholds take.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add the Project API to HISTORY under 7.1.0 and bump the version.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@alxnik-uc
alxnik-uc force-pushed the feat/UCCORE-1899/project-api branch from cea05eb to d191bc8 Compare November 13, 2026 11:06
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants