Skip to main content

OneLogin API Python SDK

Project description

onelogin-python-sdk

Official Python SDK for the OneLogin API, enabling you to programmatically manage users, roles, groups, and authentication in your OneLogin instance.

For more information about the OneLogin API, visit the OneLogin API Documentation.

Support

OneLogin by One Identity open source projects are supported through OneLogin GitHub issues. This includes all scripts, plugins, SDKs, modules, code snippets or other solutions. For assistance with any OneLogin by One Identity GitHub project, please raise a new Issue on the OneLogin GitHub issues page. Requests for assistance made through official One Identity Support will be referred back to GitHub where those requests can benefit all users.

Requirements

  • Python 3.10+
  • Dependencies:
    • Pydantic 2.11+ (latest version)
    • urllib3 2.0.2+
    • python-dateutil 2.5.3+
    • aenum 3.1.11+

Installation & Usage

pip install

You can install directly using pip:

pip install onelogin

For development and testing, install with test dependencies:

pip install onelogin[test]

Then import the package:

import onelogin

Tests

First, install the package with test dependencies:

pip install -e .[test]

Then run the tests:

pytest

Getting Started

Please follow the installation procedure and then run the following:

import os
import onelogin
from onelogin.rest import ApiException
from pprint import pprint

# Set up configuration
# Replace 'your-subdomain' with your actual OneLogin subdomain
configuration = onelogin.Configuration(
    host = "https://your-subdomain.onelogin.com"
)

# Set your API credentials
# Use environment variables to avoid hardcoding credentials
# IMPORTANT: Use ONELOGIN_CLIENT_ID and ONELOGIN_CLIENT_SECRET for your environment variables
configuration = onelogin.Configuration(
    username = os.environ["ONELOGIN_CLIENT_ID"],
    password = os.environ["ONELOGIN_CLIENT_SECRET"]
)

# Enter a context with an instance of the API client
with onelogin.ApiClient(configuration) as api_client:
    # Create an instance of the API class
    token_instance = onelogin.OAuth2Api(api_client)
    generate_token_request = {"grant_type":"client_credentials"} # GenerateTokenRequest | Request Body to Generate OAuth Token
    content_type="application/json"
    try:
        # Generate and Save Access Token
        api_response = token_instance.generate_token(generate_token_request, content_type=content_type)
        configuration.access_token = api_response.access_token
        print(configuration.access_token)
    except Exception as e:
        print("Exception when generating access token: %s\n" % e)

    user_instance = onelogin.UsersV2Api(api_client)
    try:
        # List Users
        api_response = user_instance.list_users2()
        print("The response of UsersV2Api->list_users:\n")
        pprint(api_response)
    except Exception as e:
        print("Exception when calling UsersV2Api->list_users: %s\n" % e)

Authentication

OAuth2

OneLogin API uses OAuth2 for authorization. Your client credentials (Client ID and Client Secret) are used to request an access token, which is then used for subsequent API calls.

Available Scopes

The OneLogin API supports the following scopes:

  • Authentication Only: Access to authentication endpoints only (Verify Factor, Generate SAML Assertion, Create Session Login Token, Log User Out)
  • Read Users: Access to GET calls for User, Role, and Group API resources
  • Manage Users: Access to GET, POST, PUT, and DELETE calls for User, Role, and Group API resources (except password management and role assignment)
  • Manage All: Full access to all API resources, including password management and role assignment
  • Read All: Read-only access to all API resources

You can set up your API credentials with appropriate scopes in the OneLogin portal under Security > API Credentials.

Troubleshooting

ImportError with Pydantic

If you encounter an error like ImportError: cannot import name validate_call from pydantic, make sure you have Pydantic 2.11+ installed:

pip install pydantic>=2.11.0

Environment Variable Names

Make sure to set your environment variables using the names expected by your code:

export ONELOGIN_CLIENT_ID="your-client-id"
export ONELOGIN_CLIENT_SECRET="your-client-secret"

API Connection Issues

If you're having trouble connecting to the API, double-check:

  • Your OneLogin subdomain is correct in the host URL
  • Your API credentials have the correct scopes for the operations you're trying to perform
  • Your network can reach the OneLogin API endpoints

Release Process (Maintainers)

To create a new release and publish to PyPI:

  1. Go to the Releases page in GitHub
  2. Click "Draft a new release"
  3. Click "Choose a tag" and create a new tag following semantic versioning (e.g., v3.2.3)
  4. Set the release title and description (you can use "Generate release notes" for automatic changelog)
  5. Click "Publish release"

The release workflow will automatically:

  • Extract the version from the tag (e.g., v3.2.33.2.3)
  • Update version in pyproject.toml and __version__ in onelogin/__init__.py
  • Build the Python package (sdist and wheel)
  • Publish to PyPI using the configured PYPI_API_TOKEN

That's it! The entire release process is automated from a single GitHub Release creation.

Project details


Download files

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

Source Distribution

onelogin-3.2.9.tar.gz (127.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

onelogin-3.2.9-py3-none-any.whl (281.3 kB view details)

Uploaded Python 3

File details

Details for the file onelogin-3.2.9.tar.gz.

File metadata

  • Download URL: onelogin-3.2.9.tar.gz
  • Upload date:
  • Size: 127.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for onelogin-3.2.9.tar.gz
Algorithm Hash digest
SHA256 761cc4907f73b33aaedd65a86997c1479d8fd9734f6d27cc18cabed389be9a32
MD5 71fc00f20cbfd336edd80866e2303c54
BLAKE2b-256 74aeda353e0237c6bfe02dc3b82d0bd4b9cf3767c7a534e6aca58e50ddcf6548

See more details on using hashes here.

File details

Details for the file onelogin-3.2.9-py3-none-any.whl.

File metadata

  • Download URL: onelogin-3.2.9-py3-none-any.whl
  • Upload date:
  • Size: 281.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for onelogin-3.2.9-py3-none-any.whl
Algorithm Hash digest
SHA256 29490fcc17b345c9f9d1e93ae13e18a721c47c8987f0ded3356948ed4a6c5287
MD5 6b63f4dd9ef8e61d9aa16c893b5a3fce
BLAKE2b-256 9b81977ad868f5c3d16a416f633d7e532dd1473b42839f8273a6ebe7d177875c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page