Python bindings for Hive
Project description
PyHive — a minimal Hive API client for Python
PyHive (package: PyHiveLMS) is a small, synchronous Python client for the Hive API. It provides:
- A simple
HiveClientyou use as a context manager to handle authentication and the HTTP session. - Generator-based list endpoints for memory-efficient iteration of large result sets.
Supported Hive Versions
5.1.26.2.0
Install
Install from PyPI. It's recommended to use a virtual environment.
Using pip (PyPI):
pip install PyHiveLMS
Quickstart — connect and list resources
The primary entry point is HiveClient. It accepts your Hive username, password and the base URL for your Hive instance. Use it as a context manager to ensure the underlying HTTP session is closed cleanly.
Example — list programs and print name/ID:
from pyhive import HiveClient
USERNAME = "Mentor123"
PASSWORD = "Password1"
HIVE_URL = "https://hive.org"
with HiveClient(USERNAME, PASSWORD, HIVE_URL) as client:
for program in client.get_programs():
print(program.id, program.name)
Example — fetch a program, its subjects and modules:
from pyhive import HiveClient
with HiveClient(USERNAME, PASSWORD, HIVE_URL) as client:
program = client.get_program(42)
print("Program:", program.name)
# list subjects for the same program
subjects = list(client.get_subjects(parent_program__id__in=[program.id]))
for subject in subjects:
print(" -", subject.id, subject.name)
# modules for the first subject
if subjects:
for module in client.get_modules(parent_subject=subjects[0]):
print(" *", module.id, module.name)
Example — find exercises in a module and read their form fields:
with HiveClient(USERNAME, PASSWORD, HIVE_URL) as client:
# you can pass ids or model objects to filter helpers
module = client.get_module(123)
for exercise in client.get_exercises(parent_module=module):
print(exercise.id, exercise.name)
for field in client.get_exercise_fields(exercise):
print(" field:", field.id, field.label)
Example — list assignments for a user and read responses:
with HiveClient(USERNAME, PASSWORD, HIVE_URL) as client:
assignments = client.get_assignments(user__id__in=[55])
for a in assignments:
print("Assignment:", a.id, a.exercise_name)
for resp in client.get_assignment_responses(a):
print(" response:", resp.id, resp.submitted_by)
Filtering and convenience
- List endpoints (
get_programs,get_subjects,get_modules,get_exercises,get_assignments,get_users, etc.) accept filter keyword arguments that are forwarded to the API. Useid__in,parent_program__id__in,queue__id, and the other documented kwargs to restrict results. - Many methods accept either an integer id or a model instance. For example
client.get_exercise_fields(exercise_id_or_model)accepts either.
Error handling
Network and HTTP errors are surfaced from the underlying httpx client. Typical patterns:
from httpx import HTTPError
try:
with HiveClient(USERNAME, PASSWORD, HIVE_URL) as client:
programs = list(client.get_programs())
except HTTPError as exc:
print("Network/HTTP error:", exc)
Model parsing errors will raise normal Python exceptions — wrap calls where you need robust failure handling.
Common methods (short reference)
- HiveClient(username, password, hive_url, **kwargs) — construct and authenticate client
- get_programs(...)
- get_program(program_id)
- get_subjects(...)
- get_modules(...)
- get_exercises(...)
- get_exercise(exercise_id)
- get_exercise_fields(exercise)
- get_assignments(...)
- get_assignment(assignment_id)
- get_assignment_responses(assignment)
- get_users(...)
- get_classes(...)
Return values are typed model objects from src/types or generators of those objects.
Try it locally / Run tests
Install dev dependencies and run tests with pytest:
pip install -e .
pytest -q
Troubleshooting
- Authentication errors: verify username/password and the
hive_urlbase. The client authenticates at construction. - SSL verification: pass
verify=Falseto the client constructor for self-signed servers (not recommended for production).
Contributing & development
- Tests live under
tests/and show common usage patterns. Use them as examples. - The typed models are in
src/typesand theHiveClientconvenience layer is inpyhive/client.py.
If you plan to make changes, please add tests for new behavior and keep changes small and focused.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
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 pyhivelms-1.1.1-py3-none-any.whl.
File metadata
- Download URL: pyhivelms-1.1.1-py3-none-any.whl
- Upload date:
- Size: 70.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed8874707697b809bb52b25bc3b5f41fe9da51ba46b1983ed8393f267e2687b1
|
|
| MD5 |
316eda91dac97c9fcd32d761a5816380
|
|
| BLAKE2b-256 |
f10e24328bafd9c0d9c57739c71fa42bd87ac9dd0e5ef95e6f5882840a35a919
|