{"id":3751,"library":"pycognito","title":"pycognito","description":"pycognito is a Python library that provides a simplified interface for interacting with AWS Cognito User Pools, wrapping Boto3's Cognito client. It includes built-in support for the Secure Remote Password (SRP) protocol, making user authentication straightforward. The current version is 2024.5.1, and it typically releases new versions monthly or bi-monthly, incorporating fixes and feature enhancements.","status":"active","version":"2024.5.1","language":"python","source_language":"en","source_url":"https://github.com/pvizeli/pycognito","tags":["aws","cognito","authentication","srp","boto3"],"install":[{"cmd":"pip install pycognito","lang":"bash","label":"Install pycognito"}],"dependencies":[{"reason":"Core dependency for interacting with AWS services, including Cognito.","package":"boto3"},{"reason":"Used for JWT validation; replaced `python-jose` in version 2024.2.0.","package":"PyJWT"}],"imports":[{"symbol":"Cognito","correct":"from pycognito import Cognito"}],"quickstart":{"code":"import os\nfrom pycognito import Cognito\n\n# It's highly recommended to load these from environment variables or a secure configuration system.\n# Replace 'your_pool_id', 'your_client_id', 'your_username', 'YourStrongPassword123!'\nUSER_POOL_ID = os.environ.get('COGNITO_USER_POOL_ID', 'us-east-1_your_pool_id')\nCLIENT_ID = os.environ.get('COGNITO_CLIENT_ID', 'your_client_id')\nUSERNAME = os.environ.get('COGNITO_USERNAME', 'your_username')\nPASSWORD = os.environ.get('COGNITO_PASSWORD', 'YourStrongPassword123!')\n\n# Check if placeholder values are still present\nif 'your_pool_id' in USER_POOL_ID or 'your_client_id' in CLIENT_ID or\\\n   USERNAME == 'your_username' or PASSWORD == 'YourStrongPassword123!':\n    print(\"Please set COGNITO_USER_POOL_ID, COGNITO_CLIENT_ID, COGNITO_USERNAME, and COGNITO_PASSWORD environment variables or replace placeholders in the code.\")\nelse:\n    try:\n        # Initialize Cognito with User Pool ID, Client ID, and username\n        c = Cognito(USER_POOL_ID, CLIENT_ID, username=USERNAME)\n\n        # Authenticate the user. SRP (Secure Remote Password) protocol is handled automatically.\n        c.authenticate(password=PASSWORD)\n\n        print(f\"Successfully authenticated user: {USERNAME}\")\n        print(f\"Access Token (first 30 chars): {c.access_token[:30]}...\")\n        print(f\"ID Token (first 30 chars): {c.id_token[:30]}...\")\n        # Refresh token is also available as c.refresh_token\n        \n        # Example: Get user attributes\n        user_attributes = c.get_user_attributes()\n        print(f\"User attributes: {user_attributes}\")\n\n    except Exception as e:\n        print(f\"Authentication failed: {e}\")","lang":"python","description":"This quickstart demonstrates how to initialize the `Cognito` client and authenticate a user using their username and password. It automatically handles the SRP (Secure Remote Password) protocol. Ensure you replace the placeholder values for `USER_POOL_ID`, `CLIENT_ID`, `USERNAME`, and `PASSWORD` with your actual Cognito credentials, ideally loaded from environment variables."},"warnings":[{"fix":"Ensure `PyJWT` is installed (it's a dependency) and review any custom JWT processing code. Most direct usage of `pycognito` should remain unaffected.","message":"The internal JWT validation library switched from `python-jose` to `PyJWT`. While the public API for token handling is largely stable, users who relied on specific internals or configurations of `python-jose` might encounter issues.","severity":"breaking","affected_versions":"<2024.2.0"},{"fix":"Upgrade your Python environment to version 3.8 or newer before installing or running `pycognito`.","message":"The minimum required Python version has been raised to 3.8. Users on older Python versions will experience installation or runtime failures.","severity":"breaking","affected_versions":"<2024.5.0"},{"fix":"Review calls to `admin_create_user` and `admin_reset_user_password` in your application. Consult the latest documentation or GitHub examples for required parameters, especially `client_metadata` and handling of temporary passwords.","message":"Parameter changes and fixes for `admin_create_user` and `admin_reset_user_password` methods, particularly regarding `client_metadata` and temporary password generation, were introduced. Older implementations might not align with the current expected parameters or behavior.","severity":"gotcha","affected_versions":"<2022.11.0"},{"fix":"Thoroughly test your MFA implementation. Follow the Cognito documentation and `pycognito` examples carefully for `associate_srp_mfa`, `verify_mfa`, and other MFA-related methods to ensure correct sequence and parameter handling.","message":"While pycognito handles SRP, Multi-Factor Authentication (MFA) setup and interaction (e.g., `associate_srp_mfa`, `verify_mfa`) can be complex and is a common source of implementation errors if not handled precisely according to the Cognito flow. Though fixes were made, careful implementation is still required.","severity":"gotcha","affected_versions":"<2022.11.1"}],"env_vars":null,"search_vec":"'2024.5.1':45 'authent':39,64 'aw':15,62 'bi':55 'bi-month':54 'boto3':20,66 'built':27 'built-in':26 'client':23 'cognito':16,22,63 'current':42 'enhanc':61 'featur':60 'fix':58 'includ':25 'incorpor':57 'interact':13 'interfac':11 'librari':6 'make':37 'month':52,56 'new':50 'password':34 'pool':18 'protocol':36 'provid':8 'pycognito':1,2 'python':5 'releas':49 'remot':33 'secur':32 'simplifi':10 'srp':35,65 'straightforward':40 'support':29 'typic':48 'user':17,38 'version':43,51 'wrap':19","created_at":"2026-04-11T17:43:09.464117+00:00","updated_at":"2026-04-16T18:22:29.832102+00:00","problems":[{"fix":"Install the pycognito library using pip: `pip install pycognito`","cause":"The 'pycognito' package is not installed in the Python environment where the code is being executed.","error":"ModuleNotFoundError: No module named 'pycognito'"},{"fix":"Verify the username and password, ensure the user is confirmed in Cognito, confirm the client secret is correctly used if required by your app client, and check that tokens are valid and not expired. For `pycognito.Cognito` initialization, ensure `client_secret` is provided if the app client requires it.","cause":"This error typically occurs when the authentication credentials are incorrect, the user's account is not confirmed, the application client is misconfigured (e.g., missing a client secret), or the provided tokens are invalid or expired.","error":"botocore.exceptions.NotAuthorizedException: An error occurred (NotAuthorizedException)"},{"fix":"Verify the user's existence and spelling of the username in the Cognito User Pool. If using aliases (email/phone), ensure the correct identifier is passed to the `pycognito` method, and consider checking if the user is confirmed. If 'Prevent user existence errors' is enabled on the app client, this error might be masked as `NotAuthorizedException`.","cause":"The requested user does not exist in the specified Cognito User Pool, or the user is not confirmed and the 'Prevent user existence errors' setting is disabled, or an incorrect alias (like email/phone) is used where a username is expected by an administrative API.","error":"botocore.exceptions.UserNotFoundException: An error occurred (UserNotFoundException)"},{"fix":"Review the specific `pycognito` method call and its arguments against the AWS Cognito API documentation for the expected parameter types and formats. Ensure all required parameters are present and correctly formatted.","cause":"One or more parameters passed to the underlying AWS Cognito API call via `pycognito` do not meet the expected format, constraints, or are missing. This could be due to incorrect data types or missing required fields.","error":"botocore.exceptions.InvalidParameterException: An error occurred (InvalidParameterException)"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"2024.5.1","cli_name":"","cli_version":null,"type":"library","homepage":"https://docs.pycognito.dev","github":"https://github.com/pvizeli/pycognito","docs":null,"changelog":null,"pypi":"https://pypi.org/project/pycognito/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["aws","auth-security"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-29","next_check":"2026-07-28","install_tag":null}}