Metadata-Version: 2.4
Name: djangogeoexporter
Version: 0.1.0
Summary: A Django module to facilitate exports, particularly map and relational database exports
License-Expression: AGPL-3.0-only
License-File: LICENSE
Keywords: Django,geopackage,parquet,spreadsheet,excel,calc,ods,odf,dbchiro,dbwildlife
Author: dbWildlife
Author-email: contact@dbwildlife.info
Requires-Python: >=3.12,<4.0
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Provides-Extra: all
Provides-Extra: gpkg
Provides-Extra: parquet
Provides-Extra: spreadsheet
Requires-Dist: geopandas (>=1.0) ; extra == "all"
Requires-Dist: geopandas (>=1.0) ; extra == "gpkg"
Requires-Dist: geopandas (>=1.0) ; extra == "parquet"
Requires-Dist: odfpy (>=1.4.1) ; extra == "all"
Requires-Dist: odfpy (>=1.4.1) ; extra == "spreadsheet"
Requires-Dist: openpyxl (>=3.1) ; extra == "all"
Requires-Dist: openpyxl (>=3.1) ; extra == "spreadsheet"
Requires-Dist: pandas (>=2.2) ; extra == "all"
Requires-Dist: pandas (>=2.2) ; extra == "gpkg"
Requires-Dist: pandas (>=2.2) ; extra == "parquet"
Requires-Dist: pandas (>=2.2) ; extra == "spreadsheet"
Requires-Dist: pyarrow (>=15) ; extra == "all"
Requires-Dist: pyarrow (>=15) ; extra == "parquet"
Requires-Dist: pyogrio (>=0.9) ; extra == "all"
Requires-Dist: pyogrio (>=0.9) ; extra == "gpkg"
Project-URL: Documentation, https://dbchiro.github.io/DjGeoExporter/
Project-URL: Homepage, https://github.com/dbwildlife/DjGeoExporter
Project-URL: Repository, https://github.com/dbwildlife/DjGeoExporter
Description-Content-Type: text/markdown

# DjangoGeoExporter

DjangoGeoExporter provides declarative flat, relational, and geospatial exports
from Django querysets.

## Quickstart

Install the package with the features required by your project:

```bash
poetry add "djangogeoexporter[all]"
```

Available extras are `spreadsheet` (XLSX and ODS), `parquet`, `gpkg`
(GeoPackage), and `all`. With pip, use the equivalent command:

```bash
pip install "djangogeoexporter[all]"
```

Declare an export using your Django models:

```python
from djangogeoexporter import ExportDefinition, ExportTable, Field, JSONField

from myapp.models import Commune, Observation


class ObservationsExport(ExportDefinition):
    name = "observations"
    tables = (
        ExportTable(
            "communes",
            Commune.objects.all(),
            ("id", "name", "geom"),
            geometry_field="geom",
            crs="EPSG:4326",
        ),
        ExportTable(
            "observations",
            Observation.objects.select_related("commune"),
            (
                "id",
                Field("commune", source="commune__name"),
                "observed_at",
            ),
        ),
    )
```

Generate the export and dispose of its temporary file when finished:

```python
from shutil import copyfile

from djangogeoexporter import export

result = export(ObservationsExport, format="gpkg")
try:
    copyfile(result.path, result.filename)
finally:
    result.cleanup()
```

Supported formats include CSV, TSV, XLSX, ODS, Parquet/GeoParquet, and
GeoPackage. Relational CSV and TSV exports are returned as ZIP archives.

## JSON and JSONB fields

Django `models.JSONField` columns (backed by `json` or `jsonb` in PostgreSQL)
are detected automatically. Their values are stored as strict, compact UTF-8
JSON text in every output format. This avoids format-dependent structures and
allows the exported value to be consumed directly with `json.loads(value)` in
Python or cast with `value::jsonb` in PostgreSQL. In particular, JSON `null` is
exported as `null`, while a regular nullable field keeps the format's normal
empty/null representation.

For a plain iterable, a computed field, or an annotation that cannot be
identified through Django model metadata, mark the field explicitly:

```python
ExportTable(
    "observations",
    rows,
    ("id", JSONField("metadata")),
)
```

Only standard JSON values are accepted. Non-standard floating-point values
such as `NaN` and `Infinity` are rejected because PostgreSQL cannot import
them as JSON/JSONB.

See the [`docs/`](docs/) directory for configuration, dynamic export contexts,
field labels, Django response integration, and format-specific options.

## Code quality

Install development dependencies with `poetry install --with dev`. Ruff handles
linting, import sorting, and formatting, using a line length of 79 characters.

To test all export formats, install the optional dependencies as well:

```bash
poetry install --with test -E all
poetry run pytest
```

Without the extras, tests requiring optional export dependencies are skipped.
Django integration tests also require a running PostgreSQL/PostGIS database
configured through `config.settings_test`.

- `make lint`: run lint checks.
- `make format`: sort imports and format Python code.
- `make check`: check linting and formatting without modifying files.

Run `poetry run pre-commit install` to enable the Ruff hooks before commits.
For VS Code, install the Ruff extension (`charliermarsh.ruff`).

## Releases (GitLab / PyPI)

Tags in the exact format `x.x.x` (for example `0.1.0`, without a `v`
prefix) trigger package publication after the unit and integration tests pass.
The pipeline builds a wheel and source distribution, validates their metadata,
publishes both to PyPI, then creates a GitLab release. Build artifacts include
the packages and extracted release notes.

Before the first publication, configure `PYPI_API_TOKEN` in GitLab under
Settings > CI/CD > Variables with a PyPI API token authorized to publish
`djangogeoexporter`. Mark the variable as masked and protected, and protect
release tags under Settings > Repository > Protected tags so those pipelines
can access it. For a new PyPI project, the first upload requires an account
token; once the project exists, use a project-scoped token.

Before tagging, add a unique, non-empty section to `CHANGELOG.md`:

```markdown
## [0.1.0] - 2026-11-10

### Changes

- Describe the changes included in this release.
```

Commit the changelog, then create and push the tag:

```bash
git tag 0.1.0
git push origin 0.1.0
```

The tag sets the package version during the build; no version commit is
created. Missing, empty or duplicate changelog sections stop publication.
PyPI versions cannot be overwritten: publish subsequent changes with a new
version tag.

