getuser
A small, cross-platform Python library for retrieving system user information.
Build
We use Rubisco to build GitHub release.
ru dist
We use Hatchling to build PyPI release.
python -m build
Installation
- Prerequisites: Python 3.8 or newer.
- On Windows, the
pywin32dependency is required; it is declared conditionally inpyproject.toml.
Install locally (recommended inside a virtual environment):
python -m pip install getuser
Quick Start
Use the library from Python:
from getuser import get_current_username, get_user_info, list_users
print(get_current_username())
for username in list_users():
info = get_user_info(username)
print(username, info)
Run the package as a module from the command line:
python -m getuser
This prints the list of users, the current user, and a JSON-formatted user record for each user.
API
-
get_current_username() -> str- Returns the username of the current user.
-
get_user_info(username: str) -> UserRecord | None- Returns a
UserRecordfor the given username, orNoneif the user does not exist. UserRecordfields:username: :ogin name.unique_id: Platform-specific unique identifier. (UID on Unix as a string, SID on Windows)display_name: Full name of the user.home_directory: User home/profile directory.primary_group: Primary group name or idis_enabled: Account enabled flag (bool orNoneif unknown)platform_details: Raw platform-specific information. (It may be unserializable)
- Returns a
-
list_users() -> list[str]- Returns a list of usernames on the system (strings only).
Platform Support and Implementation Notes
-
Unix-like systems (Linux, macOS): Implementation in
getuser/unix.pyusingpwd,grp, andgetpass. The GECOS field is parsed to populate display name and related fields. -
Windows: Implementation in
getuser/win32.pyusingpywin32(win32api,win32net,win32security). Theunique_idis a SID string.platform_detailscontains the raw dictionary returned byNetUserGetInfo.
Example Output
Running python -m getuser produces output similar to the following (example on Windows):
Users:
Administrator
ChenPi11
DefaultAccount
Guest
Current user: ChenPi11
User record for Administrator:
{
"username": "Administrator",
"unique_id": "S-*-*-*-*-*-*-*",
"display_name": "Administrator",
"home_directory": "",
"primary_group": "Administrator",
"is_enabled": false,
"platform_details": {
"name": "Administrator",
"password": null,
"password_age": 0,
"priv": 2,
"home_dir": "",
"comment": "***",
"flags": *,
"script_path": "",
"auth_flags": 0,
"full_name": "",
"usr_comment": "",
"parms": "",
"workstations": "",
"last_logon": 0,
"last_logoff": 0,
"acct_expires": *,
"max_storage": *,
"units_per_week": *,
"logon_hours": "b'*'",
"bad_pw_count": 0,
"num_logons": 0,
"logon_server": "\\\\*",
"country_code": 0,
"code_page": 0,
"user_sid": "<PySID object at 0x0000011CB363EA70>",
"primary_group_id": *,
"profile": "",
"home_dir_drive": "",
"password_expired": 0
}
}
User record for ChenPi11:
{
"username": "ChenPi11",
"unique_id": "S-*-*-*-*-*-*-*",
"display_name": "\u9648\u6ea2\u98de",
"home_directory": "",
"primary_group": "ChenPi11",
"is_enabled": true,
"platform_details": {
...
}
}
Development & Testing
Install development dependencies (optional):
python -m pip install -e .[dev,ruff]
Recommended tools: ruff, pylint, pyright (see pyproject.toml).
License and Author
- License: The Unlicense (See
LICENSEin the repository root). - Author: ChenPi11 (wushengwuxi-msctinoulk@outlook.com)
Metadata
Release files for getuser 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| getuser-0.1.1.tar.gz | 10.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| getuser-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 20.7 kB
Release files / getuser-0.1.1.tar.gz
| Download URL | getuser-0.1.1.tar.gz |
|---|---|
| Size | 10.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0f8a114304b50a28c732de2fc53cbc26848bd70666ad53f0b0a881455ea210eb
|
|
BLAKE2b-256 checksum How to use checksums |
50ba7a93301738c8e42302df66d52d13c47d4f0e938d8d823ba06837aade1212
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Release files / getuser-0.1.1-py3-none-any.whl
| Download URL | getuser-0.1.1-py3-none-any.whl |
|---|---|
| Size | 9.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d827f294881af06e70b2546b4dc7c1039d66e2c4909b7d6c621098458f2c1839
|
|
BLAKE2b-256 checksum How to use checksums |
c3034e38c08d1f2eef2d396a84a56860f4f184d1b1f1f1617a02a660109622f1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|