# Darsman Course Lesson

## Requirements

- Python (== 3.10)
- grpcio-tools (>=1.62.1)

## Installation

Run the following command using pip:

```bash
pip install dmcl
```

## Sample code

```python
import asyncio
from dmcl import Course, Lesson, Package


# Note:
# Course has the widest functionality so is used here.
# Lesson and Package should be used in the same way.

async def main():
    # see `Env example` for confgs, you may want to only fill host,port and api_key
    course = Course()

    # Get one course using its identifier
    await course.fetch_one(
        identifier="b2f6c8e2-7e3a-4cb3-a58e-ef4e3f893708",
        timeout="3.5",              # Optional: override default timeout
        wait_for_ready=True         # Optional: wait for channel if not ready
    )

    # Get all courses
    await course.fetch_all(order_by="title", page_size=1, page_number=1)

    # Like a course
    await course.like(
        course_identifier="b2f6c8e2-7e3a-4cb3-a58e-ef4e3f893708",
    )

    # Unlike a course
    await course.unlike(
        course_identifier="b2f6c8e2-7e3a-4cb3-a58e-ef4e3f893708",
    )

    # Add comment to a course
    await course.comment(
        name="Utaab",
        content="Hello I'm Utaab",
        owner_identifier="b2f6c8e2-7e3a-4cb3-a58e-ef4e3f893708"
    )

if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())

```

## Env example

```python
### === COURSE_LESSON SDK CONFIG === ###

# Server config
COURSE_LESSON_SDK_HOST=127.0.0.1
COURSE_LESSON_SDK_PORT=50051
COURSE_LESSON_SDK_API_KEY=your_api_key_here

# Graceful shutdown
COURSE_LESSON_SDK_CHANNEL_SHUTDOWN_GRACE=10

# Keepalive (for long-lived connection health checks)
COURSE_LESSON_SDK_KEEPALIVE_TIME_MS=60000
COURSE_LESSON_SDK_KEEPALIVE_TIMEOUT_MS=5000
COURSE_LESSON_SDK_KEEPALIVE_PERMIT_WITHOUT_CALLS=1
COURSE_LESSON_SDK_MAX_PINGS_WITHOUT_DATA=0

# Retry policy
COURSE_LESSON_SDK_MAX_ATTEMPTS=5  # more than 5 isn't allowed by grpc
COURSE_LESSON_SDK_INITIAL_BACKOFF=0.1s
COURSE_LESSON_SDK_MAX_BACKOFF=1.5s
COURSE_LESSON_SDK_BACKOFF_MULTIPLIER=2.0
COURSE_LESSON_SDK_RETRYABLE_STATUS_CODES=["UNAVAILABLE", "RESOURCE_EXHAUSTED", "ABORTED"]

# RPC-level configs
COURSE_LESSON_SDK_WAIT_FOR_READY=true
COURSE_LESSON_SDK_TIMEOUT=5.0
```
