Skip to main content

Python SDK for Go IAM - A lightweight Identity and Access Management server

Project description

🔐 goiam-python

PyPI version Python versions

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

goiam_python-0.0.2.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

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

goiam_python-0.0.2-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file goiam_python-0.0.2.tar.gz.

File metadata

  • Download URL: goiam_python-0.0.2.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for goiam_python-0.0.2.tar.gz
Algorithm Hash digest
SHA256 27ff516e040a5cb40cce6b3345bdee86afc3476c88f8cf72c5a8b066a503df6a
MD5 0374fe54a66f9a6d05a5c6484f738a3c
BLAKE2b-256 4db3d98b84281c385fc4f0a69c167ea38a60e45dc62c60372c66367301e92422

See more details on using hashes here.

File details

Details for the file goiam_python-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: goiam_python-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for goiam_python-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5846c15b8deb054bcddc3a4edbd7184c8f497825a172d4812df01414eb75b92a
MD5 d81d05993d2b046e5c9431c445a679ea
BLAKE2b-256 73fcc74d94b2e8007b7e208f1cd1b34f2cf08e696c127955346da0fb000f05fb

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