apache-atlas


Nameapache-atlas JSON
Version 0.0.16 PyPI version JSON
download
home_pagehttps://github.com/apache/atlas/tree/master/intg/src/main/python
SummaryApache Atlas Python Client
upload_time2024-11-22 21:33:15
maintainerNone
docs_urlNone
authorApache Atlas
requires_python>=3.6
licenseApache LICENSE 2.0
keywords atlas client apache atlas
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Apache Atlas Python Client

Python library for Apache Atlas.

## Installation

Use the package manager [pip](https://pip.pypa.io/en/stable/) to install Python client for Apache Atlas.

```bash
> pip install apache-atlas
```

Verify if apache-atlas client is installed:
```bash
> pip list

Package      Version
------------ ---------
apache-atlas 0.0.16
```

## Usage

```python atlas_example.py```
```python
# atlas_example.py

import time

from apache_atlas.client.base_client import AtlasClient
from apache_atlas.model.instance     import AtlasEntity, AtlasEntityWithExtInfo, AtlasEntitiesWithExtInfo, AtlasRelatedObjectId
from apache_atlas.model.enums        import EntityOperation


## Step 1: create a client to connect to Apache Atlas server
client = AtlasClient('http://localhost:21000', ('admin', 'atlasR0cks!'))

# For Kerberos authentication, use HTTPKerberosAuth as shown below
#
# from requests_kerberos import HTTPKerberosAuth
#
# client = AtlasClient('http://localhost:21000', HTTPKerberosAuth())

# to disable SSL certificate validation (not recommended for production use!)
#
# client.session.verify = False


## Step 2: Let's create a database entity
test_db            = AtlasEntity({ 'typeName': 'hive_db' })
test_db.attributes = { 'name': 'test_db', 'clusterName': 'prod', 'qualifiedName': 'test_db@prod' }

entity_info        = AtlasEntityWithExtInfo()
entity_info.entity = test_db

print('Creating test_db')

resp = client.entity.create_entity(entity_info)

guid_db = resp.get_assigned_guid(test_db.guid)

print('    created test_db: guid=' + guid_db)


## Step 3: Let's create a table entity, and two column entities - in one call
test_tbl                        = AtlasEntity({ 'typeName': 'hive_table' })
test_tbl.attributes             = { 'name': 'test_tbl', 'qualifiedName': 'test_db.test_tbl@prod' }
test_tbl.relationshipAttributes = { 'db': AtlasRelatedObjectId({ 'guid': guid_db }) }

test_col1                        = AtlasEntity({ 'typeName': 'hive_column' })
test_col1.attributes             = { 'name': 'test_col1', 'type': 'string', 'qualifiedName': 'test_db.test_tbl.test_col1@prod' }
test_col1.relationshipAttributes = { 'table': AtlasRelatedObjectId({ 'guid': test_tbl.guid }) }

test_col2                        = AtlasEntity({ 'typeName': 'hive_column' })
test_col2.attributes             = { 'name': 'test_col2', 'type': 'string', 'qualifiedName': 'test_db.test_tbl.test_col2@prod' }
test_col2.relationshipAttributes = { 'table': AtlasRelatedObjectId({ 'guid': test_tbl.guid }) }

entities_info          = AtlasEntitiesWithExtInfo()
entities_info.entities = [ test_tbl, test_col1, test_col2 ]

print('Creating test_tbl')

resp = client.entity.create_entities(entities_info)

guid_tbl  = resp.get_assigned_guid(test_tbl.guid)
guid_col1 = resp.get_assigned_guid(test_col1.guid)
guid_col2 = resp.get_assigned_guid(test_col2.guid)

print('    created test_tbl:           guid=' + guid_tbl)
print('    created test_tbl.test_col1: guid=' + guid_col1)
print('    created test_tbl.test_col2: guid=' + guid_col2)


## Step 4: Let's create a view entity that feeds from the table created earlier
#          Also create a lineage between the table and the view, and lineages between their columns as well
test_view                        = AtlasEntity({ 'typeName': 'hive_table' })
test_view.attributes             = { 'name': 'test_view', 'qualifiedName': 'test_db.test_view@prod' }
test_view.relationshipAttributes = { 'db': AtlasRelatedObjectId({ 'guid': guid_db }) }

test_view_col1                        = AtlasEntity({ 'typeName': 'hive_column' })
test_view_col1.attributes             = { 'name': 'test_col1', 'type': 'string', 'qualifiedName': 'test_db.test_view.test_col1@prod' }
test_view_col1.relationshipAttributes = { 'table': AtlasRelatedObjectId({ 'guid': test_view.guid }) }

test_view_col2                        = AtlasEntity({ 'typeName': 'hive_column' })
test_view_col2.attributes             = { 'name': 'test_col2', 'type': 'string', 'qualifiedName': 'test_db.test_view.test_col2@prod' }
test_view_col2.relationshipAttributes = { 'table': AtlasRelatedObjectId({ 'guid': test_view.guid }) }

test_process                         = AtlasEntity({ 'typeName': 'hive_process' })
test_process.attributes              = { 'name': 'create_test_view', 'userName': 'admin', 'operationType': 'CREATE', 'qualifiedName': 'create_test_view@prod' }
test_process.attributes['queryText'] = 'create view test_view as select * from test_tbl'
test_process.attributes['queryPlan'] = '<queryPlan>'
test_process.attributes['queryId']   = '<queryId>'
test_process.attributes['startTime'] = int(time.time() * 1000)
test_process.attributes['endTime']   = int(time.time() * 1000)
test_process.relationshipAttributes  = { 'inputs': [ AtlasRelatedObjectId({ 'guid': guid_tbl }) ], 'outputs': [ AtlasRelatedObjectId({ 'guid': test_view.guid }) ] }

test_col1_lineage                        = AtlasEntity({ 'typeName': 'hive_column_lineage' })
test_col1_lineage.attributes             = { 'name': 'test_view.test_col1 lineage', 'depenendencyType': 'read', 'qualifiedName': 'test_db.test_view.test_col1@prod' }
test_col1_lineage.attributes['query']    = { 'guid': test_process.guid }
test_col1_lineage.relationshipAttributes = { 'inputs': [ AtlasRelatedObjectId({ 'guid': guid_col1 }) ], 'outputs': [ AtlasRelatedObjectId({ 'guid': test_view_col1.guid }) ] }

test_col2_lineage                        = AtlasEntity({ 'typeName': 'hive_column_lineage' })
test_col2_lineage.attributes             = { 'name': 'test_view.test_col2 lineage', 'depenendencyType': 'read', 'qualifiedName': 'test_db.test_view.test_col2@prod' }
test_col2_lineage.attributes['query']    = { 'guid': test_process.guid }
test_col2_lineage.relationshipAttributes = { 'inputs': [ AtlasRelatedObjectId({ 'guid': guid_col2 }) ], 'outputs': [ AtlasRelatedObjectId({ 'guid': test_view_col2.guid }) ] }

entities_info          = AtlasEntitiesWithExtInfo()
entities_info.entities = [ test_process, test_col1_lineage, test_col2_lineage ]

entities_info.add_referenced_entity(test_view)
entities_info.add_referenced_entity(test_view_col1)
entities_info.add_referenced_entity(test_view_col2)

print('Creating test_view')

resp = client.entity.create_entities(entities_info)

guid_view         = resp.get_assigned_guid(test_view.guid)
guid_view_col1    = resp.get_assigned_guid(test_view_col1.guid)
guid_view_col2    = resp.get_assigned_guid(test_view_col2.guid)
guid_process      = resp.get_assigned_guid(test_process.guid)
guid_col1_lineage = resp.get_assigned_guid(test_col1_lineage.guid)
guid_col2_lineage = resp.get_assigned_guid(test_col2_lineage.guid)

print('    created test_view:           guid=' + guid_view)
print('    created test_view.test_col1: guid=' + guid_view_col1)
print('    created test_view.test_col2: guid=' + guid_view_col1)
print('    created test_view lineage:   guid=' + guid_process)
print('    created test_col1 lineage:   guid=' + guid_col1_lineage)
print('    created test_col2 lineage:   guid=' + guid_col2_lineage)


## Step 5: Finally, cleanup by deleting entities created above
print('Deleting entities')

resp = client.entity.delete_entities_by_guids([ guid_col1_lineage, guid_col2_lineage, guid_process, guid_view, guid_tbl, guid_db ])

deleted_count = len(resp.mutatedEntities[EntityOperation.DELETE.name]) if resp and resp.mutatedEntities and EntityOperation.DELETE.name in resp.mutatedEntities else 0

print('    ' + str(deleted_count) + ' entities deleted')
```
For more examples, checkout `sample-app` python project in [atlas-examples](https://github.com/apache/atlas/blob/master/atlas-examples/sample-app/src/main/python/sample_client.py) module.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/apache/atlas/tree/master/intg/src/main/python",
    "name": "apache-atlas",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "atlas client, apache atlas",
    "author": "Apache Atlas",
    "author_email": "dev@atlas.apache.org",
    "download_url": "https://files.pythonhosted.org/packages/d1/56/d94655ba10a2dbf7fe69ff544057b0e1c174b7da5b2d88153735b43adc57/apache_atlas-0.0.16.tar.gz",
    "platform": null,
    "description": "# Apache Atlas Python Client\n\nPython library for Apache Atlas.\n\n## Installation\n\nUse the package manager [pip](https://pip.pypa.io/en/stable/) to install Python client for Apache Atlas.\n\n```bash\n> pip install apache-atlas\n```\n\nVerify if apache-atlas client is installed:\n```bash\n> pip list\n\nPackage      Version\n------------ ---------\napache-atlas 0.0.16\n```\n\n## Usage\n\n```python atlas_example.py```\n```python\n# atlas_example.py\n\nimport time\n\nfrom apache_atlas.client.base_client import AtlasClient\nfrom apache_atlas.model.instance     import AtlasEntity, AtlasEntityWithExtInfo, AtlasEntitiesWithExtInfo, AtlasRelatedObjectId\nfrom apache_atlas.model.enums        import EntityOperation\n\n\n## Step 1: create a client to connect to Apache Atlas server\nclient = AtlasClient('http://localhost:21000', ('admin', 'atlasR0cks!'))\n\n# For Kerberos authentication, use HTTPKerberosAuth as shown below\n#\n# from requests_kerberos import HTTPKerberosAuth\n#\n# client = AtlasClient('http://localhost:21000', HTTPKerberosAuth())\n\n# to disable SSL certificate validation (not recommended for production use!)\n#\n# client.session.verify = False\n\n\n## Step 2: Let's create a database entity\ntest_db            = AtlasEntity({ 'typeName': 'hive_db' })\ntest_db.attributes = { 'name': 'test_db', 'clusterName': 'prod', 'qualifiedName': 'test_db@prod' }\n\nentity_info        = AtlasEntityWithExtInfo()\nentity_info.entity = test_db\n\nprint('Creating test_db')\n\nresp = client.entity.create_entity(entity_info)\n\nguid_db = resp.get_assigned_guid(test_db.guid)\n\nprint('    created test_db: guid=' + guid_db)\n\n\n## Step 3: Let's create a table entity, and two column entities - in one call\ntest_tbl                        = AtlasEntity({ 'typeName': 'hive_table' })\ntest_tbl.attributes             = { 'name': 'test_tbl', 'qualifiedName': 'test_db.test_tbl@prod' }\ntest_tbl.relationshipAttributes = { 'db': AtlasRelatedObjectId({ 'guid': guid_db }) }\n\ntest_col1                        = AtlasEntity({ 'typeName': 'hive_column' })\ntest_col1.attributes             = { 'name': 'test_col1', 'type': 'string', 'qualifiedName': 'test_db.test_tbl.test_col1@prod' }\ntest_col1.relationshipAttributes = { 'table': AtlasRelatedObjectId({ 'guid': test_tbl.guid }) }\n\ntest_col2                        = AtlasEntity({ 'typeName': 'hive_column' })\ntest_col2.attributes             = { 'name': 'test_col2', 'type': 'string', 'qualifiedName': 'test_db.test_tbl.test_col2@prod' }\ntest_col2.relationshipAttributes = { 'table': AtlasRelatedObjectId({ 'guid': test_tbl.guid }) }\n\nentities_info          = AtlasEntitiesWithExtInfo()\nentities_info.entities = [ test_tbl, test_col1, test_col2 ]\n\nprint('Creating test_tbl')\n\nresp = client.entity.create_entities(entities_info)\n\nguid_tbl  = resp.get_assigned_guid(test_tbl.guid)\nguid_col1 = resp.get_assigned_guid(test_col1.guid)\nguid_col2 = resp.get_assigned_guid(test_col2.guid)\n\nprint('    created test_tbl:           guid=' + guid_tbl)\nprint('    created test_tbl.test_col1: guid=' + guid_col1)\nprint('    created test_tbl.test_col2: guid=' + guid_col2)\n\n\n## Step 4: Let's create a view entity that feeds from the table created earlier\n#          Also create a lineage between the table and the view, and lineages between their columns as well\ntest_view                        = AtlasEntity({ 'typeName': 'hive_table' })\ntest_view.attributes             = { 'name': 'test_view', 'qualifiedName': 'test_db.test_view@prod' }\ntest_view.relationshipAttributes = { 'db': AtlasRelatedObjectId({ 'guid': guid_db }) }\n\ntest_view_col1                        = AtlasEntity({ 'typeName': 'hive_column' })\ntest_view_col1.attributes             = { 'name': 'test_col1', 'type': 'string', 'qualifiedName': 'test_db.test_view.test_col1@prod' }\ntest_view_col1.relationshipAttributes = { 'table': AtlasRelatedObjectId({ 'guid': test_view.guid }) }\n\ntest_view_col2                        = AtlasEntity({ 'typeName': 'hive_column' })\ntest_view_col2.attributes             = { 'name': 'test_col2', 'type': 'string', 'qualifiedName': 'test_db.test_view.test_col2@prod' }\ntest_view_col2.relationshipAttributes = { 'table': AtlasRelatedObjectId({ 'guid': test_view.guid }) }\n\ntest_process                         = AtlasEntity({ 'typeName': 'hive_process' })\ntest_process.attributes              = { 'name': 'create_test_view', 'userName': 'admin', 'operationType': 'CREATE', 'qualifiedName': 'create_test_view@prod' }\ntest_process.attributes['queryText'] = 'create view test_view as select * from test_tbl'\ntest_process.attributes['queryPlan'] = '<queryPlan>'\ntest_process.attributes['queryId']   = '<queryId>'\ntest_process.attributes['startTime'] = int(time.time() * 1000)\ntest_process.attributes['endTime']   = int(time.time() * 1000)\ntest_process.relationshipAttributes  = { 'inputs': [ AtlasRelatedObjectId({ 'guid': guid_tbl }) ], 'outputs': [ AtlasRelatedObjectId({ 'guid': test_view.guid }) ] }\n\ntest_col1_lineage                        = AtlasEntity({ 'typeName': 'hive_column_lineage' })\ntest_col1_lineage.attributes             = { 'name': 'test_view.test_col1 lineage', 'depenendencyType': 'read', 'qualifiedName': 'test_db.test_view.test_col1@prod' }\ntest_col1_lineage.attributes['query']    = { 'guid': test_process.guid }\ntest_col1_lineage.relationshipAttributes = { 'inputs': [ AtlasRelatedObjectId({ 'guid': guid_col1 }) ], 'outputs': [ AtlasRelatedObjectId({ 'guid': test_view_col1.guid }) ] }\n\ntest_col2_lineage                        = AtlasEntity({ 'typeName': 'hive_column_lineage' })\ntest_col2_lineage.attributes             = { 'name': 'test_view.test_col2 lineage', 'depenendencyType': 'read', 'qualifiedName': 'test_db.test_view.test_col2@prod' }\ntest_col2_lineage.attributes['query']    = { 'guid': test_process.guid }\ntest_col2_lineage.relationshipAttributes = { 'inputs': [ AtlasRelatedObjectId({ 'guid': guid_col2 }) ], 'outputs': [ AtlasRelatedObjectId({ 'guid': test_view_col2.guid }) ] }\n\nentities_info          = AtlasEntitiesWithExtInfo()\nentities_info.entities = [ test_process, test_col1_lineage, test_col2_lineage ]\n\nentities_info.add_referenced_entity(test_view)\nentities_info.add_referenced_entity(test_view_col1)\nentities_info.add_referenced_entity(test_view_col2)\n\nprint('Creating test_view')\n\nresp = client.entity.create_entities(entities_info)\n\nguid_view         = resp.get_assigned_guid(test_view.guid)\nguid_view_col1    = resp.get_assigned_guid(test_view_col1.guid)\nguid_view_col2    = resp.get_assigned_guid(test_view_col2.guid)\nguid_process      = resp.get_assigned_guid(test_process.guid)\nguid_col1_lineage = resp.get_assigned_guid(test_col1_lineage.guid)\nguid_col2_lineage = resp.get_assigned_guid(test_col2_lineage.guid)\n\nprint('    created test_view:           guid=' + guid_view)\nprint('    created test_view.test_col1: guid=' + guid_view_col1)\nprint('    created test_view.test_col2: guid=' + guid_view_col1)\nprint('    created test_view lineage:   guid=' + guid_process)\nprint('    created test_col1 lineage:   guid=' + guid_col1_lineage)\nprint('    created test_col2 lineage:   guid=' + guid_col2_lineage)\n\n\n## Step 5: Finally, cleanup by deleting entities created above\nprint('Deleting entities')\n\nresp = client.entity.delete_entities_by_guids([ guid_col1_lineage, guid_col2_lineage, guid_process, guid_view, guid_tbl, guid_db ])\n\ndeleted_count = len(resp.mutatedEntities[EntityOperation.DELETE.name]) if resp and resp.mutatedEntities and EntityOperation.DELETE.name in resp.mutatedEntities else 0\n\nprint('    ' + str(deleted_count) + ' entities deleted')\n```\nFor more examples, checkout `sample-app` python project in [atlas-examples](https://github.com/apache/atlas/blob/master/atlas-examples/sample-app/src/main/python/sample_client.py) module.\n",
    "bugtrack_url": null,
    "license": "Apache LICENSE 2.0",
    "summary": "Apache Atlas Python Client",
    "version": "0.0.16",
    "project_urls": {
        "Homepage": "https://github.com/apache/atlas/tree/master/intg/src/main/python"
    },
    "split_keywords": [
        "atlas client",
        " apache atlas"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f5c3c30a4b90110c165da0c84d506fe1b2994550268c90574f40ec0e05cf6d48",
                "md5": "e6327cd91abc5db6a24294e767f7e47f",
                "sha256": "a217fe3c0db85e64c3bee30e5499f955a11cf12c4ecb5dfdffd4f5648eda9be0"
            },
            "downloads": -1,
            "filename": "apache_atlas-0.0.16-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e6327cd91abc5db6a24294e767f7e47f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 35465,
            "upload_time": "2024-11-22T21:33:14",
            "upload_time_iso_8601": "2024-11-22T21:33:14.006215Z",
            "url": "https://files.pythonhosted.org/packages/f5/c3/c30a4b90110c165da0c84d506fe1b2994550268c90574f40ec0e05cf6d48/apache_atlas-0.0.16-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d156d94655ba10a2dbf7fe69ff544057b0e1c174b7da5b2d88153735b43adc57",
                "md5": "a79fbeabe86a84b0c7375544fac7965e",
                "sha256": "926fddaa080aa4f2c4cb787763eb3426aa972100ad7e4f2e3f8f3cfdae52d450"
            },
            "downloads": -1,
            "filename": "apache_atlas-0.0.16.tar.gz",
            "has_sig": false,
            "md5_digest": "a79fbeabe86a84b0c7375544fac7965e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 20378,
            "upload_time": "2024-11-22T21:33:15",
            "upload_time_iso_8601": "2024-11-22T21:33:15.602095Z",
            "url": "https://files.pythonhosted.org/packages/d1/56/d94655ba10a2dbf7fe69ff544057b0e1c174b7da5b2d88153735b43adc57/apache_atlas-0.0.16.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-22 21:33:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "apache",
    "github_project": "atlas",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "apache-atlas"
}
        
Elapsed time: 1.24074s