Skip to content

Find connections

Find a connection by name and type

You may have noticed that connections in Atlan have qualifiedNames that include a timestamp. As a result, they are not trivial to directly construct.

1.4.0 1.1.0

However, you can search for them by name and type to resolve their qualifiedName:

Find a connection by name and type
1
2
3
List<Connection> connections = Connection.findByName( // (1)
    "production", // (2)
    AtlanConnectorType.SNOWFLAKE); // (3)
  1. Use the findByName static method on the Connection class to search for connections by name and type. If you name your connections uniquely (by type), this should only return a single-item list.
  2. Provide the name of the connection (this will be exact-matched).
  3. Provide the type of the connection. You can also (optionally) provide a list of extra attributes you want to retrieve for the connection. Core attributes like qualifiedName and its GUID are already included.
Find a connection by name and type
1
2
3
4
5
6
7
8
9
from pyatlan.client.atlan import AtlanClient
from pyatlan.model.enums import AtlanConnectorType

client = AtlanClient()
connections = client.asset.find_connections_by_name( # (1)
    name="production", # (2)
    connector_type=AtlanConnectorType.SNOWFLAKE, # (3)
    attributes=[] # (4)
)
  1. Use the asset.find_connections_by_name method on the AtlanClient class to search for connections by name and type. If you name your connections uniquely (by type), this should only return a single-item list.
  2. Provide the name of the connection (this will be exact-matched).
  3. Provide the type of the connection.
  4. You can also (optionally) provide a list of extra attributes you want to retrieve for the connection. Core attributes like qualifiedName and its GUID are already included.
Find a connection by name and type
1
2
3
val connections = Connection.findByName( // (1)
    "production", // (2)
    AtlanConnectorType.SNOWFLAKE) // (3)
  1. Use the findByName static method on the Connection class to search for connections by name and type. If you name your connections uniquely (by type), this should only return a single-item list.
  2. Provide the name of the connection (this will be exact-matched).
  3. Provide the type of the connection. You can also (optionally) provide a list of extra attributes you want to retrieve for the connection. Core attributes like qualifiedName and its GUID are already included.
POST /api/meta/search/indexsearch
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
{
  "dsl": { // (1)
    "query": {
      "bool": { // (2)
        "filter": [ // (3)
          {
            "term": { // (4)
              "__state": {
                "value": "ACTIVE"
              }
            }
          },
          {
            "term": { // (5)
              "__typeName.keyword": {
                "value": "Connection"
              }
            }
          },
          {
            "term": { // (6)
              "name.keyword": {
                "value": "production"
              }
            }
          },
          {
            "term": { // (7)
              "connectorName": {
                "value": "snowflake"
              }
            }
          }
        ]
      }
    },
    "track_total_hits": true
  },
  "suppressLogs": true,
  "showSearchScore": false,
  "excludeMeanings": false,
  "excludeClassifications": false
}
  1. Run a search to find the connections.
  2. To start building up a query with multiple conditions, you can use a bool query in Elasticsearch.
  3. You can use the filter criteria to define all the conditions the search results must match in a binary way (either matches or doesn't). This avoids the need to calculate a score for each result.
  4. Searches by default will return all assets that are found — whether active or archived (soft-deleted). In most cases, you probably only want the active ones.
  5. Since there could be tables, views, materialized views, columns, databases, schemas, etc in this connection — but you only want the connection itself — you can use an exact match on the type to restrict results to only connections.
  6. Exact match search (case-sensitive) on the name of the connection.
  7. Exact match search on the type of the connector for the connection.

Find all connections

1.4.0 1.1.0

On the other hand, you may want to find all the connections that exist in the environment:

Find all connections
1
2
3
4
5
6
7
Connection.select() // (1)
    .pageSize(100) // (2)
    .stream() // (3)
    .filter(a -> a instanceof Connection) // (4)
    .forEach(c -> { // (5)
        log.info("Connection: {}", c);
    });
  1. To start building up a query to include all connections, you can use the select() convenience method on Connection itself. This will already limit results to only active (non-archived) connections.
  2. (Optional) You can chain a pageSize() method to control the page sizes, to further limit API calls by retrieving more results per page.
  3. The search will only run when you call the stream() method, which will then lazily-load each page of results into a stream.
  4. (Optional) You can do any other operations you might do on a stream, such as filtering the results to ensure they are of a certain type.
  5. This is the pattern for iterating through all results (across pages) covered in the Searching for assets portion of the SDK documentation.
Find all connections
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
from pyatlan.client.atlan import AtlanClient
from pyatlan.model.assets import Connection
from pyatlan.model.fluent_search import FluentSearch, CompoundQuery

client = AtlanClient()  # (1)
request = (
    FluentSearch()  # (2)
    .where(CompoundQuery.asset_type(Connection))  # (3)
    .where(CompoundQuery.active_assets())  # (4)
    .page_size(100)  # (5)
).to_request()  # (6)
for result in client.asset.search(request):  # (7)
    if isinstance(result, Connection):  # (8)
        print(result)
  1. Start with a client to run the search through. For the default client, you can always use AtlanClient().
  2. To search across all assets, you can use a FluentSearch object.
  3. The .where() method allows you to limit to only certain assets. In this example, we are looking for connections, so use the CompoundQuery.asset_type() helper to narrow to only connections.
  4. You can chain additional .where() methods to add further conditions, like this example where we limit to only active (non-archived) assets.
  5. (Optional) You can chain a pageSize() method to control the page sizes, to further limit API calls by retrieving more results per page.
  6. You can then translate the fluent search into an index search request.
  7. This is the pattern for iterating through all results (across pages) covered in the Searching for assets portion of the SDK documentation.
  8. Use the isinstance method to ensure that the asset is of the desired type. This will also allow an IDE to provide specific type hints for this asset type.
Find all connections
1
2
3
4
5
6
7
Connection.select() // (1)
    .pageSize(100) // (2)
    .stream() // (3)
    .filter { it is Connection } // (4)
    .forEach {  // (5)
        log.info { "Connection: $it" }
    }
  1. To start building up a query to include all connections, you can use the select() convenience method on Connection itself. This will already limit results to only active (non-archived) connections.
  2. (Optional) You can chain a pageSize() method to control the page sizes, to further limit API calls by retrieving more results per page.
  3. The search will only run when you call the stream() method, which will then lazily-load each page of results into a stream.
  4. (Optional) You can do any other operations you might do on a stream, such as filtering the results to ensure they are of a certain type.
  5. This is the pattern for iterating through all results (across pages) covered in the Searching for assets portion of the SDK documentation.
POST /api/meta/search/indexsearch
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
{
  "dsl": { // (1)
    "from": 0,
    "size": 100,
    "query": {
      "bool": { // (2)
        "filter": [ // (3)
          {
            "term": { // (4)
              "__typeName.keyword": {
                "value": "Connection"
              }
            }
          },
          {
            "term": {
              "__state": { // (5)
                "value": "ACTIVE"
              }
            }
          }
        ]
      }
    },
    "track_total_hits": true
  },
  "suppressLogs": true,
  "showSearchScore": false,
  "excludeMeanings": false,
  "excludeClassifications": false
}
  1. Run a search to find the connections.

  2. To start building up a query with multiple conditions, you can use a bool query in Elasticsearch.

  3. You can use the filter criteria to define all the conditions the search results must match in a binary way (either matches or doesn't). This avoids the need to calculate a score for each result.

  4. You can use an exact match on the type to restrict results to only connections.

  5. Searches by default will return all assets that are found — whether active or archived (soft-deleted). In most cases, you probably only want the active ones.