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}")

Delete a Resource

try:
    service.delete_resource("resource-id", token)
    print("Resource deleted successfully")
except Exception as error:
    print(f"Failed to delete 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.3.0.tar.gz (11.1 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.3.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for goiam_python-0.3.0.tar.gz
Algorithm Hash digest
SHA256 9ccac99377338102f66848243b942c5af74e990170e39d26cc94571b311fd4aa
MD5 b3f00d70603b73c61fad7a63d1179418
BLAKE2b-256 0c5d7d729a9d762741648051c4f0b23ca132378edee1edd2d02b5cb556b9f3a7

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for goiam_python-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b1b280b9b6784aef616d1d3d42ca456418c7f13697d3996d3701b75d40c98b0a
MD5 a467053d6e03f6f8a920e1d111ab18bb
BLAKE2b-256 bffee00937a014b1c3245940e4b0be3291a6ef6c19f392b7d38a2dfdd3242256

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