Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

Security Interface for you project.

Project description

Security Interface

This library provides easy API for authentication and authorization.


Install with the following command:

$ pip install security_interface


First of all you need implement IdentityPolicyInterface and AuthorizationPolicyInterface interfaces. For example we can implement JWT Security:

import jwt
from security_interface import IdentityPolicyInterface, AuthorizationPolicyInterface

class JwtIdentityPolicy(IdentityPolicyInterface):
    def __init__(self, secret, algorithm="HS256"):
        self.algorithm = algorithm
        self.secret = secret

    async def identify(self, identity):
        if jwt is None:
            raise TypeError("Please install PyJWT")
            return jwt.decode(
                options={"verify_exp": True, "verify_iat": True},
        except Exception as e:
            return None

class JwtAuthPolicy(AuthorizationPolicyInterface):
    async def can(self, identity, permission):
        return permission in identity["scope"]

Create security instance with our implementation

from security_interface.api import Security
jwt_identity = JwtIdentityPolicy("SECRET")
jwt_auth_policy = JwtAuthPolicy()
security = Security(jwt_identity, jwt_auth_policy)
# Checking claim
# Checking permission
security.can(CLAIM, "read")
security.can(CLAIM, "write")

For full implementation see DEMO

Project details

Release history Release notifications

This version


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for security-interface, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size security_interface-0.1.0-py2.py3-none-any.whl (5.5 kB) File type Wheel Python version py2.py3 Upload date Hashes View hashes
Filename, size security_interface-0.1.0.tar.gz (3.4 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page