snowflake.core.network_policy.NetworkPolicyCollection

class snowflake.core.network_policy.NetworkPolicyCollection(root: Root)

Bases: AccountObjectCollectionParent[NetworkPolicyResource]

Represents the collection operations on the Snowflake Network Policy resource.

With this collection, you can create, iterate through, and fetch network policies that you have access to in the current context.

Examples

Creating a network policy instance with only a single ip allowed:

>>> network_policies = root.network_policies
>>> new_network_policy = NetworkPolicy(
...     name = 'single_ip_policy',
...     allowed_ip_list=['192.168.1.32/32'],
...     blocked_ip_list=['0.0.0.0'],
... )
>>> network_policies.create(new_network_policy)
Copy

Attributes

root

Methods

create(network_policy: NetworkPolicy, mode: CreateMode = CreateMode.error_if_exists) NetworkPolicyResource

Create a network policy in Snowflake.

Parameters:
  • network_policy (NetworkPolicy) – The NetworkPolicy object, together with NetworkPolicy’s properties: name; allowed_network_rule_list, blocked_network_rule_list, allowed_ip_list, blocked_ip_list, comment are optional

  • mode (CreateMode, optional) –

    One of the following enum values:

    CreateMode.error_if_exists: Throw an snowflake.core.exceptions.ConflictError if the network policy already exists in Snowflake. Equivalent to SQL create network policy <name> ....

    CreateMode.or_replace: Replace if the network policy already exists in Snowflake. Equivalent to SQL create or replace network policy <name> ....

    CreateMode.if_not_exists: Do nothing if the network policy already exists in Snowflake. Equivalent to SQL create network policy <name> if not exists...

    Default is CreateMode.error_if_exists.

Examples

Create a Network Policy instance:

>>> root.network_policies.create(NetworkPolicy(
...     name = 'my_network_policy',
...     allowed_network_rule_list = allowed_rules,
...     blocked_network_rule_list = blocked_rules,
...     allowed_ip_list=['8.8.8.8'],
...     blocked_ip_list=['0.0.0.0'],
... ))
Copy
items() ItemsView[str, T]
iter() Iterator[NetworkPolicy]

Iterate through NetworkPolicy objects from Snowflake.

Examples

Printing the names of all visible network policies:

>>> for network_policy in root.network_policies.iter():
>>>     print(network_policy.name)
Copy
keys() KeysView[str]
values() ValuesView[T]