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.1.0.tar.gz (10.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.1.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: goiam_python-0.1.0.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

Hashes for goiam_python-0.1.0.tar.gz
Algorithm Hash digest
SHA256 80201921554e610b5bfce05d589559e4df1d31f24ab412ec388519301386355e
MD5 9814dd3ae0265b19316192a54cd6d3a0
BLAKE2b-256 7d0a2a2ec03cc40967634904e07928108cb00869e8b057cc7081a2c94a8b504c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: goiam_python-0.1.0-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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9ab703f065e60cad8888236cb76f21d455a5cf1e3eac7313a5db0c661d5ac98b
MD5 8b8a1482c8e809e350b5e4b3680e2dda
BLAKE2b-256 0038f6e1fa10df346b06aca8f9aec03f839417e4d3b8139eefe5633132e156c2

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