Skip to content

Commit 6caa67b

Browse files
authored
Merge pull request #872 from opsmill/develop
Merge develop into infrahub-develop
2 parents f737549 + a4c5ecb commit 6caa67b

15 files changed

Lines changed: 575 additions & 8 deletions

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,24 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
1010
This project uses [*towncrier*](https://towncrier.readthedocs.io/) and the changes for the upcoming release can be found in <https://github.com/opsmill/infrahub/tree/develop/infrahub/python_sdk/changelog/>.
1111

1212
<!-- towncrier release notes start -->
13+
14+
## [1.19.0](https://github.com/opsmill/infrahub-sdk-python/tree/v1.19.0) - 2026-03-16
15+
16+
### Added
17+
18+
- Added support for FileObject nodes with file upload and download capabilities. New methods `upload_from_path(path)` and `upload_from_bytes(content, name)` allow setting file content before saving, while `download_file(dest)` enables downloading files to memory or streaming to disk for large files. ([#ihs193](https://github.com/opsmill/infrahub-sdk-python/issues/ihs193))
19+
- Python SDK API documentation is now generated directly from the docstrings of the classes, functions, and methods contained in the code. ([#201](https://github.com/opsmill/infrahub-sdk-python/issues/201))
20+
- Added a 'py.typed' file to the project. This is to enable type checking when the Infrahub SDK is imported from other projects. The addition of this file could cause new typing issues in external projects until all typing issues have been resolved. Adding it to the project now to better highlight remaining issues.
21+
22+
### Changed
23+
24+
- Updated branch report command to use node metadata for proposed change creator information instead of the deprecated relationship-based approach. Requires Infrahub 1.7 or above.
25+
26+
### Fixed
27+
28+
- Allow SDK tracking feature to continue after encountering delete errors due to impacted nodes having already been deleted by cascade delete. ([#265](https://github.com/opsmill/infrahub-sdk-python/issues/265))
29+
- Fixed Python SDK query generation regarding from_pool generated attribute value ([#497](https://github.com/opsmill/infrahub-sdk-python/issues/497))
30+
1331
## [1.18.1](https://github.com/opsmill/infrahub-sdk-python/tree/v1.18.1) - 2026-01-08
1432

1533
### Fixed

changelog/+5f3ef109.added.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

changelog/+infrahubctl-proposedchange.changed.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

changelog/151.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add `infrahubctl schema export` command to export schemas from Infrahub.

changelog/201.added.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

changelog/265.fixed.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

changelog/497.fixed.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

changelog/ihs193.added.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/docs/infrahubctl/infrahubctl-schema.mdx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ $ infrahubctl schema [OPTIONS] COMMAND [ARGS]...
1717
**Commands**:
1818

1919
* `check`: Check if schema files are valid and what...
20+
* `export`: Export the schema from Infrahub as YAML...
2021
* `load`: Load one or multiple schema files into...
2122

2223
## `infrahubctl schema check`
@@ -40,6 +41,25 @@ $ infrahubctl schema check [OPTIONS] SCHEMAS...
4041
* `--config-file TEXT`: [env var: INFRAHUBCTL_CONFIG; default: infrahubctl.toml]
4142
* `--help`: Show this message and exit.
4243

44+
## `infrahubctl schema export`
45+
46+
Export the schema from Infrahub as YAML files, one per namespace.
47+
48+
**Usage**:
49+
50+
```console
51+
$ infrahubctl schema export [OPTIONS]
52+
```
53+
54+
**Options**:
55+
56+
* `--directory PATH`: Directory path to store schema files [default: (dynamic)]
57+
* `--branch TEXT`: Branch from which to export the schema
58+
* `--namespaces TEXT`: Namespace(s) to export (default: all user-defined)
59+
* `--debug / --no-debug`: [default: no-debug]
60+
* `--config-file TEXT`: [env var: INFRAHUBCTL_CONFIG; default: infrahubctl.toml]
61+
* `--help`: Show this message and exit.
62+
4363
## `infrahubctl schema load`
4464

4565
Load one or multiple schema files into Infrahub.

infrahub_sdk/ctl/schema.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import asyncio
44
import time
5+
from datetime import datetime, timezone
56
from pathlib import Path
67
from typing import TYPE_CHECKING, Any
78

@@ -211,3 +212,49 @@ def _display_schema_warnings(console: Console, warnings: list[SchemaWarning]) ->
211212
console.print(
212213
f"[yellow] {warning.type.value}: {warning.message} [{', '.join([kind.display for kind in warning.kinds])}]"
213214
)
215+
216+
217+
def _default_export_directory() -> Path:
218+
timestamp = datetime.now(timezone.utc).astimezone().strftime("%Y%m%d-%H%M%S")
219+
return Path(f"infrahub-schema-export-{timestamp}")
220+
221+
222+
@app.command()
223+
@catch_exception(console=console)
224+
async def export(
225+
directory: Path = typer.Option(_default_export_directory, help="Directory path to store schema files"),
226+
branch: str = typer.Option(None, help="Branch from which to export the schema"),
227+
namespaces: list[str] = typer.Option([], help="Namespace(s) to export (default: all user-defined)"),
228+
debug: bool = False,
229+
_: str = CONFIG_PARAM,
230+
) -> None:
231+
"""Export the schema from Infrahub as YAML files, one per namespace."""
232+
init_logging(debug=debug)
233+
234+
client = initialize_client()
235+
user_schemas = await client.schema.export(
236+
branch=branch,
237+
namespaces=namespaces or None,
238+
)
239+
240+
if not user_schemas.namespaces:
241+
console.print("[yellow]No user-defined schema found to export.")
242+
return
243+
244+
directory.mkdir(parents=True, exist_ok=True)
245+
246+
for ns, data in sorted(user_schemas.namespaces.items()):
247+
payload: dict[str, Any] = {"version": "1.0"}
248+
if data.generics:
249+
payload["generics"] = data.generics
250+
if data.nodes:
251+
payload["nodes"] = data.nodes
252+
253+
output_file = directory / f"{ns.lower()}.yml"
254+
output_file.write_text(
255+
yaml.dump(payload, default_flow_style=False, sort_keys=False, allow_unicode=True),
256+
encoding="utf-8",
257+
)
258+
console.print(f"[green] Exported namespace '{ns}' to {output_file}")
259+
260+
console.print(f"[green] Schema exported to {directory}")

0 commit comments

Comments
 (0)