diff options
author | CoprDistGit <infra@openeuler.org> | 2023-06-20 04:15:51 +0000 |
---|---|---|
committer | CoprDistGit <infra@openeuler.org> | 2023-06-20 04:15:51 +0000 |
commit | d1eb3f0ac1b8ea9d3c928f64b63a7a9c367a8a9e (patch) | |
tree | af1f4d0ea301646a57aa90864dd094d025ce6482 | |
parent | 7864c3735416561df49b25d65ddec46a275deb9e (diff) |
automatic import of python-origo-sdk-pythonopeneuler20.03
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | python-origo-sdk-python.spec | 1029 | ||||
-rw-r--r-- | sources | 1 |
3 files changed, 1031 insertions, 0 deletions
@@ -0,0 +1 @@ +/origo-sdk-python-0.3.1.tar.gz diff --git a/python-origo-sdk-python.spec b/python-origo-sdk-python.spec new file mode 100644 index 0000000..d048d15 --- /dev/null +++ b/python-origo-sdk-python.spec @@ -0,0 +1,1029 @@ +%global _empty_manifest_terminate_build 0 +Name: python-origo-sdk-python +Version: 0.3.1 +Release: 1 +Summary: SDK for origo +License: MIT License +URL: https://github.com/oslokommune/origo-sdk-python +Source0: https://mirrors.aliyun.com/pypi/web/packages/39/2a/1f9243353872bb5a909aa7eab3c0b29e41456249cd95522ad5b527e548ad/origo-sdk-python-0.3.1.tar.gz +BuildArch: noarch + +Requires: python3-PrettyTable +Requires: python3-PyJWT +Requires: python3-jsonschema +Requires: python3-keycloak +Requires: python3-requests +Requires: python3-urllib3 + +%description +# Deprecation warning + +This module is deprecated in favor of `origo-sdk`. + +The module contents has moved from the `origo` namespace to `origo.sdk`. Ie. +`from origo.data.upload import Upload` is changed to `from +origo.sdk.data.upload import Upload`. + +# Configuration + +When calling any classes interacting with the Origo API and there are no Config params passed to the constructor, a config object will be +automaticly created for you based on environment variables + + +### Environment variables +Default, will pick up configuration from current environment. +The credentials is resolved automatically if you do not set a specific Auth config, in the following order: + +1. _Client Credentials_: If you have added client_id / client_secret to the config. Or if you use the +environment variable equivalent: `ORIGO_CLIENT_ID` / `ORIGO_CLIENT_SECRET`. +2. _Username And Password_: If you have added username / password to the config. Or if you use the +environment variable equivalent: `ORIGO_USERNAME` / `ORIGO_PASSWORD`. +``` +# keycloak user +export ORIGO_USERNAME=my-user + +# keycloak password for ORIGO_USERNAME +export ORIGO_PASSWORD=my-password + +# keycloak client +export ORIGO_CLIENT_ID=my-machine-client + +# keycloak secret for ORIGO_CLIENT_ID +export ORIGO_CLIENT_SECRET=some-generated-secure-string + + +# overrides default environment (dev), but will be trumped by --env=<environment> on the commandline +export ORIGO_ENVIRONMENT=dev|prod + +# If you are sending events and have been assigned a API key +export ORIGO_API_KEY=your-api-key +``` + +### Getting Credentials: +`username/password ` are synced with Oslo municipalities Active Directory so any user with an association can +use their personal account to access the SDK. + +For `client credentials` please contact the data platform team. `dataplattform[at]oslo.kommune.no` + +### TODO: Named profiles +If environment variables are not available, the system will try to load from a default profile: Located in ~/.origo/configuration + +# Usage + +Table of contents: +- [Upload data](#upload-data) +- [Sending events](#sending-events) +- [Create and manage event streams](#create-and-manage-event-streams) +- [Creating datasets with versions and editions](#creating-datasets-with-versions-and-editions) + +## Upload data + +When uploading data you need to refer to an existing dataset that you own, a version and an edition. +If these are non existent then you can create them yourself. This can be achieved [using the sdk](#create-a-new-dataset-with-version-and-edition), +or you can use our [command line interface](https://github.com/oslokommune/origo-cli). + + +```python +from origo.data.upload import Upload +from origo.config import Config + +origo_config = Config() + +# If necessary you can override default values +origo_config.config["cacheCredentials"] = False + +data_uploader = Upload(config=origo_config) + +# Upload file 'data.json' to dataset-id/version/edition +dataset_id = "my-dataset-id" +version = "my-version" # example value: 1 +edition = "my-edition" # example value: 20200618T114038 + +filename = "/path-to-file/data.json" + +# Note! filename must be pointing to an existing file on your disk +upload_response = data_uploader.upload(filename, dataset_id, version, edition) +print(upload_response) +# { +# "result": True, +# "trace_id": "my-dataset-id-54a3c78e-86a3-4631-8f28-0252fe1c7c13" +# } +``` + +The `trace_id` returned by the upload method can be used to "trace" the steps involved in the upload process: + +```python +from origo.status import Status +... +status = Status(config=origo_config) +trace_events = status.get_status(trace_id) +print(trace_events) +# [ +# { +# "trace_id": "my-dataset-1a2bc345-6789-1234-567d-8912ef34a567", +# "trace_status": "STARTED", +# "trace_event_id": "1a2b3cd4-eef5-6aa7-bccd-e889912334f5", +# "trace_event_status": "OK", +# "component": "data-uploader", +# ... +# }, +# { +# "trace_id": "my-dataset-1a2bc345-6789-1234-567d-8912ef34a567", +# "trace_status": "CONTINUE", +# ... +# }, +# { +# "trace_id": "my-dataset-1a2bc345-6789-1234-567d-8912ef34a567", +# "trace_event_id": "1aa2b345-678c-9de1-f2a3-4566bcd78912", +# "trace_status": "FINISHED", +# "trace_event_status": "OK", +# ... +# } +# ] +``` + +## Download data + +When downloading data you need to refer to an existing dataset that you own, a version and an edition. +If these are non existent then you can create them yourself. This can be achieved [using the sdk](#create-a-new-dataset-with-version-and-edition), +or you can use our [command line interface](https://github.com/oslokommune/origo-cli). + +```python +from origo.data.download import Download +from origo.config import Config + +origo_config = Config(env="dev") + +# If necessary you can override default config values +origo_config.config["cacheCredentials"] = False + +data_downloader = Download(config=origo_config) + +dataset_id = "your-dataset-id" +version = "1" +edition = "latest" + +# Downloading a file +res1 = data_downloader.download(dataset_id, version, edition, "my/preferred/output/path") +print(res1) +# { +# "downloaded_files": ["my/preferred/output/path/file_name.csv"] +# } +``` + +## Sending events + +In order to start sending events you will need access to an event stream. If such an event stream is already +in place you are good to go. If not, you can create one either by [using the sdk](#create-and-manage-event-streams), +or by [using our command line interface](https://github.com/oslokommune/origo-cli). + +```python +from origo.event.post_event import PostEvent +from origo.config import Config + +origo_config = Config() + +# If necessary you can override default config values +origo_config.config["cacheCredentials"] = True + +event_poster = PostEvent(config=origo_config) + +dataset_id = "some-dataset-id" +version = "1" +event = {"foo": "bar"} + +res = event_poster.post_event(event, dataset_id, version) +# res: +# {'message': 'Ok'} + +# Method also supports list of dictionaries +event_list = [{"foo": "bar"}, {"foo": "bar"}] + +res2 = event_poster.post_event(event_list, dataset_id, version) +# res2: +# {'message': 'Ok'} + +``` + +## Create and manage event streams + +In order to create an event stream you need to have defined a dataset and a version, +unless these already exist. Defining a dataset and a version can be +achieved [using the sdk](#creating-datasets-with-versions-and-editions), +or you can use our [command line interface](https://github.com/oslokommune/origo-cli). +You do not need to define an edition in order to create an event stream. + +```python +from origo.event.event_stream_client import EventStreamClient + + +# Using default configuration for dev-environment +event_stream_client = EventStreamClient(env="dev") + +dataset_id = "some-dataset-id" +version = "1" + + +# Creating a new event stream: +create_response = event_stream_client.create_event_stream( + dataset_id, version +) +# create_response: +# {'message': 'Accepted'} + + +# Getting info about the event stream +event_stream_info = event_stream_client.get_event_stream_info(dataset_id, version) +# event_stream_info: +# { 'createdAt': '2020-01-29T07:02:32.598520+00:00', +# 'createdBy': 'jd', +# 'id': 'test-stream-manager/1', +# 'status': 'CREATE_IN_PROGRESS' +# } + +# Note! You must wait until the event stream has status=ACTIVE +# before you can successfully send events to the stream + + +# Deleting the event stream +delete_response = event_stream_client.delete_event_stream(dataset_id, version) +# delete_response: +# {'message': 'Delete initiated'} + +``` + + +## Creating datasets with versions and editions +```python +from origo.data.dataset import Dataset +from origo.config import Config + +origo_config = Config() + +# If necessary you can override default values +origo_config.config["cacheCredentials"] = False + +# Create a new dataset +dataset = Dataset(config=origo_config) + +dataset_metadata = { + "title": "Precise Descriptive Title", + "description": "Describe your dataset here", + "keywords": ["some-keyword"], + "accessRights": "public", + "confidentiality": "green", + "objective": "Exemplify how to create a new dataset", + "contactPoint": { + "name": "Your name", + "email": "your_email@domain.com", + "phone": "999555111" + }, + "publisher": "name of organization or person responsible for publishing the data" +} + +new_dataset = dataset.create_dataset(data=dataset_metadata) + +# new_dataset: +# { 'Id': 'precise-descriptive-title', +# 'Type': 'Dataset', +# '_links': {'self': {'href': '/datasets/precise-descriptive-title'}}, +# 'accessRights': 'public', +# 'confidentiality': 'green', +# 'contactPoint': { 'email': 'your_email@domain.com', +# 'name': 'Your name', +# 'phone': '999555111'}, +# 'description': 'Describe your dataset here', +# 'keywords': ['some-keyword'], +# 'objective': 'Exemplify how to create a new dataset', +# 'publisher': 'name of organization or person responsible for publishing the ' +# 'data', +# 'title': 'Precise Descriptive Title'} + + +# create version for new dataset: +version_data = {"version": "1"} +new_version = dataset.create_version(new_dataset["Id"], data=version_data) + +# new_version: +# { 'Id': 'precise-descriptive-title/1', +# 'Type': 'Version', +# '_links': { 'self': { 'href': '/datasets/precise-descriptive-title/versions/1'}}, +# 'version': '1'} + +# create edition for new_dataset/new_version: +import datetime + +# Note! edition-field must be ISO 8601 with utc offset +edition_data = { + "edition": str(datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc).isoformat()), + "description": "My edition description", + "startTime": "2019-01-01", + "endTime": "2019-12-31" +} +new_edition = dataset.create_edition(new_dataset["Id"], new_version["version"], data=edition_data) + +# new_edition +# { 'Id': 'precise-descriptive-title/1/20200115T130439', +# 'Type': 'Edition', +# '_links': { 'self': { 'href': '/datasets/precise-descriptive-title/versions/1/editions/20200115T130439'}}, +# 'description': 'My edition description', +# 'edition': '2020-01-15T13:04:39.041778+00:00', +# 'endTime': '2019-12-31', +# 'startTime': '2019-01-01'} +``` + + + + +%package -n python3-origo-sdk-python +Summary: SDK for origo +Provides: python-origo-sdk-python +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-origo-sdk-python +# Deprecation warning + +This module is deprecated in favor of `origo-sdk`. + +The module contents has moved from the `origo` namespace to `origo.sdk`. Ie. +`from origo.data.upload import Upload` is changed to `from +origo.sdk.data.upload import Upload`. + +# Configuration + +When calling any classes interacting with the Origo API and there are no Config params passed to the constructor, a config object will be +automaticly created for you based on environment variables + + +### Environment variables +Default, will pick up configuration from current environment. +The credentials is resolved automatically if you do not set a specific Auth config, in the following order: + +1. _Client Credentials_: If you have added client_id / client_secret to the config. Or if you use the +environment variable equivalent: `ORIGO_CLIENT_ID` / `ORIGO_CLIENT_SECRET`. +2. _Username And Password_: If you have added username / password to the config. Or if you use the +environment variable equivalent: `ORIGO_USERNAME` / `ORIGO_PASSWORD`. +``` +# keycloak user +export ORIGO_USERNAME=my-user + +# keycloak password for ORIGO_USERNAME +export ORIGO_PASSWORD=my-password + +# keycloak client +export ORIGO_CLIENT_ID=my-machine-client + +# keycloak secret for ORIGO_CLIENT_ID +export ORIGO_CLIENT_SECRET=some-generated-secure-string + + +# overrides default environment (dev), but will be trumped by --env=<environment> on the commandline +export ORIGO_ENVIRONMENT=dev|prod + +# If you are sending events and have been assigned a API key +export ORIGO_API_KEY=your-api-key +``` + +### Getting Credentials: +`username/password ` are synced with Oslo municipalities Active Directory so any user with an association can +use their personal account to access the SDK. + +For `client credentials` please contact the data platform team. `dataplattform[at]oslo.kommune.no` + +### TODO: Named profiles +If environment variables are not available, the system will try to load from a default profile: Located in ~/.origo/configuration + +# Usage + +Table of contents: +- [Upload data](#upload-data) +- [Sending events](#sending-events) +- [Create and manage event streams](#create-and-manage-event-streams) +- [Creating datasets with versions and editions](#creating-datasets-with-versions-and-editions) + +## Upload data + +When uploading data you need to refer to an existing dataset that you own, a version and an edition. +If these are non existent then you can create them yourself. This can be achieved [using the sdk](#create-a-new-dataset-with-version-and-edition), +or you can use our [command line interface](https://github.com/oslokommune/origo-cli). + + +```python +from origo.data.upload import Upload +from origo.config import Config + +origo_config = Config() + +# If necessary you can override default values +origo_config.config["cacheCredentials"] = False + +data_uploader = Upload(config=origo_config) + +# Upload file 'data.json' to dataset-id/version/edition +dataset_id = "my-dataset-id" +version = "my-version" # example value: 1 +edition = "my-edition" # example value: 20200618T114038 + +filename = "/path-to-file/data.json" + +# Note! filename must be pointing to an existing file on your disk +upload_response = data_uploader.upload(filename, dataset_id, version, edition) +print(upload_response) +# { +# "result": True, +# "trace_id": "my-dataset-id-54a3c78e-86a3-4631-8f28-0252fe1c7c13" +# } +``` + +The `trace_id` returned by the upload method can be used to "trace" the steps involved in the upload process: + +```python +from origo.status import Status +... +status = Status(config=origo_config) +trace_events = status.get_status(trace_id) +print(trace_events) +# [ +# { +# "trace_id": "my-dataset-1a2bc345-6789-1234-567d-8912ef34a567", +# "trace_status": "STARTED", +# "trace_event_id": "1a2b3cd4-eef5-6aa7-bccd-e889912334f5", +# "trace_event_status": "OK", +# "component": "data-uploader", +# ... +# }, +# { +# "trace_id": "my-dataset-1a2bc345-6789-1234-567d-8912ef34a567", +# "trace_status": "CONTINUE", +# ... +# }, +# { +# "trace_id": "my-dataset-1a2bc345-6789-1234-567d-8912ef34a567", +# "trace_event_id": "1aa2b345-678c-9de1-f2a3-4566bcd78912", +# "trace_status": "FINISHED", +# "trace_event_status": "OK", +# ... +# } +# ] +``` + +## Download data + +When downloading data you need to refer to an existing dataset that you own, a version and an edition. +If these are non existent then you can create them yourself. This can be achieved [using the sdk](#create-a-new-dataset-with-version-and-edition), +or you can use our [command line interface](https://github.com/oslokommune/origo-cli). + +```python +from origo.data.download import Download +from origo.config import Config + +origo_config = Config(env="dev") + +# If necessary you can override default config values +origo_config.config["cacheCredentials"] = False + +data_downloader = Download(config=origo_config) + +dataset_id = "your-dataset-id" +version = "1" +edition = "latest" + +# Downloading a file +res1 = data_downloader.download(dataset_id, version, edition, "my/preferred/output/path") +print(res1) +# { +# "downloaded_files": ["my/preferred/output/path/file_name.csv"] +# } +``` + +## Sending events + +In order to start sending events you will need access to an event stream. If such an event stream is already +in place you are good to go. If not, you can create one either by [using the sdk](#create-and-manage-event-streams), +or by [using our command line interface](https://github.com/oslokommune/origo-cli). + +```python +from origo.event.post_event import PostEvent +from origo.config import Config + +origo_config = Config() + +# If necessary you can override default config values +origo_config.config["cacheCredentials"] = True + +event_poster = PostEvent(config=origo_config) + +dataset_id = "some-dataset-id" +version = "1" +event = {"foo": "bar"} + +res = event_poster.post_event(event, dataset_id, version) +# res: +# {'message': 'Ok'} + +# Method also supports list of dictionaries +event_list = [{"foo": "bar"}, {"foo": "bar"}] + +res2 = event_poster.post_event(event_list, dataset_id, version) +# res2: +# {'message': 'Ok'} + +``` + +## Create and manage event streams + +In order to create an event stream you need to have defined a dataset and a version, +unless these already exist. Defining a dataset and a version can be +achieved [using the sdk](#creating-datasets-with-versions-and-editions), +or you can use our [command line interface](https://github.com/oslokommune/origo-cli). +You do not need to define an edition in order to create an event stream. + +```python +from origo.event.event_stream_client import EventStreamClient + + +# Using default configuration for dev-environment +event_stream_client = EventStreamClient(env="dev") + +dataset_id = "some-dataset-id" +version = "1" + + +# Creating a new event stream: +create_response = event_stream_client.create_event_stream( + dataset_id, version +) +# create_response: +# {'message': 'Accepted'} + + +# Getting info about the event stream +event_stream_info = event_stream_client.get_event_stream_info(dataset_id, version) +# event_stream_info: +# { 'createdAt': '2020-01-29T07:02:32.598520+00:00', +# 'createdBy': 'jd', +# 'id': 'test-stream-manager/1', +# 'status': 'CREATE_IN_PROGRESS' +# } + +# Note! You must wait until the event stream has status=ACTIVE +# before you can successfully send events to the stream + + +# Deleting the event stream +delete_response = event_stream_client.delete_event_stream(dataset_id, version) +# delete_response: +# {'message': 'Delete initiated'} + +``` + + +## Creating datasets with versions and editions +```python +from origo.data.dataset import Dataset +from origo.config import Config + +origo_config = Config() + +# If necessary you can override default values +origo_config.config["cacheCredentials"] = False + +# Create a new dataset +dataset = Dataset(config=origo_config) + +dataset_metadata = { + "title": "Precise Descriptive Title", + "description": "Describe your dataset here", + "keywords": ["some-keyword"], + "accessRights": "public", + "confidentiality": "green", + "objective": "Exemplify how to create a new dataset", + "contactPoint": { + "name": "Your name", + "email": "your_email@domain.com", + "phone": "999555111" + }, + "publisher": "name of organization or person responsible for publishing the data" +} + +new_dataset = dataset.create_dataset(data=dataset_metadata) + +# new_dataset: +# { 'Id': 'precise-descriptive-title', +# 'Type': 'Dataset', +# '_links': {'self': {'href': '/datasets/precise-descriptive-title'}}, +# 'accessRights': 'public', +# 'confidentiality': 'green', +# 'contactPoint': { 'email': 'your_email@domain.com', +# 'name': 'Your name', +# 'phone': '999555111'}, +# 'description': 'Describe your dataset here', +# 'keywords': ['some-keyword'], +# 'objective': 'Exemplify how to create a new dataset', +# 'publisher': 'name of organization or person responsible for publishing the ' +# 'data', +# 'title': 'Precise Descriptive Title'} + + +# create version for new dataset: +version_data = {"version": "1"} +new_version = dataset.create_version(new_dataset["Id"], data=version_data) + +# new_version: +# { 'Id': 'precise-descriptive-title/1', +# 'Type': 'Version', +# '_links': { 'self': { 'href': '/datasets/precise-descriptive-title/versions/1'}}, +# 'version': '1'} + +# create edition for new_dataset/new_version: +import datetime + +# Note! edition-field must be ISO 8601 with utc offset +edition_data = { + "edition": str(datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc).isoformat()), + "description": "My edition description", + "startTime": "2019-01-01", + "endTime": "2019-12-31" +} +new_edition = dataset.create_edition(new_dataset["Id"], new_version["version"], data=edition_data) + +# new_edition +# { 'Id': 'precise-descriptive-title/1/20200115T130439', +# 'Type': 'Edition', +# '_links': { 'self': { 'href': '/datasets/precise-descriptive-title/versions/1/editions/20200115T130439'}}, +# 'description': 'My edition description', +# 'edition': '2020-01-15T13:04:39.041778+00:00', +# 'endTime': '2019-12-31', +# 'startTime': '2019-01-01'} +``` + + + + +%package help +Summary: Development documents and examples for origo-sdk-python +Provides: python3-origo-sdk-python-doc +%description help +# Deprecation warning + +This module is deprecated in favor of `origo-sdk`. + +The module contents has moved from the `origo` namespace to `origo.sdk`. Ie. +`from origo.data.upload import Upload` is changed to `from +origo.sdk.data.upload import Upload`. + +# Configuration + +When calling any classes interacting with the Origo API and there are no Config params passed to the constructor, a config object will be +automaticly created for you based on environment variables + + +### Environment variables +Default, will pick up configuration from current environment. +The credentials is resolved automatically if you do not set a specific Auth config, in the following order: + +1. _Client Credentials_: If you have added client_id / client_secret to the config. Or if you use the +environment variable equivalent: `ORIGO_CLIENT_ID` / `ORIGO_CLIENT_SECRET`. +2. _Username And Password_: If you have added username / password to the config. Or if you use the +environment variable equivalent: `ORIGO_USERNAME` / `ORIGO_PASSWORD`. +``` +# keycloak user +export ORIGO_USERNAME=my-user + +# keycloak password for ORIGO_USERNAME +export ORIGO_PASSWORD=my-password + +# keycloak client +export ORIGO_CLIENT_ID=my-machine-client + +# keycloak secret for ORIGO_CLIENT_ID +export ORIGO_CLIENT_SECRET=some-generated-secure-string + + +# overrides default environment (dev), but will be trumped by --env=<environment> on the commandline +export ORIGO_ENVIRONMENT=dev|prod + +# If you are sending events and have been assigned a API key +export ORIGO_API_KEY=your-api-key +``` + +### Getting Credentials: +`username/password ` are synced with Oslo municipalities Active Directory so any user with an association can +use their personal account to access the SDK. + +For `client credentials` please contact the data platform team. `dataplattform[at]oslo.kommune.no` + +### TODO: Named profiles +If environment variables are not available, the system will try to load from a default profile: Located in ~/.origo/configuration + +# Usage + +Table of contents: +- [Upload data](#upload-data) +- [Sending events](#sending-events) +- [Create and manage event streams](#create-and-manage-event-streams) +- [Creating datasets with versions and editions](#creating-datasets-with-versions-and-editions) + +## Upload data + +When uploading data you need to refer to an existing dataset that you own, a version and an edition. +If these are non existent then you can create them yourself. This can be achieved [using the sdk](#create-a-new-dataset-with-version-and-edition), +or you can use our [command line interface](https://github.com/oslokommune/origo-cli). + + +```python +from origo.data.upload import Upload +from origo.config import Config + +origo_config = Config() + +# If necessary you can override default values +origo_config.config["cacheCredentials"] = False + +data_uploader = Upload(config=origo_config) + +# Upload file 'data.json' to dataset-id/version/edition +dataset_id = "my-dataset-id" +version = "my-version" # example value: 1 +edition = "my-edition" # example value: 20200618T114038 + +filename = "/path-to-file/data.json" + +# Note! filename must be pointing to an existing file on your disk +upload_response = data_uploader.upload(filename, dataset_id, version, edition) +print(upload_response) +# { +# "result": True, +# "trace_id": "my-dataset-id-54a3c78e-86a3-4631-8f28-0252fe1c7c13" +# } +``` + +The `trace_id` returned by the upload method can be used to "trace" the steps involved in the upload process: + +```python +from origo.status import Status +... +status = Status(config=origo_config) +trace_events = status.get_status(trace_id) +print(trace_events) +# [ +# { +# "trace_id": "my-dataset-1a2bc345-6789-1234-567d-8912ef34a567", +# "trace_status": "STARTED", +# "trace_event_id": "1a2b3cd4-eef5-6aa7-bccd-e889912334f5", +# "trace_event_status": "OK", +# "component": "data-uploader", +# ... +# }, +# { +# "trace_id": "my-dataset-1a2bc345-6789-1234-567d-8912ef34a567", +# "trace_status": "CONTINUE", +# ... +# }, +# { +# "trace_id": "my-dataset-1a2bc345-6789-1234-567d-8912ef34a567", +# "trace_event_id": "1aa2b345-678c-9de1-f2a3-4566bcd78912", +# "trace_status": "FINISHED", +# "trace_event_status": "OK", +# ... +# } +# ] +``` + +## Download data + +When downloading data you need to refer to an existing dataset that you own, a version and an edition. +If these are non existent then you can create them yourself. This can be achieved [using the sdk](#create-a-new-dataset-with-version-and-edition), +or you can use our [command line interface](https://github.com/oslokommune/origo-cli). + +```python +from origo.data.download import Download +from origo.config import Config + +origo_config = Config(env="dev") + +# If necessary you can override default config values +origo_config.config["cacheCredentials"] = False + +data_downloader = Download(config=origo_config) + +dataset_id = "your-dataset-id" +version = "1" +edition = "latest" + +# Downloading a file +res1 = data_downloader.download(dataset_id, version, edition, "my/preferred/output/path") +print(res1) +# { +# "downloaded_files": ["my/preferred/output/path/file_name.csv"] +# } +``` + +## Sending events + +In order to start sending events you will need access to an event stream. If such an event stream is already +in place you are good to go. If not, you can create one either by [using the sdk](#create-and-manage-event-streams), +or by [using our command line interface](https://github.com/oslokommune/origo-cli). + +```python +from origo.event.post_event import PostEvent +from origo.config import Config + +origo_config = Config() + +# If necessary you can override default config values +origo_config.config["cacheCredentials"] = True + +event_poster = PostEvent(config=origo_config) + +dataset_id = "some-dataset-id" +version = "1" +event = {"foo": "bar"} + +res = event_poster.post_event(event, dataset_id, version) +# res: +# {'message': 'Ok'} + +# Method also supports list of dictionaries +event_list = [{"foo": "bar"}, {"foo": "bar"}] + +res2 = event_poster.post_event(event_list, dataset_id, version) +# res2: +# {'message': 'Ok'} + +``` + +## Create and manage event streams + +In order to create an event stream you need to have defined a dataset and a version, +unless these already exist. Defining a dataset and a version can be +achieved [using the sdk](#creating-datasets-with-versions-and-editions), +or you can use our [command line interface](https://github.com/oslokommune/origo-cli). +You do not need to define an edition in order to create an event stream. + +```python +from origo.event.event_stream_client import EventStreamClient + + +# Using default configuration for dev-environment +event_stream_client = EventStreamClient(env="dev") + +dataset_id = "some-dataset-id" +version = "1" + + +# Creating a new event stream: +create_response = event_stream_client.create_event_stream( + dataset_id, version +) +# create_response: +# {'message': 'Accepted'} + + +# Getting info about the event stream +event_stream_info = event_stream_client.get_event_stream_info(dataset_id, version) +# event_stream_info: +# { 'createdAt': '2020-01-29T07:02:32.598520+00:00', +# 'createdBy': 'jd', +# 'id': 'test-stream-manager/1', +# 'status': 'CREATE_IN_PROGRESS' +# } + +# Note! You must wait until the event stream has status=ACTIVE +# before you can successfully send events to the stream + + +# Deleting the event stream +delete_response = event_stream_client.delete_event_stream(dataset_id, version) +# delete_response: +# {'message': 'Delete initiated'} + +``` + + +## Creating datasets with versions and editions +```python +from origo.data.dataset import Dataset +from origo.config import Config + +origo_config = Config() + +# If necessary you can override default values +origo_config.config["cacheCredentials"] = False + +# Create a new dataset +dataset = Dataset(config=origo_config) + +dataset_metadata = { + "title": "Precise Descriptive Title", + "description": "Describe your dataset here", + "keywords": ["some-keyword"], + "accessRights": "public", + "confidentiality": "green", + "objective": "Exemplify how to create a new dataset", + "contactPoint": { + "name": "Your name", + "email": "your_email@domain.com", + "phone": "999555111" + }, + "publisher": "name of organization or person responsible for publishing the data" +} + +new_dataset = dataset.create_dataset(data=dataset_metadata) + +# new_dataset: +# { 'Id': 'precise-descriptive-title', +# 'Type': 'Dataset', +# '_links': {'self': {'href': '/datasets/precise-descriptive-title'}}, +# 'accessRights': 'public', +# 'confidentiality': 'green', +# 'contactPoint': { 'email': 'your_email@domain.com', +# 'name': 'Your name', +# 'phone': '999555111'}, +# 'description': 'Describe your dataset here', +# 'keywords': ['some-keyword'], +# 'objective': 'Exemplify how to create a new dataset', +# 'publisher': 'name of organization or person responsible for publishing the ' +# 'data', +# 'title': 'Precise Descriptive Title'} + + +# create version for new dataset: +version_data = {"version": "1"} +new_version = dataset.create_version(new_dataset["Id"], data=version_data) + +# new_version: +# { 'Id': 'precise-descriptive-title/1', +# 'Type': 'Version', +# '_links': { 'self': { 'href': '/datasets/precise-descriptive-title/versions/1'}}, +# 'version': '1'} + +# create edition for new_dataset/new_version: +import datetime + +# Note! edition-field must be ISO 8601 with utc offset +edition_data = { + "edition": str(datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc).isoformat()), + "description": "My edition description", + "startTime": "2019-01-01", + "endTime": "2019-12-31" +} +new_edition = dataset.create_edition(new_dataset["Id"], new_version["version"], data=edition_data) + +# new_edition +# { 'Id': 'precise-descriptive-title/1/20200115T130439', +# 'Type': 'Edition', +# '_links': { 'self': { 'href': '/datasets/precise-descriptive-title/versions/1/editions/20200115T130439'}}, +# 'description': 'My edition description', +# 'edition': '2020-01-15T13:04:39.041778+00:00', +# 'endTime': '2019-12-31', +# 'startTime': '2019-01-01'} +``` + + + + +%prep +%autosetup -n origo-sdk-python-0.3.1 + +%build +%py3_build + +%install +%py3_install +install -d -m755 %{buildroot}/%{_pkgdocdir} +if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi +if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi +if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi +if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi +pushd %{buildroot} +if [ -d usr/lib ]; then + find usr/lib -type f -printf "\"/%h/%f\"\n" >> filelist.lst +fi +if [ -d usr/lib64 ]; then + find usr/lib64 -type f -printf "\"/%h/%f\"\n" >> filelist.lst +fi +if [ -d usr/bin ]; then + find usr/bin -type f -printf "\"/%h/%f\"\n" >> filelist.lst +fi +if [ -d usr/sbin ]; then + find usr/sbin -type f -printf "\"/%h/%f\"\n" >> filelist.lst +fi +touch doclist.lst +if [ -d usr/share/man ]; then + find usr/share/man -type f -printf "\"/%h/%f.gz\"\n" >> doclist.lst +fi +popd +mv %{buildroot}/filelist.lst . +mv %{buildroot}/doclist.lst . + +%files -n python3-origo-sdk-python -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Tue Jun 20 2023 Python_Bot <Python_Bot@openeuler.org> - 0.3.1-1 +- Package Spec generated @@ -0,0 +1 @@ +395fc95719d9e6e6362041fc12603238 origo-sdk-python-0.3.1.tar.gz |