0
# User and Organization Management
1
2
User profile access, organization management, membership operations, and social features. Handles both public user information and authenticated user capabilities.
3
4
## Capabilities
5
6
### User Information and Access
7
8
Access user profiles, repositories, and public information.
9
10
```python { .api }
11
class Github:
12
def get_user(self, login: str = None) -> Union[AuthenticatedUser, NamedUser]:
13
"""
14
Get a user by login or the authenticated user.
15
16
Args:
17
login (str, optional): Username (if None, returns authenticated user)
18
19
Returns:
20
Union[AuthenticatedUser, NamedUser]: User object
21
"""
22
23
class NamedUser:
24
# User properties
25
@property
26
def login(self) -> str: ...
27
@property
28
def name(self) -> str: ...
29
@property
30
def email(self) -> str: ...
31
@property
32
def bio(self) -> str: ...
33
@property
34
def company(self) -> str: ...
35
@property
36
def location(self) -> str: ...
37
@property
38
def blog(self) -> str: ...
39
@property
40
def avatar_url(self) -> str: ...
41
@property
42
def public_repos(self) -> int: ...
43
@property
44
def public_gists(self) -> int: ...
45
@property
46
def followers(self) -> int: ...
47
@property
48
def following(self) -> int: ...
49
@property
50
def created_at(self) -> datetime: ...
51
@property
52
def updated_at(self) -> datetime: ...
53
@property
54
def type(self) -> str: ... # "User" or "Bot"
55
56
def get_repos(
57
self,
58
type: str = None,
59
sort: str = None,
60
direction: str = None
61
):
62
"""
63
Get user's repositories.
64
65
Args:
66
type (str, optional): Repository type ("all", "owner", "member")
67
sort (str, optional): Sort by ("created", "updated", "pushed", "full_name")
68
direction (str, optional): Sort direction ("asc", "desc")
69
70
Returns:
71
PaginatedList[Repository]: List of repositories
72
"""
73
74
def get_gists(self, since: datetime = None):
75
"""
76
Get user's gists.
77
78
Args:
79
since (datetime, optional): Only gists updated after this date
80
81
Returns:
82
PaginatedList[Gist]: List of gists
83
"""
84
85
def get_followers(self):
86
"""
87
Get user's followers.
88
89
Returns:
90
PaginatedList[NamedUser]: List of followers
91
"""
92
93
def get_following(self):
94
"""
95
Get users this user is following.
96
97
Returns:
98
PaginatedList[NamedUser]: List of followed users
99
"""
100
101
def get_starred(self, sort: str = None, direction: str = None):
102
"""
103
Get repositories starred by the user.
104
105
Args:
106
sort (str, optional): Sort by ("created", "updated")
107
direction (str, optional): Sort direction ("asc", "desc")
108
109
Returns:
110
PaginatedList[Repository]: List of starred repositories
111
"""
112
113
def get_subscriptions(self):
114
"""
115
Get repositories watched by the user.
116
117
Returns:
118
PaginatedList[Repository]: List of watched repositories
119
"""
120
121
def get_orgs(self):
122
"""
123
Get organizations the user belongs to.
124
125
Returns:
126
PaginatedList[Organization]: List of organizations
127
"""
128
129
def get_events(self):
130
"""
131
Get user's public events.
132
133
Returns:
134
PaginatedList[Event]: List of events
135
"""
136
137
def get_received_events(self):
138
"""
139
Get events received by the user.
140
141
Returns:
142
PaginatedList[Event]: List of received events
143
"""
144
```
145
146
### Authenticated User Capabilities
147
148
Extended functionality available to the authenticated user for account management and content creation.
149
150
```python { .api }
151
class AuthenticatedUser(NamedUser):
152
@property
153
def total_private_repos(self) -> int: ...
154
@property
155
def owned_private_repos(self) -> int: ...
156
@property
157
def private_gists(self) -> int: ...
158
@property
159
def disk_usage(self) -> int: ...
160
@property
161
def collaborators(self) -> int: ...
162
@property
163
def plan(self) -> Plan: ...
164
165
def edit(
166
self,
167
name: str = None,
168
email: str = None,
169
blog: str = None,
170
company: str = None,
171
location: str = None,
172
hireable: bool = None,
173
bio: str = None
174
):
175
"""
176
Edit authenticated user's profile.
177
178
Args:
179
name (str, optional): Full name
180
email (str, optional): Email address
181
blog (str, optional): Blog URL
182
company (str, optional): Company name
183
location (str, optional): Location
184
hireable (bool, optional): Available for hire
185
bio (str, optional): Biography
186
"""
187
188
def create_repo(
189
self,
190
name: str,
191
description: str = None,
192
homepage: str = None,
193
private: bool = False,
194
has_issues: bool = True,
195
has_wiki: bool = True,
196
has_downloads: bool = True,
197
auto_init: bool = False,
198
gitignore_template: str = None,
199
license_template: str = None,
200
allow_squash_merge: bool = True,
201
allow_merge_commit: bool = True,
202
allow_rebase_merge: bool = True
203
):
204
"""
205
Create a new repository for the authenticated user.
206
207
Args:
208
name (str): Repository name
209
description (str, optional): Repository description
210
homepage (str, optional): Homepage URL
211
private (bool, optional): Create private repository
212
has_issues (bool, optional): Enable issues
213
has_wiki (bool, optional): Enable wiki
214
has_downloads (bool, optional): Enable downloads
215
auto_init (bool, optional): Initialize with README
216
gitignore_template (str, optional): .gitignore template name
217
license_template (str, optional): License template name
218
allow_squash_merge (bool, optional): Allow squash merging
219
allow_merge_commit (bool, optional): Allow merge commits
220
allow_rebase_merge (bool, optional): Allow rebase merging
221
222
Returns:
223
Repository: Created repository
224
"""
225
226
def create_gist(
227
self,
228
description: str,
229
files: dict,
230
public: bool = True
231
):
232
"""
233
Create a new gist.
234
235
Args:
236
description (str): Gist description
237
files (dict): Dictionary mapping filenames to InputFileContent objects
238
public (bool, optional): Create public gist
239
240
Returns:
241
Gist: Created gist
242
"""
243
244
def get_notifications(
245
self,
246
all: bool = False,
247
participating: bool = False,
248
since: datetime = None,
249
before: datetime = None
250
):
251
"""
252
Get notifications for the authenticated user.
253
254
Args:
255
all (bool, optional): Include read notifications
256
participating (bool, optional): Only participating notifications
257
since (datetime, optional): Only notifications updated after this date
258
before (datetime, optional): Only notifications updated before this date
259
260
Returns:
261
PaginatedList[Notification]: List of notifications
262
"""
263
264
def get_issues(
265
self,
266
filter: str = None,
267
state: str = None,
268
labels: list = None,
269
sort: str = None,
270
direction: str = None,
271
since: datetime = None
272
):
273
"""
274
Get issues assigned to the authenticated user across all repositories.
275
276
Args:
277
filter (str, optional): Filter by ("assigned", "created", "mentioned", "subscribed")
278
state (str, optional): Issue state ("open", "closed", "all")
279
labels (list, optional): List of label names
280
sort (str, optional): Sort by ("created", "updated", "comments")
281
direction (str, optional): Sort direction ("asc", "desc")
282
since (datetime, optional): Only issues updated after this date
283
284
Returns:
285
PaginatedList[Issue]: List of issues
286
"""
287
288
def create_key(self, title: str, key: str):
289
"""
290
Add an SSH key to the authenticated user's account.
291
292
Args:
293
title (str): Key title
294
key (str): SSH public key content
295
296
Returns:
297
UserKey: Created SSH key
298
"""
299
300
def get_keys(self):
301
"""
302
Get SSH keys for the authenticated user.
303
304
Returns:
305
PaginatedList[UserKey]: List of SSH keys
306
"""
307
308
def mark_notifications_as_read(self, last_read_at: datetime = None):
309
"""
310
Mark notifications as read.
311
312
Args:
313
last_read_at (datetime, optional): Mark notifications read up to this time
314
"""
315
```
316
317
### Organization Management
318
319
Access and manage GitHub organizations, membership, and team operations.
320
321
```python { .api }
322
class Github:
323
def get_organization(self, login: str) -> Organization:
324
"""
325
Get an organization by login.
326
327
Args:
328
login (str): Organization login
329
330
Returns:
331
Organization: Organization object
332
"""
333
334
class Organization:
335
# Organization properties
336
@property
337
def login(self) -> str: ...
338
@property
339
def name(self) -> str: ...
340
@property
341
def email(self) -> str: ...
342
@property
343
def blog(self) -> str: ...
344
@property
345
def location(self) -> str: ...
346
@property
347
def description(self) -> str: ...
348
@property
349
def avatar_url(self) -> str: ...
350
@property
351
def public_repos(self) -> int: ...
352
@property
353
def public_gists(self) -> int: ...
354
@property
355
def followers(self) -> int: ...
356
@property
357
def following(self) -> int: ...
358
@property
359
def created_at(self) -> datetime: ...
360
@property
361
def updated_at(self) -> datetime: ...
362
@property
363
def type(self) -> str: ... # "Organization"
364
365
def edit(
366
self,
367
billing_email: str = None,
368
blog: str = None,
369
company: str = None,
370
description: str = None,
371
email: str = None,
372
location: str = None,
373
name: str = None
374
):
375
"""
376
Edit organization profile.
377
378
Args:
379
billing_email (str, optional): Billing email
380
blog (str, optional): Blog URL
381
company (str, optional): Company name
382
description (str, optional): Organization description
383
email (str, optional): Public email
384
location (str, optional): Location
385
name (str, optional): Organization name
386
"""
387
388
def get_repos(
389
self,
390
type: str = None,
391
sort: str = None,
392
direction: str = None
393
):
394
"""
395
Get organization repositories.
396
397
Args:
398
type (str, optional): Repository type ("all", "public", "private", "forks", "sources", "member")
399
sort (str, optional): Sort by ("created", "updated", "pushed", "full_name")
400
direction (str, optional): Sort direction ("asc", "desc")
401
402
Returns:
403
PaginatedList[Repository]: List of repositories
404
"""
405
406
def create_repo(
407
self,
408
name: str,
409
description: str = None,
410
homepage: str = None,
411
private: bool = False,
412
has_issues: bool = True,
413
has_wiki: bool = True,
414
has_downloads: bool = True,
415
team_id: int = None,
416
auto_init: bool = False,
417
gitignore_template: str = None,
418
license_template: str = None
419
):
420
"""
421
Create a repository in the organization.
422
423
Args:
424
name (str): Repository name
425
description (str, optional): Repository description
426
homepage (str, optional): Homepage URL
427
private (bool, optional): Create private repository
428
has_issues (bool, optional): Enable issues
429
has_wiki (bool, optional): Enable wiki
430
has_downloads (bool, optional): Enable downloads
431
team_id (int, optional): Team with admin access
432
auto_init (bool, optional): Initialize with README
433
gitignore_template (str, optional): .gitignore template
434
license_template (str, optional): License template
435
436
Returns:
437
Repository: Created repository
438
"""
439
440
def get_members(self, filter: str = None, role: str = None):
441
"""
442
Get organization members.
443
444
Args:
445
filter (str, optional): Filter by ("2fa_disabled", "all")
446
role (str, optional): Filter by role ("all", "admin", "member")
447
448
Returns:
449
PaginatedList[NamedUser]: List of members
450
"""
451
452
def get_public_members(self):
453
"""
454
Get public organization members.
455
456
Returns:
457
PaginatedList[NamedUser]: List of public members
458
"""
459
460
def has_in_members(self, member: NamedUser):
461
"""
462
Check if user is a member of the organization.
463
464
Args:
465
member (NamedUser): User to check
466
467
Returns:
468
bool: True if user is a member
469
"""
470
471
def has_in_public_members(self, member: NamedUser):
472
"""
473
Check if user is a public member of the organization.
474
475
Args:
476
member (NamedUser): User to check
477
478
Returns:
479
bool: True if user is a public member
480
"""
481
482
def add_to_public_members(self, member: NamedUser):
483
"""
484
Make organization membership public for a user.
485
486
Args:
487
member (NamedUser): User to make public member
488
"""
489
490
def remove_from_public_members(self, member: NamedUser):
491
"""
492
Remove user from public members (makes membership private).
493
494
Args:
495
member (NamedUser): User to remove from public members
496
"""
497
498
def remove_from_members(self, member: NamedUser):
499
"""
500
Remove user from organization.
501
502
Args:
503
member (NamedUser): User to remove
504
"""
505
506
def get_events(self):
507
"""
508
Get organization public events.
509
510
Returns:
511
PaginatedList[Event]: List of events
512
"""
513
```
514
515
### Team Management
516
517
Manage organization teams, team membership, and team repository access.
518
519
```python { .api }
520
class Organization:
521
def get_teams(self):
522
"""
523
Get organization teams.
524
525
Returns:
526
PaginatedList[Team]: List of teams
527
"""
528
529
def get_team(self, id: int):
530
"""
531
Get a team by ID.
532
533
Args:
534
id (int): Team ID
535
536
Returns:
537
Team: Team object
538
"""
539
540
def create_team(
541
self,
542
name: str,
543
repo_names: list = None,
544
permission: str = None,
545
privacy: str = None,
546
description: str = None,
547
parent_team_id: int = None
548
):
549
"""
550
Create a team in the organization.
551
552
Args:
553
name (str): Team name
554
repo_names (list, optional): Repository names to add to team
555
permission (str, optional): Permission level ("pull", "push", "admin")
556
privacy (str, optional): Team privacy ("secret", "closed")
557
description (str, optional): Team description
558
parent_team_id (int, optional): Parent team ID for nested teams
559
560
Returns:
561
Team: Created team
562
"""
563
564
class Team:
565
@property
566
def id(self) -> int: ...
567
@property
568
def name(self) -> str: ...
569
@property
570
def slug(self) -> str: ...
571
@property
572
def description(self) -> str: ...
573
@property
574
def privacy(self) -> str: ...
575
@property
576
def permission(self) -> str: ...
577
@property
578
def members_count(self) -> int: ...
579
@property
580
def repos_count(self) -> int: ...
581
582
def edit(
583
self,
584
name: str = None,
585
description: str = None,
586
privacy: str = None,
587
permission: str = None,
588
parent_team_id: int = None
589
):
590
"""
591
Edit team settings.
592
593
Args:
594
name (str, optional): Team name
595
description (str, optional): Team description
596
privacy (str, optional): Team privacy
597
permission (str, optional): Permission level
598
parent_team_id (int, optional): Parent team ID
599
"""
600
601
def delete(self):
602
"""Delete the team."""
603
604
def get_members(self, role: str = None):
605
"""
606
Get team members.
607
608
Args:
609
role (str, optional): Filter by role ("member", "maintainer", "all")
610
611
Returns:
612
PaginatedList[NamedUser]: List of members
613
"""
614
615
def has_in_members(self, member: NamedUser):
616
"""
617
Check if user is a team member.
618
619
Args:
620
member (NamedUser): User to check
621
622
Returns:
623
bool: True if user is a member
624
"""
625
626
def add_membership(self, member: NamedUser, role: str = None):
627
"""
628
Add user to team.
629
630
Args:
631
member (NamedUser): User to add
632
role (str, optional): Role ("member", "maintainer")
633
"""
634
635
def remove_membership(self, member: NamedUser):
636
"""
637
Remove user from team.
638
639
Args:
640
member (NamedUser): User to remove
641
"""
642
643
def get_repos(self):
644
"""
645
Get team repositories.
646
647
Returns:
648
PaginatedList[Repository]: List of repositories
649
"""
650
651
def add_to_repos(self, repo: Repository, permission: str = None):
652
"""
653
Add repository to team.
654
655
Args:
656
repo (Repository): Repository to add
657
permission (str, optional): Permission level
658
"""
659
660
def remove_from_repos(self, repo: Repository):
661
"""
662
Remove repository from team.
663
664
Args:
665
repo (Repository): Repository to remove
666
"""
667
```
668
669
## Usage Examples
670
671
### User Information
672
673
```python
674
from github import Github, Auth
675
676
g = Github(auth=Auth.Token("your_token"))
677
678
# Get authenticated user
679
user = g.get_user()
680
print(f"Authenticated as: {user.login}")
681
print(f"Name: {user.name}")
682
print(f"Email: {user.email}")
683
print(f"Public repos: {user.public_repos}")
684
685
# Get another user
686
other_user = g.get_user("octocat")
687
print(f"User: {other_user.name}")
688
print(f"Bio: {other_user.bio}")
689
print(f"Location: {other_user.location}")
690
691
# Get user's repositories
692
for repo in other_user.get_repos():
693
print(f"Repository: {repo.full_name}")
694
```
695
696
### Organization Management
697
698
```python
699
# Get organization
700
org = g.get_organization("myorg")
701
print(f"Organization: {org.name}")
702
print(f"Description: {org.description}")
703
print(f"Public repos: {org.public_repos}")
704
705
# List organization members
706
for member in org.get_members():
707
print(f"Member: {member.login}")
708
709
# Create repository in organization
710
repo = org.create_repo(
711
name="new-project",
712
description="A new project repository",
713
private=True,
714
has_issues=True
715
)
716
print(f"Created repo: {repo.full_name}")
717
```
718
719
### Team Management
720
721
```python
722
# Get organization teams
723
for team in org.get_teams():
724
print(f"Team: {team.name} ({team.members_count} members)")
725
726
# Create a new team
727
team = org.create_team(
728
name="Development Team",
729
description="Main development team",
730
privacy="closed",
731
permission="push"
732
)
733
734
# Add members to team
735
user_to_add = g.get_user("developer")
736
team.add_membership(user_to_add, role="member")
737
738
# Add repository to team
739
team.add_to_repos(repo, permission="push")
740
```