horizon-data-core 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- horizon_data_core-0.0.1/.coveragerc +11 -0
- horizon_data_core-0.0.1/.gitignore +18 -0
- horizon_data_core-0.0.1/.npmpackagejsonlintrc.json +11 -0
- horizon_data_core-0.0.1/CHANGELOG.md +210 -0
- horizon_data_core-0.0.1/PKG-INFO +23 -0
- horizon_data_core-0.0.1/README.md +0 -0
- horizon_data_core-0.0.1/SDK_README.md +259 -0
- horizon_data_core-0.0.1/package.json +47 -0
- horizon_data_core-0.0.1/pyproject.toml +56 -0
- horizon_data_core-0.0.1/src/horizon_data_core/__init__.py +5 -0
- horizon_data_core-0.0.1/src/horizon_data_core/api.py +909 -0
- horizon_data_core-0.0.1/src/horizon_data_core/base_types.py +357 -0
- horizon_data_core-0.0.1/src/horizon_data_core/client.py +87 -0
- horizon_data_core-0.0.1/src/horizon_data_core/helpers.py +104 -0
- horizon_data_core-0.0.1/src/horizon_data_core/logging.py +103 -0
- horizon_data_core-0.0.1/src/horizon_data_core/orm_types.py +253 -0
- horizon_data_core-0.0.1/src/horizon_data_core/py.typed +0 -0
- horizon_data_core-0.0.1/src/horizon_data_core/resources/__init__.py +1 -0
- horizon_data_core-0.0.1/src/horizon_data_core/resources/database.py +101 -0
- horizon_data_core-0.0.1/src/horizon_data_core/resources/postgres_dataframe_io_manager.py +225 -0
- horizon_data_core-0.0.1/src/horizon_data_core/resources/py.typed +0 -0
- horizon_data_core-0.0.1/src/horizon_data_core/resources/s3.py +17 -0
- horizon_data_core-0.0.1/src/horizon_data_core/sdk.py +1588 -0
- horizon_data_core-0.0.1/tests/__init__.py +1 -0
- horizon_data_core-0.0.1/tests/test_api.py +365 -0
- horizon_data_core-0.0.1/tests/test_helpers.py +105 -0
- horizon_data_core-0.0.1/tests/test_logging.py +29 -0
- horizon_data_core-0.0.1/tests/test_postgres_io.py +420 -0
- horizon_data_core-0.0.1/tests/test_resources_s3.py +8 -0
- horizon_data_core-0.0.1/tests/test_sdk.py +302 -0
- horizon_data_core-0.0.1/turbo.json +41 -0
- horizon_data_core-0.0.1/uv.lock +1734 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
*.tsbuildinfo
|
|
2
|
+
.coverage
|
|
3
|
+
.coverage_reports
|
|
4
|
+
.mypy_cache
|
|
5
|
+
.pytest_cache
|
|
6
|
+
.ruff_cache
|
|
7
|
+
.turbo
|
|
8
|
+
.venv
|
|
9
|
+
__pycache__
|
|
10
|
+
node_modules
|
|
11
|
+
tmp*
|
|
12
|
+
minio_data
|
|
13
|
+
*.duckdb
|
|
14
|
+
*.duckdb.wal
|
|
15
|
+
dagster_home/*
|
|
16
|
+
!dagster_home/dagster.yaml
|
|
17
|
+
pretrained_models
|
|
18
|
+
htmlcov
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
# @spear-ai/horizon-data-core
|
|
2
|
+
|
|
3
|
+
## 3.11.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 64177c0: Synchronize shared developer tooling versions across packages via a catalog.
|
|
8
|
+
- Updated dependencies [64177c0]
|
|
9
|
+
- Updated dependencies [bcb856f]
|
|
10
|
+
- @spear-ai/horizon-database@3.11.2
|
|
11
|
+
|
|
12
|
+
## 3.11.1
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- d77906c: Fixed the release action after the pnpm migration.
|
|
17
|
+
- Updated dependencies [e9e4e5a]
|
|
18
|
+
- Updated dependencies [488ed7c]
|
|
19
|
+
- Updated dependencies [d77906c]
|
|
20
|
+
- @spear-ai/horizon-database@3.11.1
|
|
21
|
+
|
|
22
|
+
## 3.11.0
|
|
23
|
+
|
|
24
|
+
### Minor Changes
|
|
25
|
+
|
|
26
|
+
- bef40ed: Migrated from Yarn 4 to PNPM 10 for workspace and package management.
|
|
27
|
+
- cae99c1: Added a human-friendly `name` field to the data_stream table for display in the UI, and updated the SDK to generate idempotent data stream IDs based on sensor and platform names.
|
|
28
|
+
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- 798ad81: Added elevation, update_rate, and normalizer fields to BearingTimeRecordSpecification across horizon-data-core, horizon-database, and horizon-app packages
|
|
32
|
+
- 8d93639: Completed a dependency management and update pass.
|
|
33
|
+
- dfc3dd6: Add pitch, roll, and speed_over_ground fields to metadata_row table in horizon-database
|
|
34
|
+
- b2f2d36: Added elevation, update_rate, and normalizer fields to BeamgramSpecification across horizon-data-core, horizon-database, and horizon-app packages
|
|
35
|
+
- Updated dependencies [5de93a0]
|
|
36
|
+
- Updated dependencies [087f0c7]
|
|
37
|
+
- Updated dependencies [f044c34]
|
|
38
|
+
- Updated dependencies [798ad81]
|
|
39
|
+
- Updated dependencies [7bf8707]
|
|
40
|
+
- Updated dependencies [7de66a6]
|
|
41
|
+
- Updated dependencies [8c32a5d]
|
|
42
|
+
- Updated dependencies [8d93639]
|
|
43
|
+
- Updated dependencies [087f0c7]
|
|
44
|
+
- Updated dependencies [7440a27]
|
|
45
|
+
- Updated dependencies [bef40ed]
|
|
46
|
+
- Updated dependencies [dfc3dd6]
|
|
47
|
+
- Updated dependencies [b2f2d36]
|
|
48
|
+
- Updated dependencies [cae99c1]
|
|
49
|
+
- Updated dependencies [9262ea7]
|
|
50
|
+
- Updated dependencies [8641344]
|
|
51
|
+
- @spear-ai/horizon-database@3.11.0
|
|
52
|
+
|
|
53
|
+
## 3.10.0
|
|
54
|
+
|
|
55
|
+
### Minor Changes
|
|
56
|
+
|
|
57
|
+
- 8ff4746: Make several fixes to how the SDK handles the life cycle of a connection to iceberg catalog
|
|
58
|
+
|
|
59
|
+
Changed the default SDK behavior to only write data to postgres instead of iceberg
|
|
60
|
+
|
|
61
|
+
BREAKING CHANGES:
|
|
62
|
+
- Changes how SDK is initialized. Now must provide catalog parameters, not a catalog
|
|
63
|
+
- Change from "create" and "create_or_update" verbs to "insert" and "upsert" verbs in the SDK
|
|
64
|
+
|
|
65
|
+
### Patch Changes
|
|
66
|
+
|
|
67
|
+
- 7affe45: Update shared dependencies and tooling
|
|
68
|
+
- Updated dependencies [c1f5996]
|
|
69
|
+
- Updated dependencies [7affe45]
|
|
70
|
+
- Updated dependencies [5462d23]
|
|
71
|
+
- Updated dependencies [8ff4746]
|
|
72
|
+
- @spear-ai/horizon-database@3.10.0
|
|
73
|
+
|
|
74
|
+
## 3.9.0
|
|
75
|
+
|
|
76
|
+
### Patch Changes
|
|
77
|
+
|
|
78
|
+
- Updated dependencies [d9ecabb]
|
|
79
|
+
- @spear-ai/horizon-database@3.9.0
|
|
80
|
+
|
|
81
|
+
## 3.8.0
|
|
82
|
+
|
|
83
|
+
### Patch Changes
|
|
84
|
+
|
|
85
|
+
- Updated dependencies [2502b1f]
|
|
86
|
+
- Updated dependencies [0aaed7e]
|
|
87
|
+
- @spear-ai/horizon-database@3.8.0
|
|
88
|
+
|
|
89
|
+
## 3.7.1
|
|
90
|
+
|
|
91
|
+
### Patch Changes
|
|
92
|
+
|
|
93
|
+
- f97fca5: Linked Horizon package versions.
|
|
94
|
+
- Updated dependencies [197dd9f]
|
|
95
|
+
- Updated dependencies [f97fca5]
|
|
96
|
+
- @spear-ai/horizon-database@3.7.1
|
|
97
|
+
|
|
98
|
+
## 0.3.9
|
|
99
|
+
|
|
100
|
+
### Patch Changes
|
|
101
|
+
|
|
102
|
+
- Updated dependencies [39d3fab]
|
|
103
|
+
- @spear-ai/horizon-database@3.1.4
|
|
104
|
+
|
|
105
|
+
## 0.3.8
|
|
106
|
+
|
|
107
|
+
### Patch Changes
|
|
108
|
+
|
|
109
|
+
- Updated dependencies [186b115]
|
|
110
|
+
- @spear-ai/horizon-database@3.1.3
|
|
111
|
+
|
|
112
|
+
## 0.3.7
|
|
113
|
+
|
|
114
|
+
### Patch Changes
|
|
115
|
+
|
|
116
|
+
- Updated dependencies [2595d3c]
|
|
117
|
+
- @spear-ai/horizon-database@3.1.2
|
|
118
|
+
|
|
119
|
+
## 0.3.6
|
|
120
|
+
|
|
121
|
+
### Patch Changes
|
|
122
|
+
|
|
123
|
+
- Updated dependencies [ef40c73]
|
|
124
|
+
- @spear-ai/horizon-database@3.1.1
|
|
125
|
+
|
|
126
|
+
## 0.3.5
|
|
127
|
+
|
|
128
|
+
### Patch Changes
|
|
129
|
+
|
|
130
|
+
- 7d111f8: Updated dependencies.
|
|
131
|
+
- Updated dependencies [1c37e74]
|
|
132
|
+
- Updated dependencies [1c37e74]
|
|
133
|
+
- Updated dependencies [7d111f8]
|
|
134
|
+
- Updated dependencies [f11ab43]
|
|
135
|
+
- Updated dependencies [26fb39f]
|
|
136
|
+
- Updated dependencies [26fb39f]
|
|
137
|
+
- Updated dependencies [26fb39f]
|
|
138
|
+
- @spear-ai/horizon-database@3.1.0
|
|
139
|
+
|
|
140
|
+
## 0.3.4
|
|
141
|
+
|
|
142
|
+
### Patch Changes
|
|
143
|
+
|
|
144
|
+
- Updated dependencies [0e34c3f]
|
|
145
|
+
- @spear-ai/horizon-database@3.0.1
|
|
146
|
+
|
|
147
|
+
## 0.3.3
|
|
148
|
+
|
|
149
|
+
### Patch Changes
|
|
150
|
+
|
|
151
|
+
- 0c63eab: Switch out psycopg2 for psycopg2-binary to avoid installation errors
|
|
152
|
+
- 873d1c2: Adjusted postgres connector to handle special sslmode case for neon connection.
|
|
153
|
+
- Updated dependencies [873d1c2]
|
|
154
|
+
- Updated dependencies [873d1c2]
|
|
155
|
+
- Updated dependencies [b60aeba]
|
|
156
|
+
- @spear-ai/horizon-database@3.0.0
|
|
157
|
+
|
|
158
|
+
## 0.3.2
|
|
159
|
+
|
|
160
|
+
### Patch Changes
|
|
161
|
+
|
|
162
|
+
- 099931f: Fake patch to induce release.
|
|
163
|
+
- Updated dependencies [099931f]
|
|
164
|
+
- @spear-ai/horizon-database@2.1.2
|
|
165
|
+
|
|
166
|
+
## 0.3.1
|
|
167
|
+
|
|
168
|
+
### Patch Changes
|
|
169
|
+
|
|
170
|
+
- 1152a0e: Fake patch to allow release.
|
|
171
|
+
- Updated dependencies [1152a0e]
|
|
172
|
+
- @spear-ai/horizon-database@2.1.1
|
|
173
|
+
|
|
174
|
+
## 0.3.0
|
|
175
|
+
|
|
176
|
+
### Minor Changes
|
|
177
|
+
|
|
178
|
+
- 5e32b51: Adjusted pipelines generating visual artifacts to produce tiles rather than JSON.
|
|
179
|
+
- 5398cf6: Bump python version from 3.11 to 3.12
|
|
180
|
+
|
|
181
|
+
### Patch Changes
|
|
182
|
+
|
|
183
|
+
- dd7f8bb: Updated linting dependencies across the packages.
|
|
184
|
+
- 5e6c2c2: Bumped dependency versions.
|
|
185
|
+
- 0639322: Updated and synchronized dependencies across packages.
|
|
186
|
+
- Updated dependencies [5e32b51]
|
|
187
|
+
- Updated dependencies [dd7f8bb]
|
|
188
|
+
- Updated dependencies [72f5207]
|
|
189
|
+
- Updated dependencies [1fb74d0]
|
|
190
|
+
- Updated dependencies [51b4231]
|
|
191
|
+
- Updated dependencies [6878a4e]
|
|
192
|
+
- Updated dependencies [5e6c2c2]
|
|
193
|
+
- Updated dependencies [9aa39ae]
|
|
194
|
+
- Updated dependencies [535cd6d]
|
|
195
|
+
- Updated dependencies [0639322]
|
|
196
|
+
- Updated dependencies [249e936]
|
|
197
|
+
- @spear-ai/horizon-database@2.1.0
|
|
198
|
+
|
|
199
|
+
## 0.2.0
|
|
200
|
+
|
|
201
|
+
### Minor Changes
|
|
202
|
+
|
|
203
|
+
- 9862f58: Migrate all data pipelines out into separate repo level packages
|
|
204
|
+
|
|
205
|
+
### Patch Changes
|
|
206
|
+
|
|
207
|
+
- Updated dependencies [b1442f6]
|
|
208
|
+
- Updated dependencies [b1442f6]
|
|
209
|
+
- Updated dependencies [bd1628a]
|
|
210
|
+
- @spear-ai/horizon-database@2.0.0
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: horizon-data-core
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Horizon’s core data SDK.
|
|
5
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
6
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
7
|
+
Requires-Python: <3.13,>=3.12
|
|
8
|
+
Requires-Dist: dagster-aws>=0.22.1
|
|
9
|
+
Requires-Dist: dagster-iceberg>=0.3.3
|
|
10
|
+
Requires-Dist: dagster-pandera>=0.22.1
|
|
11
|
+
Requires-Dist: dagster>=1.6.1
|
|
12
|
+
Requires-Dist: geojson>=3
|
|
13
|
+
Requires-Dist: pandas>=2
|
|
14
|
+
Requires-Dist: pandera[mypy]>=0.18
|
|
15
|
+
Requires-Dist: polars>=1.33.1
|
|
16
|
+
Requires-Dist: psycopg2-binary>=2.9.10
|
|
17
|
+
Requires-Dist: pyarrow>=21.0.0
|
|
18
|
+
Requires-Dist: pydantic>=2.5
|
|
19
|
+
Requires-Dist: pyiceberg[pyarrow,s3fs]>=0.10
|
|
20
|
+
Requires-Dist: pytest>=8.3.4
|
|
21
|
+
Requires-Dist: s3path>=0.6
|
|
22
|
+
Requires-Dist: sqlalchemy[mypy]>=2.0.36
|
|
23
|
+
Requires-Dist: turfpy>=0.0.7
|
|
File without changes
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
# Horizon Data Core SDK
|
|
2
|
+
|
|
3
|
+
The Horizon Data Core SDK provides a simple interface for working with both PostgreSQL and Iceberg tables in the Horizon system.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Pydantic BaseModels**: Type-safe data models for all entities
|
|
8
|
+
- **PostgreSQL Operations**: Full CRUD operations for PostgreSQL tables
|
|
9
|
+
- **Iceberg Operations**: Write and read operations for Iceberg tables
|
|
10
|
+
- **Automatic Conversion**: Seamless conversion between Pydantic models and SQLAlchemy ORM models
|
|
11
|
+
|
|
12
|
+
## Quick Start
|
|
13
|
+
|
|
14
|
+
### 1. Initialize the SDK
|
|
15
|
+
|
|
16
|
+
```python
|
|
17
|
+
from horizon_data_core.api import initialize_sdk
|
|
18
|
+
from horizon_data_core.client import PostgresClient
|
|
19
|
+
from pyiceberg.catalog import load_catalog
|
|
20
|
+
from uuid import uuid4
|
|
21
|
+
|
|
22
|
+
# Set up PostgreSQL client
|
|
23
|
+
postgres_client = PostgresClient(
|
|
24
|
+
organization_id=uuid4(),
|
|
25
|
+
user="postgres",
|
|
26
|
+
passwd="password",
|
|
27
|
+
host="localhost",
|
|
28
|
+
port=5432,
|
|
29
|
+
database_name="horizon"
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
# Set up Iceberg catalog
|
|
33
|
+
iceberg_catalog = load_catalog("rest", uri="http://localhost:8181")
|
|
34
|
+
|
|
35
|
+
# Initialize the SDK with organization_id
|
|
36
|
+
organization_id = uuid4() # This should come from your user context
|
|
37
|
+
initialize_sdk(postgres_client, iceberg_catalog, organization_id)
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### 2. Working with PostgreSQL Tables
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
from horizon_data_core.api import create_entity, read_entity, update_entity, delete_entity, list_entities
|
|
44
|
+
from horizon_data_core.base_types import Entity
|
|
45
|
+
from uuid import uuid4
|
|
46
|
+
from datetime import datetime
|
|
47
|
+
|
|
48
|
+
# Create a new entity
|
|
49
|
+
entity = Entity(
|
|
50
|
+
id=uuid4(),
|
|
51
|
+
name="My Entity",
|
|
52
|
+
kind_id=uuid4(),
|
|
53
|
+
# organization_id will be automatically set by the SDK
|
|
54
|
+
)
|
|
55
|
+
created_entity = create_entity(entity)
|
|
56
|
+
|
|
57
|
+
# Read the entity
|
|
58
|
+
retrieved_entity = read_entity(created_entity.id)
|
|
59
|
+
|
|
60
|
+
# Update the entity
|
|
61
|
+
retrieved_entity.name = "Updated Entity Name"
|
|
62
|
+
updated_entity = update_entity(retrieved_entity)
|
|
63
|
+
|
|
64
|
+
# List entities with filters (organization_id is automatically applied)
|
|
65
|
+
entities = list_entities()
|
|
66
|
+
|
|
67
|
+
# Delete the entity
|
|
68
|
+
delete_entity(updated_entity.id)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### 3. Working with Iceberg Tables
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from horizon_data_core.api import create_data_row, create_metadata_row, list_data_rows, list_metadata_rows
|
|
75
|
+
from horizon_data_core.base_types import DataRow, MetadataRow
|
|
76
|
+
from datetime import datetime
|
|
77
|
+
|
|
78
|
+
# Create a data row
|
|
79
|
+
data_row = DataRow(
|
|
80
|
+
data_stream_id="stream-123",
|
|
81
|
+
datetime=datetime.now(),
|
|
82
|
+
vector=[1.0, 2.0, 3.0, 4.0, 5.0],
|
|
83
|
+
data_type="sensor_data",
|
|
84
|
+
vector_start_bound=0.0,
|
|
85
|
+
vector_end_bound=10.0
|
|
86
|
+
)
|
|
87
|
+
create_data_row(data_row)
|
|
88
|
+
|
|
89
|
+
# Create a metadata row
|
|
90
|
+
metadata_row = MetadataRow(
|
|
91
|
+
data_stream_id="stream-123",
|
|
92
|
+
datetime=datetime.now(),
|
|
93
|
+
latitude=40.7128,
|
|
94
|
+
longitude=-74.0060,
|
|
95
|
+
altitude=10.5,
|
|
96
|
+
speed=25.0,
|
|
97
|
+
heading=90.0
|
|
98
|
+
)
|
|
99
|
+
create_metadata_row(metadata_row)
|
|
100
|
+
|
|
101
|
+
# List data rows with filters
|
|
102
|
+
data_rows = list_data_rows(data_stream_id="stream-123")
|
|
103
|
+
metadata_rows = list_metadata_rows(data_stream_id="stream-123")
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Available Models
|
|
107
|
+
|
|
108
|
+
### PostgreSQL Models
|
|
109
|
+
|
|
110
|
+
- `EntityKind`: A descriptive class of which an `entity` is a physical instantiation of.
|
|
111
|
+
- `Entity`: Core entity instances
|
|
112
|
+
- `DataStream`: Data streams associated with entities
|
|
113
|
+
- `Mission`: Mission definitions
|
|
114
|
+
- `MissionEntity`: Mission-entity relationships
|
|
115
|
+
- `Ontology`: Ontology definitions
|
|
116
|
+
- `OntologyClass`: Classes within ontologies
|
|
117
|
+
- `BeamgramSpecification`: The set of parameters used to specify how a beamgram is constructed
|
|
118
|
+
- `BearingTimeRecordSpecification`: The set of parameters used to specify how a bearing time record is constructed
|
|
119
|
+
- `DataRow`: Time-series data with vector information
|
|
120
|
+
- `MetadataRow`: Location and movement metadata
|
|
121
|
+
|
|
122
|
+
### Iceberg Models
|
|
123
|
+
|
|
124
|
+
- `DataRow`: Time-series data with vector information
|
|
125
|
+
- `MetadataRow`: Location and movement metadata
|
|
126
|
+
|
|
127
|
+
## API Reference
|
|
128
|
+
|
|
129
|
+
### PostgreSQL Operations
|
|
130
|
+
|
|
131
|
+
For each PostgreSQL model, the following operations are available:
|
|
132
|
+
|
|
133
|
+
- `create_[model](model_instance)`: Create a new record
|
|
134
|
+
- `read_[model](id)`: Read a record by ID
|
|
135
|
+
- `read_[model](model_instance)`: Read a record by matching non-id fields
|
|
136
|
+
- `update_[model](model_instance)`: Update an existing record
|
|
137
|
+
- `delete_[model](id)`: Delete a record by ID
|
|
138
|
+
- `list_[models](**filters)`: List records with optional filters
|
|
139
|
+
|
|
140
|
+
### Iceberg Operations
|
|
141
|
+
|
|
142
|
+
For Iceberg models, the following operations are available:
|
|
143
|
+
|
|
144
|
+
- `create_[model](model_instance)`: Create a new record
|
|
145
|
+
- `list_[models](**filters)`: List records with optional filters
|
|
146
|
+
|
|
147
|
+
Note: Update and delete operations for Iceberg tables require table-specific implementation due to the nature of Iceberg's data model.
|
|
148
|
+
|
|
149
|
+
## Error Handling
|
|
150
|
+
|
|
151
|
+
The SDK includes proper error handling for:
|
|
152
|
+
|
|
153
|
+
- Invalid model data
|
|
154
|
+
- Database connection issues
|
|
155
|
+
- Missing records
|
|
156
|
+
- Iceberg catalog connectivity
|
|
157
|
+
|
|
158
|
+
## Examples
|
|
159
|
+
|
|
160
|
+
See below for complete working examples of SDK operations.
|
|
161
|
+
|
|
162
|
+
```python
|
|
163
|
+
"""Example usage of the Horizon Data Core SDK."""
|
|
164
|
+
|
|
165
|
+
from datetime import datetime
|
|
166
|
+
from uuid import uuid4
|
|
167
|
+
|
|
168
|
+
from .api import initialize_sdk
|
|
169
|
+
from .base_types import DataRow, DataStream, Entity, MetadataRow, Mission
|
|
170
|
+
from .client import PostgresClient
|
|
171
|
+
from .helpers import name_to_uuid
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def example_usage() -> None:
|
|
175
|
+
"""Example of how to use the Horizon Data Core SDK."""
|
|
176
|
+
# Initialize the SDK
|
|
177
|
+
postgres_client = PostgresClient(
|
|
178
|
+
user="postgres",
|
|
179
|
+
passwd="password",
|
|
180
|
+
host="localhost",
|
|
181
|
+
port=5432,
|
|
182
|
+
database_name="horizon",
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
# Initialize the SDK with organization_id
|
|
186
|
+
organization_id = uuid4() # This should come from your user context
|
|
187
|
+
sdk = initialize_sdk(postgres_client, {}, organization_id)
|
|
188
|
+
|
|
189
|
+
# Create a new entity
|
|
190
|
+
entity = Entity(
|
|
191
|
+
id=uuid4(),
|
|
192
|
+
name="Example Entity",
|
|
193
|
+
kind_id=uuid4(),
|
|
194
|
+
free_text="This is an example entity",
|
|
195
|
+
# organization_id will be automatically set by the SDK
|
|
196
|
+
)
|
|
197
|
+
created_entity = sdk.create_entity(entity)
|
|
198
|
+
print(f"Created entity: {created_entity}")
|
|
199
|
+
|
|
200
|
+
# Read the entity back
|
|
201
|
+
assert created_entity.id is not None
|
|
202
|
+
retrieved_entity = sdk.read_entity(created_entity.id)
|
|
203
|
+
print(f"Retrieved entity: {retrieved_entity}")
|
|
204
|
+
|
|
205
|
+
# List entities with filters (organization_id is automatically applied)
|
|
206
|
+
entities = sdk.list_entities()
|
|
207
|
+
print(f"Found {len(entities)} entities")
|
|
208
|
+
|
|
209
|
+
# Create a data stream
|
|
210
|
+
data_stream = DataStream(
|
|
211
|
+
id=uuid4(),
|
|
212
|
+
entity_id=created_entity.id,
|
|
213
|
+
# organization_id will be automatically set by the SDK
|
|
214
|
+
)
|
|
215
|
+
created_data_stream = sdk.create_data_stream(data_stream)
|
|
216
|
+
print(f"Created data stream: {created_data_stream}")
|
|
217
|
+
assert created_data_stream.id is not None
|
|
218
|
+
# Create a mission
|
|
219
|
+
mission = Mission(
|
|
220
|
+
id=uuid4(),
|
|
221
|
+
name="Example Mission",
|
|
222
|
+
start_datetime=datetime.now(),
|
|
223
|
+
# organization_id will be automatically set by the SDK
|
|
224
|
+
)
|
|
225
|
+
created_mission = sdk.create_mission(mission)
|
|
226
|
+
print(f"Created mission: {created_mission}")
|
|
227
|
+
|
|
228
|
+
# Create a data row in Postgres
|
|
229
|
+
data_row = DataRow(
|
|
230
|
+
data_stream_id=created_data_stream.id,
|
|
231
|
+
datetime=datetime.now(),
|
|
232
|
+
vector=[1.0, 2.0, 3.0, 4.0, 5.0],
|
|
233
|
+
data_type="example_data",
|
|
234
|
+
track_id=name_to_uuid(
|
|
235
|
+
"example_track"
|
|
236
|
+
), # This should be a valid specification/track_id that has been created previously
|
|
237
|
+
vector_start_bound=0.0,
|
|
238
|
+
vector_end_bound=10.0,
|
|
239
|
+
)
|
|
240
|
+
created_data_row = sdk.create_data_row(data_row)
|
|
241
|
+
print(f"Created data row: {created_data_row}")
|
|
242
|
+
|
|
243
|
+
# Create a metadata row in Iceberg table
|
|
244
|
+
metadata_row = MetadataRow(
|
|
245
|
+
data_stream_id=created_data_stream.id,
|
|
246
|
+
datetime=datetime.now(),
|
|
247
|
+
latitude=40.7128,
|
|
248
|
+
longitude=-74.0060,
|
|
249
|
+
altitude=10.5,
|
|
250
|
+
speed=25.0,
|
|
251
|
+
heading=90.0,
|
|
252
|
+
)
|
|
253
|
+
created_metadata_row = sdk.create_metadata_row(metadata_row)
|
|
254
|
+
print(f"Created metadata row: {created_metadata_row}")
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
if __name__ == "__main__":
|
|
258
|
+
example_usage()
|
|
259
|
+
```
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@spear-ai/horizon-data-core",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Horizon’s core data SDK.",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Spear AI",
|
|
7
|
+
"email": "org@spear.ai",
|
|
8
|
+
"url": "https://spear.ai"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@spear-ai/horizon-database": "workspace:^"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@dotenv-run/cli": "catalog:shared-dev",
|
|
16
|
+
"prettier": "catalog:shared-dev",
|
|
17
|
+
"turbo": "catalog:shared-dev"
|
|
18
|
+
},
|
|
19
|
+
"license": "UNLICENSED",
|
|
20
|
+
"packageManager": "pnpm@10.26.2",
|
|
21
|
+
"private": true,
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"directory": "packages/horizon-data-core",
|
|
25
|
+
"url": "https://github.com/spear-ai/horizon.git"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "uv build",
|
|
29
|
+
"env:dev": "dotenv-run -e development -r ../..",
|
|
30
|
+
"env:production": "dotenv-run -e production -r ../..",
|
|
31
|
+
"env:test": "dotenv-run -e test -r ../..",
|
|
32
|
+
"mypy:check": "uv run mypy .",
|
|
33
|
+
"postinstall": "uv sync",
|
|
34
|
+
"prettier:check": "prettier --check .",
|
|
35
|
+
"prettier:fix": "prettier --write .",
|
|
36
|
+
"publish-package": "pnpm run publish-package:jfrog && pnpm run publish-package:pypi",
|
|
37
|
+
"publish-package:jfrog": "uv publish --check-url \"${JFROG_URL}/artifactory/api/pypi/spear-ai-pypi/simple\" --publish-url \"${JFROG_URL}/artifactory/api/pypi/spear-ai-pypi\" --username \"${JFROG_USERNAME}\" --password \"${JFROG_ACCESS_TOKEN}\"",
|
|
38
|
+
"publish-package:pypi": "uv publish --check-url https://pypi.org/simple --token \"${PYPI_TOKEN}\"",
|
|
39
|
+
"pyprojectfmt:check": "uv run pyproject-fmt --check pyproject.toml --keep-full-version",
|
|
40
|
+
"pyprojectfmt:fix": "uv run pyproject-fmt pyproject.toml --keep-full-version",
|
|
41
|
+
"pytest:test": "pnpm run env:test -- uv run pytest --tb native",
|
|
42
|
+
"ruff-format:check": "uv run ruff format --check .",
|
|
43
|
+
"ruff-format:fix": "uv run ruff format .",
|
|
44
|
+
"ruff-lint:check": "uv run ruff check .",
|
|
45
|
+
"ruff-lint:fix": "uv run ruff check --fix ."
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
build-backend = "hatchling.build"
|
|
3
|
+
requires = [ "hatch-nodejs-version==0.4.0", "hatchling==1.28.0" ]
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "horizon-data-core"
|
|
7
|
+
description = "Horizon’s core data SDK."
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
requires-python = "<3.13,>=3.12"
|
|
10
|
+
classifiers = [
|
|
11
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
12
|
+
"Programming Language :: Python :: 3.12",
|
|
13
|
+
]
|
|
14
|
+
dynamic = [ "version" ]
|
|
15
|
+
dependencies = [
|
|
16
|
+
"dagster>=1.6.1",
|
|
17
|
+
"dagster-aws>=0.22.1",
|
|
18
|
+
"dagster-iceberg>=0.3.3",
|
|
19
|
+
"dagster-pandera>=0.22.1",
|
|
20
|
+
"geojson>=3",
|
|
21
|
+
"pandas>=2",
|
|
22
|
+
"pandera[mypy]>=0.18",
|
|
23
|
+
"polars>=1.33.1",
|
|
24
|
+
"psycopg2-binary>=2.9.10",
|
|
25
|
+
"pyarrow>=21.0.0",
|
|
26
|
+
"pydantic>=2.5",
|
|
27
|
+
"pyiceberg[s3fs,pyarrow]>=0.10",
|
|
28
|
+
"pytest>=8.3.4",
|
|
29
|
+
"s3path>=0.6",
|
|
30
|
+
"sqlalchemy[mypy]>=2.0.36",
|
|
31
|
+
"turfpy>=0.0.7",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
[dependency-groups]
|
|
35
|
+
dev = [
|
|
36
|
+
"boto3-stubs[s3]>=1.34.29",
|
|
37
|
+
"mypy>=1.8",
|
|
38
|
+
"pandas-stubs>=2",
|
|
39
|
+
"pyarrow-stubs>=20.0.0.20250928",
|
|
40
|
+
"pyproject-fmt>=2.6",
|
|
41
|
+
"pytest>=7",
|
|
42
|
+
"pytest-cov>=4",
|
|
43
|
+
"ruff>=0.6.4",
|
|
44
|
+
"types-pillow>=10",
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
[tool.hatch.version]
|
|
48
|
+
source = "nodejs"
|
|
49
|
+
|
|
50
|
+
[tool.pytest.ini_options]
|
|
51
|
+
addopts = "--cov=src --cov-report html --cov-fail-under=90"
|
|
52
|
+
testpaths = [ "." ]
|
|
53
|
+
|
|
54
|
+
[tool.pyright]
|
|
55
|
+
venvPath = "."
|
|
56
|
+
venv = ".venv"
|