apache-ranger is the official Python client package for Apache Ranger.
It provides typed helpers for Ranger Admin, user/group management, KMS,
Governed Data Sharing (GDS), and Policy Decision Point (PDP) APIs.
Requirements
Python 3.13 or later
Apache Ranger Admin, KMS, or PDP service reachable from your Python process
Installation
Install the client from PyPI:
pip install apache-ranger
For Kerberos/SPNEGO authentication, install the optional Kerberos dependency:
pip install requests-kerberos
Verify the installed package:
python -m pip show apache-ranger
Supported Clients
RangerClient: Ranger Admin APIs for service definitions, services, policies,
roles, security zones, plugin information, and policy delta maintenance.
RangerUserMgmtClient: user, group, and user-group management APIs.
RangerKMSClient: Ranger KMS key management APIs.
RangerGdsClient: Governed Data Sharing APIs for datasets, projects,
datashares, shared resources, and GDS policies.
RangerPDPClient: PDP authorization APIs for single authorization, batch
authorization, and effective resource permissions.
Use the authentication mechanism configured for the Ranger service you are
calling:
Basic auth: pass a (username, password) tuple to RangerClient.
Kerberos/SPNEGO: pass requests_kerberos.HTTPKerberosAuth() after installing
requests-kerberos.
KMS Hadoop simple auth: use HadoopSimpleAuth("user") when simple auth is
enabled for Ranger KMS.
Custom headers or query parameters: pass headers or query_params to the
client constructor when the deployment requires them.
PDP trusted-header or JWT auth: pass the configured trusted caller header or
Authorization: Bearer <token> header to RangerPDPClient.
Example Kerberos setup:
from requests_kerberos import HTTPKerberosAuth
from apache_ranger.client.ranger_client import RangerClient
ranger = RangerClient("https://ranger.example.com:6182", HTTPKerberosAuth())
PDP Request Notes
RangerPDPClient sends requests to the PDP REST APIs exposed under
/authz/v1.
authorize(request) calls POST /authz/v1/authorize.
authorize_multi(request) calls POST /authz/v1/authorizeMulti.
get_resource_permissions(request) calls POST /authz/v1/permissions.
PDP authorization requests should include:
context.serviceType, for example hive, hdfs, or kafka.
context.serviceName, the Ranger service name.
user.name for authorize and authorize_multi calls.
If the authenticated caller is different from request.user.name, the caller
must be allowed to delegate for that service. Without delegation permission, PDP
returns 403 FORBIDDEN.
Examples and Code References
The quick starts above cover the basics. For day-to-day API usage — creating
services and policies, managing users, calling KMS or PDP, or working with GDS
— use the runnable samples and client sources below.
Running sample scripts
After pip install apache-ranger, run a sample directly:
401 Unauthorized: verify the credentials, Kerberos ticket, or auth headers
used by the target Ranger service.
403 Forbidden: verify Ranger permissions and PDP delegation configuration
when authorizing on behalf of another user.
SSL certificate errors: configure a valid trust store for production. For
local testing only, ranger.session.verify = False can disable certificate
verification.
Connection timeouts: verify the Ranger Admin, KMS, or PDP URL and confirm the
service is reachable from the client host.
Release 0.0.13 Highlights
Python 3.13+ support.
New GDS client coverage for datasets, projects, datashares, shared resources,
and GDS policy APIs.
New PDP client coverage for Ranger authorization APIs.
New authorization request and response models.
User/group management, KMS, Ranger Admin, and model updates.