code: def take_snapshot(self, entity_id, lt=None, lte=None):
          
          snapshot = None
          if self._snapshot_strategy:
              # Get the latest event (optionally until a particular position).
              latest_event = self.event_store.get_most_recent_event(entity_id, lt=lt, lte=lte)
  
              # If there is something to snapshot, then look for a snapshot
              # taken before or at the entity version of the latest event. Please
              # note, the snapshot might have a smaller version number than
              # the latest event if events occurred since the latest snapshot was taken.
              if latest_event is not None:
                  latest_snapshot = self._snapshot_strategy.get_snapshot(
                      entity_id, lt=lt, lte=lte
                  )
                  latest_version = latest_event.originator_version
  
                  if latest_snapshot and latest_snapshot.originator_version == latest_version:
                      # If up-to-date snapshot exists, there's nothing to do.
                      snapshot = latest_snapshot
                  else:
                      # Otherwise recover entity state from latest snapshot.
                      if latest_snapshot:
                          initial_state = entity_from_snapshot(latest_snapshot)
                          gt = latest_snapshot.originator_version
                      else:
                          initial_state = None
                          gt = None
  
                      # Fast-forward entity state to latest version.
                      entity = self.get_and_project_events(
                          entity_id=entity_id,
                          gt=gt,
                          lte=latest_version,
                          initial_state=initial_state,
                      )
  
                      # Take snapshot from entity.
                      snapshot = self._snapshot_strategy.take_snapshot(entity_id, entity, latest_version)
  
          return snapshot
docs: Takes a snapshot of the entity as it existed after the most recent
          event, optionally less than, or less than or equal to, a particular position.