# Stem Docs

## Exit Policy

Representation of tor exit policies. These can be easily used to check if exiting to a destination is permissible or not. For instance…

    >>> from stem.exit_policy import ExitPolicy, MicroExitPolicy
    >>> policy = ExitPolicy('accept *:80', 'accept *:443', 'reject *:*')
    >>> print(policy)
    accept *:80, accept *:443, reject *:*
    >>> print(policy.summary())
    accept 80, 443
    >>> policy.can_exit_to('75.119.206.243', 80)
    True

    >>> policy = MicroExitPolicy('accept 80,443')
    >>> print(policy)
    accept 80,443
    >>> policy.can_exit_to('75.119.206.243', 80)
    True

    ExitPolicy - Exit policy for a Tor relay
      |- MicroExitPolicy - Microdescriptor exit policy
      |
      |- can_exit_to - check if exiting to this destination is allowed or not
      |- is_exiting_allowed - check if any exiting is allowed
      |- summary - provides a short label, similar to a microdescriptor
      |- has_private - checks if policy has anything expanded from the 'private' keyword
      |- strip_private - provides a copy of the policy without 'private' entries
      |- has_default - checks if policy ends with the defaultly appended suffix
      |- strip_default - provides a copy of the policy without the default suffix
      |- __str__  - string representation
      +- __iter__ - ExitPolicyRule entries that this contains

    ExitPolicyRule - Single rule of an exit policy chain
      |- MicroExitPolicyRule - Single rule for a microdescriptor policy
      |
      |- is_address_wildcard - checks if we'll accept any address
      |- is_port_wildcard - checks if we'll accept any port
      |- get_address_type - provides the protocol our ip address belongs to
      |- is_match - checks if we match a given destination
      |- get_mask - provides the address representation of our mask
      |- get_masked_bits - provides the bit representation of our mask
      |- is_default - flag indicating if this was part of the default end of a policy
      |- is_private - flag indicating if this was expanded from a 'private' keyword
      +- __str__ - string representation for this rule

    get_config_policy - provides the ExitPolicy based on torrc rules

stem.exit_policy.AddressType(enum)

  Enumerations for IP address types that can be in an exit policy.

  AddressType | Description
  --- | ---
  WILDCARD | any address of either IPv4 or IPv6
  IPv4 | IPv4 address
  IPv6 | IPv6 address