'Encode this JWT object into a JWT string
:param str algorithm: override the algorithm used to encode the JWT
:param int ttl: override the ttl configured in the constructor
:rtype: str The JWT string'

def to_jwt(self, algorithm=None, ttl=None):

    if (not self.secret_key):
        raise ValueError('JWT    does    not    have    a    signing    key    configured.')
    headers = self.headers.copy()
    if algorithm:
        headers['alg'] = algorithm
    algorithm = (algorithm or self.algorithm)
    payload = self.payload.copy()
    if ttl:
        payload['exp'] = (int(time.time()) + ttl)
    return jwt_lib.encode(payload, self.secret_key, algorithm=algorithm, headers=headers)
