Skip to main content

uploadkit-odoo

CI Coverage Python Odoo

Odoo integration for UploadKit.

What problem does this solve?

Adapts Werkzeug/FileStorage uploads from Odoo controllers and maps UploadKit exceptions to JSON responses — without reimplementing validation or storage. An optional Odoo 17/18 addon wires settings and a thin upload service/HTTP route.

When to use it

Use when an Odoo app uploads files through UploadKit Core (controllers or the uploadkit.service model).

When not to use it

Do not put validators, policies, or storage implementations in this package. Supply your own StorageProvider (e.g. boto3 → AWS S3 or MinIO). Creating ir.attachment records after upload is left to your module.

Installation

Requires Python 3.10–3.12 (Odoo 17/18 host range) and Odoo 17 or 18 for the addon.

pip install uploadkit-odoo uploadkit-security
uv add uploadkit-odoo uploadkit-security
poetry add uploadkit-odoo uploadkit-security

For S3/MinIO samples: pip install boto3.

Python × Odoo support

Python Odoo
3.10–3.12 Odoo 17, Odoo 18

Python 3.13+ will be added once Odoo officially supports it.

Licenses

  • PyPI package (uploadkit-odoo): Apache-2.0
  • Odoo addon (addons/uploadkit_odoo): LGPL-3

Library quick start (controller)

from odoo import http
from odoo.http import request
from uploadkit import Uploader, UploadPolicy, UploaderError
from uploadkit_odoo import as_uploadable, json_error_response
from uploadkit_security import default_validators


def notify(result):
    ...


class MyController(http.Controller):
    @http.route("/my/upload", type="http", auth="user", methods=["POST"], csrf=True)
    def upload(self, **kw):
        storage = get_provider()  # your StorageProvider factory
        policy = UploadPolicy(
            max_size=5 * 1024 * 1024,
            allowed_extensions=frozenset({"png"}),
            allowed_mime_types=frozenset({"image/png"}),
            validators=default_validators(),
        )
        uploaded = kw.get("file")
        try:
            result = Uploader(policy, storage).upload(
                as_uploadable(uploaded),
                bucket="uploads",
                object_name=uploaded.filename,
                after_upload=notify,  # or a Celery-like task with .delay
            )
        except UploaderError as exc:
            return json_error_response(exc)
        return request.make_json_response(result.as_task_kwargs())

After-upload

Library controllers can pass Core after_upload on Uploader.upload (sync callback or Celery-like .delay). The optional addon uploadkit.service.upload() returns UploadResult.as_task_kwargs() and does not accept a hook — call Core Uploader directly (as above), or enqueue work from the returned dict. Full semantics: uploadkit Core README.

Storage provider (AWS S3 or MinIO)

Same class for both backends — omit endpoint_url for AWS, set it for MinIO:

# my_module/storage.py
import boto3
from botocore.client import Config
from odoo.tools import config


class Boto3S3Storage:
    def __init__(
        self,
        *,
        access_key: str,
        secret_key: str,
        region: str = "us-east-1",
        endpoint_url: str | None = None,
    ) -> None:
        kwargs: dict = {
            "service_name": "s3",
            "aws_access_key_id": access_key,
            "aws_secret_access_key": secret_key,
            "region_name": region,
            "config": Config(signature_version="s3v4"),
        }
        if endpoint_url:
            kwargs["endpoint_url"] = endpoint_url
        self.client = boto3.client(**kwargs)

    def put(self, *, bucket, object_name, body, content_type):
        resp = self.client.put_object(
            Bucket=bucket,
            Key=object_name,
            Body=body,
            ContentType=content_type,
        )
        return resp.get("ETag")


def get_provider():
    """Factory used by uploadkit.storage_provider config parameter."""
    return Boto3S3Storage(
        access_key=config.get("uploadkit_access_key", ""),
        secret_key=config.get("uploadkit_secret_key", ""),
        region=config.get("uploadkit_region", "us-east-1"),
        endpoint_url=config.get("uploadkit_endpoint_url") or None,
    )

Odoo addon

  1. Add this repo’s addons/ directory to Odoo addons_path.
  2. pip install uploadkit-odoo uploadkit-security (and your storage deps).
  3. Install UploadKit in Apps.
  4. Configure under Settings → UploadKit:
    • Storage provider factory (dotted path, e.g. my_module.storage.get_provider)
    • Upload bucket
    • Optional object name prefix and max size

Service API

result = env["uploadkit.service"].upload(file_storage, object_name="docs/a.pdf")
# result is UploadResult.as_task_kwargs() — no after_upload parameter
# Enqueue from the dict, or call Uploader.upload(..., after_upload=...) yourself

HTTP route

POST /uploadkit/upload (auth=user, CSRF) with multipart field file (optional object_name). Returns JSON success payload or the standard UploadKit error shape.

After a successful upload you may create an ir.attachment yourself (e.g. type='url' pointing at your object URL). This package does not store into ir.attachment.

Architecture

Thin adapters over UploadKit Core. Odoo multipart uploads are Werkzeug FileStorage; as_uploadable wraps them for Uploader.

Public API (library)

Symbol Kind
as_uploadable Public
json_error_response / status_for_error / error_payload Public

Changelog

See CHANGELOG.md.

Contributing

See CONTRIBUTING.md.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uploadkit_odoo-0.1.1.tar.gz (15.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

uploadkit_odoo-0.1.1-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file uploadkit_odoo-0.1.1.tar.gz.

File metadata

  • Download URL: uploadkit_odoo-0.1.1.tar.gz
  • Upload date:
  • Size: 15.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for uploadkit_odoo-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0ab05846ee123611b591662828197147ee3ee34ab57f477032049ff28276a54b
MD5 9021f980c1fdd3b102686c4d4fde20fe
BLAKE2b-256 16799df0652a40292fad2204edc872a73d2c2edaba128a3b49efad4653d73458

See more details on using hashes here.

File details

Details for the file uploadkit_odoo-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: uploadkit_odoo-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for uploadkit_odoo-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 46cd0ae265385a30748624ad490dad6e75617437360ec0e20a436e1807d1c1c5
MD5 62191123abfc616bd6423b8a775ce17f
BLAKE2b-256 e6bfe66dc6d2af65d0ee7ccc6c36213d1a27df560222662ec724a30cd71f806e

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page