Python SDK for Go IAM - A lightweight Identity and Access Management server
Project description
🔐 goiam-python
Python SDK for Go IAM - A lightweight Identity and Access Management server.
Installation
pip install goiam-python
# or
poetry add goiam-python
# or
pipenv install goiam-python
Usage
Initialize the SDK
from goiam import new_service
service = new_service(
base_url="https://go-iam.example.com",
client_id="your-client-id",
secret="your-secret"
)
Verify Authentication Code
try:
token = service.verify("auth-code")
print(f"Access Token: {token}")
except Exception as error:
print(f"Failed to verify code: {error}")
Fetch Current User Information
try:
user = service.me(token)
print(f"User: {user.name} ({user.email})")
except Exception as error:
print(f"Failed to fetch user information: {error}")
Create a Resource
from goiam import Resource
resource = Resource(
id="resource-id",
name="Resource Name",
description="Resource Description",
key="resource-key",
enabled=True,
project_id="project-id",
created_by="creator",
updated_by="updater"
)
try:
service.create_resource(resource, token)
print("Resource created successfully")
except Exception as error:
print(f"Failed to create resource: {error}")
Classes
The SDK provides the following main classes:
User
class User:
id: str
project_id: str
name: str
email: str
phone: str
enabled: bool
profile_pic: str
expiry: Optional[str]
roles: Dict[str, UserRole]
resources: Dict[str, UserResource]
policies: Dict[str, str]
created_at: Optional[str]
created_by: str
updated_at: Optional[str]
updated_by: str
Resource
class Resource:
def __init__(self,
id: str = '',
name: str = '',
description: str = '',
key: str = '',
enabled: bool = True,
project_id: str = '',
created_by: str = '',
updated_by: str = '',
created_at: Optional[str] = None,
updated_at: Optional[str] = None,
deleted_at: Optional[str] = None):
# ...
Error Handling
The SDK methods raise exceptions with descriptive messages. It's recommended to wrap API calls in try-except blocks:
try:
result = service.verify("code")
# Handle success
except Exception as error:
print(f"API Error: {error}")
# Handle error
Testing
Run the tests using:
python -m pytest python/test_service.py
# or
python -m unittest python/test_service.py
Related Projects
✅ Admin UI: go-iam-ui
🐳 Docker Setup: go-iam-docker
🔐 Backend: go-iam
📦 SDK: go-iam-sdk
🚀 Examples: go-iam-examples
License
MIT
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file goiam_python-0.1.1.tar.gz.
File metadata
- Download URL: goiam_python-0.1.1.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba67f7e213dc14681fe707e0d4e254b069bfe43316431c82565330f1734b51ee
|
|
| MD5 |
f72cd11d35570acde9d558854161a281
|
|
| BLAKE2b-256 |
b735f0d691c6f06b69c3a3732c557a094448cebe83b9bd06139d9830b5b014e6
|
File details
Details for the file goiam_python-0.1.1-py3-none-any.whl.
File metadata
- Download URL: goiam_python-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3517d3cb36e72e4841a40718af8595ace440fdafe91c25cbb1331b80eb7c5e48
|
|
| MD5 |
77cd432b6a8a73a3d5aa4b5c26b441b9
|
|
| BLAKE2b-256 |
73daead5a540ec190db015c545049c8b3f313534e2883c99256cb223db3f2d16
|