0
# User Management
1
2
Complete user profile management, social features, and account operations for the authenticated user and public user information retrieval across GitHub's social and collaboration features.
3
4
## Capabilities
5
6
### User Information Retrieval
7
8
Access user profiles and account information with comprehensive details and social connections.
9
10
```python { .api }
11
def user(self, username):
12
"""
13
Retrieve a User object for a specific username.
14
15
Parameters:
16
- username (str, required): GitHub username
17
18
Returns:
19
User object with profile information or None if not found
20
"""
21
22
def user_with_id(self, number):
23
"""
24
Get user information using their unique GitHub ID.
25
26
Parameters:
27
- number (int, required): User's unique GitHub ID
28
29
Returns:
30
User object or None if not found
31
"""
32
33
def me(self):
34
"""
35
Retrieve information for the authenticated user.
36
37
Returns:
38
AuthenticatedUser object with enhanced permissions and details
39
"""
40
41
def all_users(self, number=-1, etag=None, per_page=None, since=None):
42
"""
43
Iterate over every user in the order they signed up.
44
45
Parameters:
46
- number (int): Number to return (-1 for all)
47
- since (int, optional): ID of last user seen for pagination
48
- etag (str, optional): ETag from previous request
49
- per_page (int, optional): Results per page
50
51
Returns:
52
Generator of ShortUser objects
53
"""
54
```
55
56
### Usage Examples
57
58
```python
59
# Get specific user
60
user = gh.user('octocat')
61
print(f"User: {user.login}")
62
print(f"Name: {user.name}")
63
print(f"Company: {user.company}")
64
print(f"Location: {user.location}")
65
print(f"Public repos: {user.public_repos}")
66
print(f"Followers: {user.followers}")
67
68
# Get user by ID
69
user = gh.user_with_id(583231)
70
71
# Get authenticated user details
72
me = gh.me()
73
print(f"Authenticated as: {me.login}")
74
print(f"Email: {me.email}")
75
print(f"Private repos: {me.total_private_repos}")
76
77
# Browse all users
78
for user in gh.all_users(number=100):
79
print(f"{user.login} (ID: {user.id})")
80
```
81
82
### Profile Management
83
84
Update and manage the authenticated user's profile information and account settings.
85
86
```python { .api }
87
def update_me(self, name=None, email=None, blog=None, company=None, location=None, hireable=False, bio=None):
88
"""
89
Update the authenticated user's profile.
90
91
Parameters:
92
- name (str, optional): Display name (not login name)
93
- email (str, optional): Public email address
94
- blog (str, optional): Blog/website URL
95
- company (str, optional): Company name
96
- location (str, optional): Location string
97
- hireable (bool): Available for hire status
98
- bio (str, optional): Biography in GitHub Flavored Markdown
99
100
Returns:
101
bool: True if successful, False otherwise
102
"""
103
```
104
105
### Usage Examples
106
107
```python
108
# Update profile information
109
success = gh.update_me(
110
name='John Smith',
111
email='john@example.com',
112
blog='https://johnsmith.dev',
113
company='Acme Corp',
114
location='San Francisco, CA',
115
hireable=True,
116
bio='Full-stack developer passionate about open source. Python & JavaScript enthusiast.'
117
)
118
119
if success:
120
print("Profile updated successfully")
121
```
122
123
### Social Following
124
125
Manage social connections through GitHub's following system for community engagement.
126
127
```python { .api }
128
def follow(self, username):
129
"""
130
Make the authenticated user follow another user.
131
132
Parameters:
133
- username (str, required): User to follow
134
135
Returns:
136
bool: True if successful, False otherwise
137
"""
138
139
def unfollow(self, username):
140
"""
141
Make the authenticated user stop following another user.
142
143
Parameters:
144
- username (str, required): User to unfollow
145
146
Returns:
147
bool: True if successful, False otherwise
148
"""
149
150
def is_following(self, username):
151
"""
152
Check if the authenticated user is following another user.
153
154
Parameters:
155
- username (str, required): User to check
156
157
Returns:
158
bool: True if following, False otherwise
159
"""
160
161
def followers(self, number=-1, etag=None):
162
"""
163
Iterate over followers of the authenticated user.
164
165
Parameters:
166
- number (int): Number to return (-1 for all)
167
- etag (str, optional): ETag from previous request
168
169
Returns:
170
Generator of ShortUser objects
171
"""
172
173
def following(self, number=-1, etag=None):
174
"""
175
Iterate over users the authenticated user is following.
176
177
Parameters:
178
- number (int): Number to return (-1 for all)
179
- etag (str, optional): ETag from previous request
180
181
Returns:
182
Generator of ShortUser objects
183
"""
184
185
def followers_of(self, username, number=-1, etag=None):
186
"""
187
Iterate over followers of a specific user.
188
189
Parameters:
190
- username (str, required): Target user's username
191
- number (int): Number to return (-1 for all)
192
- etag (str, optional): ETag from previous request
193
194
Returns:
195
Generator of ShortUser objects
196
"""
197
198
def followed_by(self, username, number=-1, etag=None):
199
"""
200
Iterate over users being followed by a specific user.
201
202
Parameters:
203
- username (str, required): Target user's username
204
- number (int): Number to return (-1 for all)
205
- etag (str, optional): ETag from previous request
206
207
Returns:
208
Generator of ShortUser objects
209
"""
210
```
211
212
### Usage Examples
213
214
```python
215
# Follow a user
216
success = gh.follow('octocat')
217
if success:
218
print("Now following octocat")
219
220
# Check following status
221
if gh.is_following('octocat'):
222
print("You are following octocat")
223
224
# List your followers
225
print("Your followers:")
226
for user in gh.followers():
227
print(f"- {user.login}")
228
229
# List who you're following
230
print("You are following:")
231
for user in gh.following():
232
print(f"- {user.login}")
233
234
# List another user's followers
235
print("octocat's followers:")
236
for user in gh.followers_of('octocat', number=10):
237
print(f"- {user.login}")
238
239
# Unfollow a user
240
gh.unfollow('octocat')
241
```
242
243
### User Blocking
244
245
Manage blocked users to control interactions and prevent harassment.
246
247
```python { .api }
248
def block(self, username):
249
"""
250
Block a specific user.
251
252
Parameters:
253
- username (str, required): User to block
254
255
Returns:
256
bool: True if successful, False otherwise
257
"""
258
259
def unblock(self, username):
260
"""
261
Unblock a specific user.
262
263
Parameters:
264
- username (str, required): User to unblock
265
266
Returns:
267
bool: True if successful, False otherwise
268
"""
269
270
def is_blocking(self, username):
271
"""
272
Check if the authenticated user is blocking another user.
273
274
Parameters:
275
- username (str, required): User to check
276
277
Returns:
278
bool: True if blocking, False otherwise
279
"""
280
281
def blocked_users(self, number=-1, etag=None):
282
"""
283
Iterate over users blocked by the authenticated user.
284
285
Parameters:
286
- number (int): Number to return (-1 for all)
287
- etag (str, optional): ETag from previous request
288
289
Returns:
290
Generator of ShortUser objects
291
"""
292
```
293
294
### Usage Examples
295
296
```python
297
# Block a user
298
success = gh.block('spammer')
299
if success:
300
print("User blocked successfully")
301
302
# Check if blocking a user
303
if gh.is_blocking('spammer'):
304
print("User is currently blocked")
305
306
# List blocked users
307
for user in gh.blocked_users():
308
print(f"Blocked: {user.login}")
309
310
# Unblock a user
311
gh.unblock('spammer')
312
```
313
314
### Email Management
315
316
Manage email addresses associated with the authenticated user's account.
317
318
```python { .api }
319
def emails(self, number=-1, etag=None):
320
"""
321
Iterate over email addresses for the authenticated user.
322
323
Parameters:
324
- number (int): Number to return (-1 for all)
325
- etag (str, optional): ETag from previous request
326
327
Returns:
328
Generator of Email objects
329
"""
330
331
def add_email_addresses(self, addresses=[]):
332
"""
333
Add email addresses to the authenticated user's account.
334
335
Parameters:
336
- addresses (list): List of email address strings
337
338
Returns:
339
List of Email objects for added addresses
340
"""
341
342
def delete_email_addresses(self, addresses=[]):
343
"""
344
Remove email addresses from the authenticated user's account.
345
346
Parameters:
347
- addresses (list): List of email address strings to remove
348
349
Returns:
350
bool: True if successful, False otherwise
351
"""
352
```
353
354
### Usage Examples
355
356
```python
357
# List current email addresses
358
for email in gh.emails():
359
print(f"Email: {email.email}")
360
print(f"Primary: {email.primary}")
361
print(f"Verified: {email.verified}")
362
363
# Add new email addresses
364
new_emails = gh.add_email_addresses(['john@company.com', 'john.work@example.com'])
365
for email in new_emails:
366
print(f"Added: {email.email}")
367
368
# Remove email addresses
369
success = gh.delete_email_addresses(['old@example.com'])
370
if success:
371
print("Email addresses removed")
372
```
373
374
### User Teams
375
376
Access team memberships across organizations for the authenticated user.
377
378
```python { .api }
379
def user_teams(self, number=-1, etag=None):
380
"""
381
Get the authenticated user's teams across all organizations.
382
383
Parameters:
384
- number (int): Number to return (-1 for all)
385
- etag (str, optional): ETag from previous request
386
387
Returns:
388
Generator of ShortTeam objects
389
"""
390
```
391
392
### Usage Examples
393
394
```python
395
# List all teams the user belongs to
396
for team in gh.user_teams():
397
print(f"Team: {team.name}")
398
print(f"Organization: {team.organization.login}")
399
print(f"Permission: {team.permission}")
400
```
401
402
## User Model Classes
403
404
```python { .api }
405
class User:
406
"""Full user representation with public profile information"""
407
id: int
408
login: str
409
name: str
410
email: str
411
bio: str
412
company: str
413
location: str
414
blog: str
415
avatar_url: str
416
html_url: str
417
followers: int
418
following: int
419
public_repos: int
420
public_gists: int
421
created_at: datetime
422
updated_at: datetime
423
# ... additional user properties
424
425
class AuthenticatedUser(User):
426
"""Authenticated user with additional private information"""
427
private_gists: int
428
total_private_repos: int
429
owned_private_repos: int
430
disk_usage: int
431
collaborators: int
432
two_factor_authentication: bool
433
plan: Plan
434
# ... additional authenticated user properties and methods
435
436
class ShortUser:
437
"""Abbreviated user representation for list operations"""
438
id: int
439
login: str
440
avatar_url: str
441
# ... essential user properties
442
443
class Email:
444
"""User email address representation"""
445
email: str
446
primary: bool
447
verified: bool
448
visibility: str
449
# ... additional email properties
450
451
class Plan:
452
"""User's GitHub subscription plan"""
453
name: str
454
space: int
455
private_repos: int
456
collaborators: int
457
# ... additional plan properties
458
```
459
460
## Common User Management Patterns
461
462
### Profile Discovery
463
```python
464
# Find users by location or company
465
users = gh.search_users('location:seattle company:github')
466
for result in users:
467
user = result.user
468
print(f"{user.login} - {user.company} in {user.location}")
469
```
470
471
### Social Network Analysis
472
```python
473
# Analyze mutual connections
474
my_following = set(u.login for u in gh.following())
475
their_following = set(u.login for u in gh.followed_by('target_user'))
476
mutual = my_following.intersection(their_following)
477
print(f"Mutual connections: {len(mutual)}")
478
```
479
480
### Account Management
481
```python
482
# Update profile and verify changes
483
success = gh.update_me(bio='Updated biography')
484
if success:
485
updated_me = gh.me()
486
print(f"New bio: {updated_me.bio}")
487
488
# Manage email notifications
489
emails = list(gh.emails())
490
primary_email = next(e for e in emails if e.primary)
491
print(f"Primary email: {primary_email.email}")
492
```
493
494
### Community Engagement
495
```python
496
# Follow contributors to interesting projects
497
repo = gh.repository('facebook', 'react')
498
for contributor in repo.contributors()[:10]: # Top 10 contributors
499
if not gh.is_following(contributor.login):
500
gh.follow(contributor.login)
501
print(f"Following {contributor.login}")
502
```