Traduction automatique supervisée
Ce contenu est traduit à l'aide d'une génération automatique guidée par des glossaires et des guides de style élaborés par des humains. Le texte n'étant pas relu manuellement ligne par ligne, des erreurs ou des tournures maladroites peuvent occasionnellement apparaître.
En cas de divergence, la version anglaise constitue la source de référence.
Import
Référence complète des attributs et méthodes du système d'import, générée à partir des docstrings. Pour un guide orienté tâches, consultez Export & Import.
starlette_admin.importers.ImportConfig
dataclass
Security and capacity limits applied by the import endpoint.
Attributes:
| Name | Type | Description |
|---|---|---|
max_upload_size |
int
|
Maximum accepted file size in bytes (default: 10 MB). Checked before any parsing begins. |
max_rows |
int | None
|
Maximum number of rows that may be imported in a single
request (default: 100,000). The file is counted in a pre-pass
before any record is created; when it holds more rows, the
endpoint returns HTTP 400 so no partial import happens. Set to
|
Source code in starlette_admin/importers/base.py
starlette_admin.importers.ImportContext
dataclass
Everything an importer needs to process one upload.
Attributes:
| Name | Type | Description |
|---|---|---|
fields |
list[BaseField]
|
Importable fields on the view (the same set used for export, resolved to the |
content |
bytes
|
The raw bytes of the main data file (CSV, XLSX, JSON, etc.). |
view |
BaseModelView
|
The model view performing the import. |
request |
Request
|
The originating HTTP request. |
dry_run |
bool
|
When |
selected_fields |
list[str] | None
|
Field names to read from the uploaded file, or |
update_existing |
bool
|
When |
Source code in starlette_admin/importers/base.py
starlette_admin.importers.ImportResult
dataclass
Summary returned after a (live or dry-run) import operation.
Attributes:
| Name | Type | Description |
|---|---|---|
rows_total |
int
|
The total number of data rows parsed from the source file. |
rows_created |
int
|
The number of records successfully created (always 0 during a dry-run). |
rows_updated |
int
|
The number of records updated in upsert mode (always 0 during a dry-run). |
rows_skipped |
int
|
The number of valid rows that were intentionally skipped (e.g., unchanged in upsert mode). |
errors |
list[ImportRowError]
|
Per-row validation and processing errors collected during the operation. |
dry_run |
bool
|
Indicates whether no data was actually committed. |
Source code in starlette_admin/importers/base.py
has_errors
property
Returns True if any row produced an error.
rows_ok
property
The number of rows processed without error (created + updated + skipped).
starlette_admin.importers.ImportRowError
dataclass
A validation or processing error for a single row.
Attributes:
| Name | Type | Description |
|---|---|---|
row |
int
|
The 1-based row number in the source file. Use |
field |
str | None
|
The name of the offending field, or |
message |
str
|
A human-readable description of the problem. |
Source code in starlette_admin/importers/base.py
starlette_admin.importers.BaseImporter
Bases: ABC
Base class for all import-format implementations.
Subclasses implement :meth:parse to yield parsed row dictionaries from the raw format bytes.
Minimal subclass example::
class CsvImporter(BaseImporter):
extension = "csv"
async def parse(
self, ctx: ImportContext
) -> AsyncGenerator[dict[str, Any], None]:
text = ctx.content.decode()
reader = csv.DictReader(io.StringIO(text))
for row in reader:
yield dict(row)
File fields (:class:~starlette_admin.fields.FileField,
:class:~starlette_admin.fields.ImageField) are always excluded from
import; see exclude_from_import on :class:~starlette_admin.fields.BaseField.
Source code in starlette_admin/importers/base.py
parse(ctx)
abstractmethod
Yield parsed row dictionaries from ctx.content.
Each yielded dictionary maps column headers (or field names) to raw string values.
Source code in starlette_admin/importers/base.py
starlette_admin.importers.CsvImporter
Bases: BaseImporter
Source code in starlette_admin/importers/csv.py
__init__(**fmtparams)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fmtparams
|
Any
|
Forwarded to |
{}
|
starlette_admin.importers.TsvImporter
Bases: CsvImporter
Source code in starlette_admin/importers/csv.py
__init__(**fmtparams)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fmtparams
|
Any
|
Forwarded to |
{}
|
starlette_admin.importers.TablibImporter
Bases: BaseImporter
Parses through tablib.Dataset for any format tablib supports.
Source code in starlette_admin/importers/tablib.py
__init__(format, **import_kwargs)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
format
|
str
|
A tablib import format name ( |
required |
import_kwargs
|
Any
|
Forwarded to |
{}
|
Source code in starlette_admin/importers/tablib.py
starlette_admin.importers.JsonImporter
Bases: BaseImporter