[![PyPI version](https://badge.fury.io/py/odd-models.svg)](https://badge.fury.io/py/odd-models)
# OpenDataDiscovery Models package
Has some useful tools for working with OpenDataDiscovery. Such as:
1. Generated Python models from OpenDataDiscovery specification.
2. API Client for working with OpenDataDiscovery.
3. API for manual discovering data entities.
### Installation
```bash
pip install odd-models
```
### Models using example
**odd-models.models** package provides automatically generated Python model by OpenDataDiscovery specification.
It can be used for creating data entities for uploading them into the Platform.
Code example ([full code](./examples/postgres_models.py)):
```python
from oddrn_generator import PostgresqlGenerator
from odd_models.models import DataEntity, DataSet, DataSetField, DataSetFieldType, DataEntityType, Type, MetadataExtension
generator = PostgresqlGenerator(host_settings="localhost", databases="my_database", schemas="public")
DataEntity(
oddrn=generator.get_oddrn_by_path("tables", "my_table"),
name="my_table",
type=DataEntityType.TABLE,
metadata=[MetadataExtension(schema_url="https://example.com/schema.json", metadata={"env": "DEV"})],
dataset=DataSet(
field_list=[
DataSetField(
oddrn=generator.get_oddrn_by_path("tables_columns", "name"),
name="name",
type=DataSetFieldType(
type=Type.TYPE_STRING,
logical_type='str',
is_nullable=False
),
)
]
)
)
```
### HTTP Client for OpenDataDiscovery
___
**odd-models.client** package provides API client for OpenDataDiscovery API.
Client provides an API for working with OpenDataDiscovery Platform.
It has various methods for working with data sources, data entities, management etc.
Code example([full code](./examples/client.py)):
```python
from examples.postgres_models import data_entity_list, generator
from odd_models.api_client.v2.odd_api_client import Client
client = Client(host="http://localhost:8080")
client.auth(name="postgres", description="Token for dev AWS account data sources")
client.create_data_source(
data_source_oddrn=generator.get_data_source_oddrn(),
data_source_name="Postgres data source",
)
client.ingest_data_entity_list(data_entities=data_entity_list)
```
### Manual Discovery API
___
When there is no programmatic way to discover data sources and data entities, **odd-models.discovery** package provides API for manual discovery of data sources and data entities.
Code example([full code](./examples/lambda_discovery.py)):
```python
from odd_models.discovery import DataSource
from odd_models.discovery.data_assets import AWSLambda, S3Artifact
from odd_models.discovery.data_assets.data_asset_list import DataAssetsList
with DataSource("//cloud/aws/dev") as data_source:
validation_lambda = AWSLambda.from_params(
region="eu-central-1", account="0123456789", function_name="validation"
)
input_artifact = S3Artifact.from_url("s3://bucket/folder/test_data.csv")
results = S3Artifact.from_url("s3://bucket/folder/test_result.csv")
metrics = S3Artifact.from_url("s3://bucket/folder/test_metrics.json")
input_artifact >> validation_lambda >> DataAssetsList([results, metrics])
data_source.add_data_asset(validation_lambda)
```
# Development
### Installation
```bash
# Install dependencies
poetry install
# Activate virtual environment
poetry shell
```
### Generating models
```bash
# Generate models. Will generate models pydantic into odd_models/models
make generate_models
# Generate api client. Will generate api client into odd_models/api_client
make generate_client
```
### Tests
```bash
pytest .
```
### Docker build
```bash
docker build -t odd-models .
```
Raw data
{
"_id": null,
"home_page": "https://github.com/opendatadiscovery/odd-models-package",
"name": "odd-models",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": null,
"keywords": "odd-models, odd_models, opendatadiscovery",
"author": "Open Data Discovery",
"author_email": "pypi@opendatadiscovery.org",
"download_url": "https://files.pythonhosted.org/packages/c2/2a/3bf61fc186838a8c95e526cb92d0791ea0bff63bca2fc6f58a4142ec2c51/odd_models-2.0.51.tar.gz",
"platform": null,
"description": "[![PyPI version](https://badge.fury.io/py/odd-models.svg)](https://badge.fury.io/py/odd-models)\n\n# OpenDataDiscovery Models package\nHas some useful tools for working with OpenDataDiscovery. Such as:\n1. Generated Python models from OpenDataDiscovery specification.\n2. API Client for working with OpenDataDiscovery.\n3. API for manual discovering data entities.\n\n### Installation\n```bash\npip install odd-models\n```\n\n### Models using example\n**odd-models.models** package provides automatically generated Python model by OpenDataDiscovery specification.\nIt can be used for creating data entities for uploading them into the Platform.\n\nCode example ([full code](./examples/postgres_models.py)):\n```python\nfrom oddrn_generator import PostgresqlGenerator\nfrom odd_models.models import DataEntity, DataSet, DataSetField, DataSetFieldType, DataEntityType, Type, MetadataExtension\ngenerator = PostgresqlGenerator(host_settings=\"localhost\", databases=\"my_database\", schemas=\"public\")\nDataEntity(\n oddrn=generator.get_oddrn_by_path(\"tables\", \"my_table\"),\n name=\"my_table\",\n type=DataEntityType.TABLE,\n metadata=[MetadataExtension(schema_url=\"https://example.com/schema.json\", metadata={\"env\": \"DEV\"})],\n dataset=DataSet(\n field_list=[\n DataSetField(\n oddrn=generator.get_oddrn_by_path(\"tables_columns\", \"name\"),\n name=\"name\",\n type=DataSetFieldType(\n type=Type.TYPE_STRING,\n logical_type='str',\n is_nullable=False\n ),\n )\n ]\n )\n)\n```\n\n\n### HTTP Client for OpenDataDiscovery\n___\n**odd-models.client** package provides API client for OpenDataDiscovery API.\nClient provides an API for working with OpenDataDiscovery Platform.\nIt has various methods for working with data sources, data entities, management etc.\n\nCode example([full code](./examples/client.py)):\n\n```python\nfrom examples.postgres_models import data_entity_list, generator\nfrom odd_models.api_client.v2.odd_api_client import Client\n\nclient = Client(host=\"http://localhost:8080\")\nclient.auth(name=\"postgres\", description=\"Token for dev AWS account data sources\")\n\nclient.create_data_source(\n data_source_oddrn=generator.get_data_source_oddrn(),\n data_source_name=\"Postgres data source\",\n)\nclient.ingest_data_entity_list(data_entities=data_entity_list)\n```\n\n### Manual Discovery API\n___\nWhen there is no programmatic way to discover data sources and data entities, **odd-models.discovery** package provides API for manual discovery of data sources and data entities.\n\nCode example([full code](./examples/lambda_discovery.py)):\n\n```python\nfrom odd_models.discovery import DataSource\nfrom odd_models.discovery.data_assets import AWSLambda, S3Artifact\nfrom odd_models.discovery.data_assets.data_asset_list import DataAssetsList\n\nwith DataSource(\"//cloud/aws/dev\") as data_source:\n validation_lambda = AWSLambda.from_params(\n region=\"eu-central-1\", account=\"0123456789\", function_name=\"validation\"\n )\n input_artifact = S3Artifact.from_url(\"s3://bucket/folder/test_data.csv\")\n\n results = S3Artifact.from_url(\"s3://bucket/folder/test_result.csv\")\n metrics = S3Artifact.from_url(\"s3://bucket/folder/test_metrics.json\")\n\n input_artifact >> validation_lambda >> DataAssetsList([results, metrics])\n\n data_source.add_data_asset(validation_lambda)\n```\n\n# Development\n\n### Installation\n```bash\n# Install dependencies\npoetry install\n\n# Activate virtual environment\npoetry shell\n```\n\n### Generating models\n```bash\n# Generate models. Will generate models pydantic into odd_models/models\nmake generate_models\n\n# Generate api client. Will generate api client into odd_models/api_client\nmake generate_client\n```\n\n### Tests\n```bash\npytest .\n```\n\n### Docker build\n```bash\ndocker build -t odd-models .\n```\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "Open Data Discovery Models",
"version": "2.0.51",
"project_urls": {
"Homepage": "https://github.com/opendatadiscovery/odd-models-package",
"Repository": "https://github.com/opendatadiscovery/odd-models-package"
},
"split_keywords": [
"odd-models",
" odd_models",
" opendatadiscovery"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "d30e93a52db85d313136860b4362c5eb60e72d763304a54ef12cefe080ce6a2a",
"md5": "e414fefc955d41876fd92d7b65c8374e",
"sha256": "ac9c036ef16deae8d80bba4ae754bd527b4110589d9bdd087e1224098663a960"
},
"downloads": -1,
"filename": "odd_models-2.0.51-py3-none-any.whl",
"has_sig": false,
"md5_digest": "e414fefc955d41876fd92d7b65c8374e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 27833,
"upload_time": "2024-10-28T13:06:25",
"upload_time_iso_8601": "2024-10-28T13:06:25.420406Z",
"url": "https://files.pythonhosted.org/packages/d3/0e/93a52db85d313136860b4362c5eb60e72d763304a54ef12cefe080ce6a2a/odd_models-2.0.51-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "c22a3bf61fc186838a8c95e526cb92d0791ea0bff63bca2fc6f58a4142ec2c51",
"md5": "1050c6f32ea9b7e8ce92594423db8b4a",
"sha256": "c2829f7e94c59c853cde1d4796785ae863a35a194606c8d6f67c0bff955e236d"
},
"downloads": -1,
"filename": "odd_models-2.0.51.tar.gz",
"has_sig": false,
"md5_digest": "1050c6f32ea9b7e8ce92594423db8b4a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 18545,
"upload_time": "2024-10-28T13:06:26",
"upload_time_iso_8601": "2024-10-28T13:06:26.404607Z",
"url": "https://files.pythonhosted.org/packages/c2/2a/3bf61fc186838a8c95e526cb92d0791ea0bff63bca2fc6f58a4142ec2c51/odd_models-2.0.51.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-28 13:06:26",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "opendatadiscovery",
"github_project": "odd-models-package",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "odd-models"
}