Name | PyOdataEdmModel JSON |
Version |
1.0.5
JSON |
| download |
home_page | |
Summary | The ODataEdmBuilder is a Python class that facilitates the construction of an Entity Data Model (EDM) for OData services. |
upload_time | 2023-10-26 11:41:46 |
maintainer | |
docs_url | None |
author | Wessel Reijngoud |
requires_python | |
license | |
keywords |
odata
edmmodel
metadata
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# ODataEdmBuilder - Readme
The `ODataEdmBuilder` is a Python class that facilitates the construction of Entity Data Model (EDM) metadata for OData services. OData is an open standard protocol that enables the creation and consumption of RESTful APIs for data access and manipulation.
OData is a widely-used protocol for building and consuming RESTful APIs. To expose data through OData, you need to define an Entity Data Model (EDM), which describes the data entities, their properties, and the relationships between them. Manually creating EDM metadata can be complex and error-prone. The OData EDM Builder simplifies this process, allowing you to generate EDM metadata with ease.
## Table of Contents
1. [Overview](#overview)
2. [Dependencies](#dependencies)
3. [Usage](#usage)
4. [Class Methods](#class-methods)
5. [Example](#example)
## 1. Overview <a name="overview"></a>
The `ODataEdmBuilder` class simplifies the creation of metadata for OData services by providing methods to define schemas, entity types, entity containers, properties, and keys. The resulting metadata is represented in EDMX format, which is an XML-based representation of the OData service metadata.
The class includes the following main features:
- Defining namespaces and service names for the OData service.
- Adding schemas with optional aliases.
- Creating entity types with properties, including support for inheritance.
- Defining keys for entity types.
- Constructing entity containers with entity sets.
- Generating EDMX metadata document.
## 1.1. Getting Started
Odata data type mapping is different depending on the source, in the config/template.json file you can find the already defined Odata data type mappings available. In the config/settings.json you can change the source of your data to correctly get the mapping from the template file. If your data source is not yet present in the template file, add it manually as a dict in a dict.
## Code Formatting
This project follows the "black" code formatting style. "black" is an opinionated code formatter that automatically formats Python code to ensure consistent style and readability. To learn more about "black," visit the [official repository](https://github.com/psf/black).
## 2. Dependencies <a name="dependencies"></a>
To install the needed dependencies please run:
```pip install -r requirements.txt```
## 3. Usage <a name="usage"></a>
### Configuration Files
Ensure that the following configuration files are present in the `config` directory:
1. **settings.json**: Contains database client information and other configuration settings.
2. **template.json**: Contains template information for EDM model generation.
### Running the Script
To create a EdmModel from either a SQL (json) result or a Dataframe result follow either of these two options:
### `create_edm_model_from_sql_result(namespace_name, service_name, schema_name, container_name, json_result)`
This function generates an EDM model based on SQL query results provided in JSON format. It takes namespace name, service name, schema name, container name, and JSON result as input. The function utilizes the `ODataEdmBuilder` class from `EdmModel.py` to create the EDM model. It maps SQL query results to EDM entities and properties, generating a comprehensive EDM model representation.
### `create_edm_model_from_df_result(namespace_name, service_name, schema_name, container_name, df)`
This function generates an EDM model based on a pandas DataFrame. It takes namespace name, service name, schema name, container name, and a pandas DataFrame as input. Similar to the SQL result function, it utilizes the `ODataEdmBuilder` class from `EdmModel.py` to create the EDM model. The function maps DataFrame columns to EDM properties, creating the necessary entity types and sets within the EDM model.
## 3.1 To use the `ODataEdmBuilder` class, follow these steps:
1. Create an instance of the `ODataEdmBuilder` by providing the `namespace` and `service_name` parameters.
2. Use the provided methods to define schemas, entity types, keys, properties, and entity containers.
3. Call the `generate_metadata()` method to generate the EDMX metadata document as a string.
4. Optionally, you can call the `clear()` method to reset the `ODataEdmBuilder` object
## 4. Class Methods <a name="class-methods"></a>
The `ODataEdmBuilder` class includes the following methods:
### 4.1 Constructor
```python
def __init__(self, namespace: str, service_name: str)
```
The constructor initializes the `ODataEdmBuilder` object with the specified `namespace` and `service_name`.
### 4.2 Schema Methods
```python
def add_schema(self, schema_name: str, alias: str = "") -> dict
```
Adds a schema with the given `schema_name` to the `ODataEdmBuilder` object. Optionally, you can provide an `alias` for the schema.
```python
def get_schema_by_name(self, schema_name: str)
```
Retrieves a schema dictionary by its `schema_name` or `alias`.
### 4.3 Entity Container Methods
```python
def add_entity_container(self, schema: dict | str, container_name: str) -> dict
```
Adds an entity container with the given `container_name` to the `ODataEdmBuilder` object under the specified `schema`.
### 4.4 Entity Set Methods
```python
def add_entity_set(self, schema: Uniont[dict, str], entity_container: dict, entity_set_name: str, entity_type_name: str) -> dict
```
Adds an entity set with the given `entity_set_name` and `entity_type_name` to the specified `entity_container` in the `schema` in the `ODataEdmBuilder` object.
### 4.5 Entity Type Methods
```python
def add_entity_type(self, schema: dict | str, entity_type_name: str, base_type: str = "", summary: str = "", long_description: str = "") -> dict
```
Adds an entity type with the given `entity_type_name` and optional `base_type` to the specified `schema` in the `ODataEdmBuilder` object. Optionally, you can include a `summary` and `long_description` for documentation purposes.
```python
def add_key(self, entity_type: dict, property_name: str, property_type: str)
```
Adds keys with a property name to the specified `entity_type` as PropertyRef.
```python
def add_property(self, entity_type: dict, property_name: str, property_type: str, nullable: bool = True) -> dict
```
Adds properties with a `property_name`, `property_type`, and `nullable` setting to the specified `entity_type` in the `ODataEdmBuilder` object.
### 4.6 Metadata Generation
```python
def generate_metadata(self) -> str
```
Generates the EDMX metadata document based on the configurations set in the `ODataEdmBuilder` object and returns it as a string.
## 5. Example <a name="example"></a>
Here is an example of how to use the `ODataEdmBuilder` class to create EDMX metadata:
```python
# Create an instance of ODataEdmBuilder
odata_builder = ODataEdmBuilder(namespace="MyNamespace", service_name="MyODataService")
# Add a schema with alias
schema = odata_builder.add_schema(schema_name="MySchema", alias="ms")
# Add an entity type with properties and keys
person_type = odata_builder.add_entity_type(
schema=schema,
entity_type_name="Person",
summary="Represents a person entity.",
long_description="This entity represents information about a person.",
)
odata_builder.add_property(person_type, "Id", "Edm.Int32")
odata_builder.add_key(person_type, "Id", "Edm.Int32")
odata_builder.add_property(person_type, "Name", "Edm.String")
odata_builder.add_property(person_type, "Age", "Edm.Int32")
# Add an entity container and entity set
container = odata_builder.add_entity_container(schema=schema, container_name="MyContainer")
odata_builder.add_entity_set(container, entity_set_name="People", entity_type_name="MySchema.Person")
# Generate and print the EDMX metadata document
metadata = odata_builder.generate_metadata()
print(metadata)
```
## License
This project is licensed under the GNU 3 License. See the [LICENSE](LICENSE) file for details.
Raw data
{
"_id": null,
"home_page": "",
"name": "PyOdataEdmModel",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "odata edmmodel metadata",
"author": "Wessel Reijngoud",
"author_email": "wreijngoud@ilionx.com",
"download_url": "https://files.pythonhosted.org/packages/94/e7/cb1d56ddd07a74755c326572531a70e9e94a564af12c0edee6617e1782a3/PyOdataEdmModel-1.0.5.tar.gz",
"platform": null,
"description": "# ODataEdmBuilder - Readme\n\nThe `ODataEdmBuilder` is a Python class that facilitates the construction of Entity Data Model (EDM) metadata for OData services. OData is an open standard protocol that enables the creation and consumption of RESTful APIs for data access and manipulation.\nOData is a widely-used protocol for building and consuming RESTful APIs. To expose data through OData, you need to define an Entity Data Model (EDM), which describes the data entities, their properties, and the relationships between them. Manually creating EDM metadata can be complex and error-prone. The OData EDM Builder simplifies this process, allowing you to generate EDM metadata with ease.\n\n## Table of Contents\n\n1. [Overview](#overview)\n2. [Dependencies](#dependencies)\n3. [Usage](#usage)\n4. [Class Methods](#class-methods)\n5. [Example](#example)\n\n## 1. Overview <a name=\"overview\"></a>\n\nThe `ODataEdmBuilder` class simplifies the creation of metadata for OData services by providing methods to define schemas, entity types, entity containers, properties, and keys. The resulting metadata is represented in EDMX format, which is an XML-based representation of the OData service metadata.\n\nThe class includes the following main features:\n- Defining namespaces and service names for the OData service.\n- Adding schemas with optional aliases.\n- Creating entity types with properties, including support for inheritance.\n- Defining keys for entity types.\n- Constructing entity containers with entity sets.\n- Generating EDMX metadata document.\n\n## 1.1. Getting Started\nOdata data type mapping is different depending on the source, in the config/template.json file you can find the already defined Odata data type mappings available. In the config/settings.json you can change the source of your data to correctly get the mapping from the template file. If your data source is not yet present in the template file, add it manually as a dict in a dict. \n\n## Code Formatting\n\nThis project follows the \"black\" code formatting style. \"black\" is an opinionated code formatter that automatically formats Python code to ensure consistent style and readability. To learn more about \"black,\" visit the [official repository](https://github.com/psf/black).\n\n## 2. Dependencies <a name=\"dependencies\"></a>\nTo install the needed dependencies please run:\n```pip install -r requirements.txt```\n\n\n## 3. Usage <a name=\"usage\"></a>\n\n### Configuration Files\n\nEnsure that the following configuration files are present in the `config` directory:\n\n1. **settings.json**: Contains database client information and other configuration settings.\n2. **template.json**: Contains template information for EDM model generation.\n\n### Running the Script\n\nTo create a EdmModel from either a SQL (json) result or a Dataframe result follow either of these two options:\n\n### `create_edm_model_from_sql_result(namespace_name, service_name, schema_name, container_name, json_result)`\n\nThis function generates an EDM model based on SQL query results provided in JSON format. It takes namespace name, service name, schema name, container name, and JSON result as input. The function utilizes the `ODataEdmBuilder` class from `EdmModel.py` to create the EDM model. It maps SQL query results to EDM entities and properties, generating a comprehensive EDM model representation.\n\n### `create_edm_model_from_df_result(namespace_name, service_name, schema_name, container_name, df)`\n\nThis function generates an EDM model based on a pandas DataFrame. It takes namespace name, service name, schema name, container name, and a pandas DataFrame as input. Similar to the SQL result function, it utilizes the `ODataEdmBuilder` class from `EdmModel.py` to create the EDM model. The function maps DataFrame columns to EDM properties, creating the necessary entity types and sets within the EDM model.\n\n\n\n## 3.1 To use the `ODataEdmBuilder` class, follow these steps:\n\n1. Create an instance of the `ODataEdmBuilder` by providing the `namespace` and `service_name` parameters.\n\n2. Use the provided methods to define schemas, entity types, keys, properties, and entity containers.\n\n3. Call the `generate_metadata()` method to generate the EDMX metadata document as a string.\n\n4. Optionally, you can call the `clear()` method to reset the `ODataEdmBuilder` object \n\n## 4. Class Methods <a name=\"class-methods\"></a>\n\nThe `ODataEdmBuilder` class includes the following methods:\n\n### 4.1 Constructor\n\n```python\ndef __init__(self, namespace: str, service_name: str)\n```\n\nThe constructor initializes the `ODataEdmBuilder` object with the specified `namespace` and `service_name`.\n\n### 4.2 Schema Methods\n\n```python\ndef add_schema(self, schema_name: str, alias: str = \"\") -> dict\n```\n\nAdds a schema with the given `schema_name` to the `ODataEdmBuilder` object. Optionally, you can provide an `alias` for the schema.\n\n```python\ndef get_schema_by_name(self, schema_name: str)\n```\n\nRetrieves a schema dictionary by its `schema_name` or `alias`.\n\n### 4.3 Entity Container Methods\n\n```python\ndef add_entity_container(self, schema: dict | str, container_name: str) -> dict\n```\n\nAdds an entity container with the given `container_name` to the `ODataEdmBuilder` object under the specified `schema`.\n\n### 4.4 Entity Set Methods\n\n```python\ndef add_entity_set(self, schema: Uniont[dict, str], entity_container: dict, entity_set_name: str, entity_type_name: str) -> dict\n```\n\nAdds an entity set with the given `entity_set_name` and `entity_type_name` to the specified `entity_container` in the `schema` in the `ODataEdmBuilder` object.\n\n### 4.5 Entity Type Methods\n\n```python\ndef add_entity_type(self, schema: dict | str, entity_type_name: str, base_type: str = \"\", summary: str = \"\", long_description: str = \"\") -> dict\n```\n\nAdds an entity type with the given `entity_type_name` and optional `base_type` to the specified `schema` in the `ODataEdmBuilder` object. Optionally, you can include a `summary` and `long_description` for documentation purposes.\n\n```python\ndef add_key(self, entity_type: dict, property_name: str, property_type: str)\n```\n\nAdds keys with a property name to the specified `entity_type` as PropertyRef.\n\n```python\ndef add_property(self, entity_type: dict, property_name: str, property_type: str, nullable: bool = True) -> dict\n```\n\nAdds properties with a `property_name`, `property_type`, and `nullable` setting to the specified `entity_type` in the `ODataEdmBuilder` object.\n\n### 4.6 Metadata Generation\n\n```python\ndef generate_metadata(self) -> str\n```\n\nGenerates the EDMX metadata document based on the configurations set in the `ODataEdmBuilder` object and returns it as a string.\n\n## 5. Example <a name=\"example\"></a>\n\nHere is an example of how to use the `ODataEdmBuilder` class to create EDMX metadata:\n\n```python\n# Create an instance of ODataEdmBuilder\nodata_builder = ODataEdmBuilder(namespace=\"MyNamespace\", service_name=\"MyODataService\")\n\n# Add a schema with alias\nschema = odata_builder.add_schema(schema_name=\"MySchema\", alias=\"ms\")\n\n# Add an entity type with properties and keys\nperson_type = odata_builder.add_entity_type(\n schema=schema,\n entity_type_name=\"Person\",\n summary=\"Represents a person entity.\",\n long_description=\"This entity represents information about a person.\",\n)\nodata_builder.add_property(person_type, \"Id\", \"Edm.Int32\")\nodata_builder.add_key(person_type, \"Id\", \"Edm.Int32\")\nodata_builder.add_property(person_type, \"Name\", \"Edm.String\")\nodata_builder.add_property(person_type, \"Age\", \"Edm.Int32\")\n\n# Add an entity container and entity set\ncontainer = odata_builder.add_entity_container(schema=schema, container_name=\"MyContainer\")\nodata_builder.add_entity_set(container, entity_set_name=\"People\", entity_type_name=\"MySchema.Person\")\n\n# Generate and print the EDMX metadata document\nmetadata = odata_builder.generate_metadata()\nprint(metadata)\n```\n\n## License\nThis project is licensed under the GNU 3 License. See the [LICENSE](LICENSE) file for details.\n",
"bugtrack_url": null,
"license": "",
"summary": "The ODataEdmBuilder is a Python class that facilitates the construction of an Entity Data Model (EDM) for OData services.",
"version": "1.0.5",
"project_urls": {
"Source": "https://github.com/wesselreijngoud/PyOdataEdmModel"
},
"split_keywords": [
"odata",
"edmmodel",
"metadata"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "2a3ecdad807216ac31935c84af174f0ca20d442cc59b7660baabaa66adf0388d",
"md5": "e061beda6fe695dc5cb74538d8ec8d17",
"sha256": "aa6ab4fdd87416801fff7a009b688ea4e435c8da76b6769dd5a6b20a37b70d81"
},
"downloads": -1,
"filename": "PyOdataEdmModel-1.0.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "e061beda6fe695dc5cb74538d8ec8d17",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 27041,
"upload_time": "2023-10-26T11:41:44",
"upload_time_iso_8601": "2023-10-26T11:41:44.661002Z",
"url": "https://files.pythonhosted.org/packages/2a/3e/cdad807216ac31935c84af174f0ca20d442cc59b7660baabaa66adf0388d/PyOdataEdmModel-1.0.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "94e7cb1d56ddd07a74755c326572531a70e9e94a564af12c0edee6617e1782a3",
"md5": "3391f79573a5e2b36542cf7cc37ceedb",
"sha256": "acc8a4826d3fcaeea1da9bdaa34b26b77c82c9312579e637cd5576d1fadfee97"
},
"downloads": -1,
"filename": "PyOdataEdmModel-1.0.5.tar.gz",
"has_sig": false,
"md5_digest": "3391f79573a5e2b36542cf7cc37ceedb",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 27045,
"upload_time": "2023-10-26T11:41:46",
"upload_time_iso_8601": "2023-10-26T11:41:46.502919Z",
"url": "https://files.pythonhosted.org/packages/94/e7/cb1d56ddd07a74755c326572531a70e9e94a564af12c0edee6617e1782a3/PyOdataEdmModel-1.0.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-10-26 11:41:46",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "wesselreijngoud",
"github_project": "PyOdataEdmModel",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "pyodataedmmodel"
}