No project description provided
Project description
ProjectV2 Client
This is an in-progress client to use the ProjectV2 functionality through the GitHub GraphQL API.
Setup
- Install the
projectv2module:pip3 install github-projectv2 - Create a
.envfile in the root containing a value forGITHUB_API_TOKEN(this will be loaded usingpython-dotenv) - Use the
requirements.txtfile to ensure you have all of the dependencies you need. - Enjoy!
NOTE: You can use an actual environment variable instead of the .env approach, setting the same GITHUB_API_TOKEN value
Example Usage
from projectv2.project import Project
project = Project()
project.get('myorg', '1234')
print(project.title)
# Find the field with the name "Test Field 1"
found = None
for field in project.fields:
if field.name == "Test Field 1":
found = field
if found is None:
raise Exception("Field not found")
items = project.get_items('myorg')
print(items)
# Look on the project fields and find the one with the name "Test Field 1" and get its options
# Then, find the option with the name "Option 1" and get its id
for option in found.options:
if option.name == "test3":
newOption = option
for item in items:
result = item.update_field_value(project, field, newOption)
print(result)
Modules
Project
The Project module is used to get the information about a project. It results in an instance with the following properties:
title(string)description(string)id(string): internal ID of project recordnumber(integer): public-facing ID number of projectfields(list): Set of fields in the project, default and customitems(list): Set of "items" in the project, usually issue instancesorg(string): Name of the organization the project belongs tocreatedAt(datetime): Date/time of project creationclosedAt(datetime): Date/time when project was closedclosed(boolean): The open/closed state of the projectshortDescription(string): Short description of the projectpublic(boolean): Visibility for the project (public=True, private=False)readme(string): Full readme for the projecturl(string): Full public-facing URL location of the project
NOTE: When the get method is called on the Project, the get_fields method will automatically be called to populate the fields property with instances of the Field class.
Methods
get(org, projectNumber): Get a project by organization name and public-facing project number
Where:
org(string): the name of the organizationprojectNumber(string): the public-facing ID for the project
get_fields(org): Get the fields for a project given the organization name and public-facing project number
Where:
orgis the name of the organization (optional)
get_field(name): Get a single field from a project
Where:
nameis the name of the field (title)
get_items(args): Get the items currently in the project (issues)
Where args are one or more named variables:
org(string) is the name of the organizationoptions(dict) are options for the query (see "Query Options" section below) Returns:- A set of
Itemobject types
get_views(args): Get the current list of views for the project
Where args are one or more named variables:
org(string): optional name of the organizationoptions(dict) are options for the query (see "Query Options" section below) Returns:- A set of
Viewobject types
create(data): Create a new project
Where:
data(list): Data to use in the creation of the project (required values:title,ownerId) Returns:- A
Projectinstance with the new data set
remove_item(item): Removes an item from a project
Where:
itemmust be a record as fetched byget_items, not from a call toItem.getReturns:- The internal ID of the deleted item
add_item(item): Adds an item/issue to a project
Where:
itemis a record as fetched byItem.getor from the list fromProject.get_itemsReturns:- The internal ID of the item that was added
save(): Saves the current state of the project record (fields saved are title, shortDescription, readme, closed)
Returns:
- The current instance, a
Projectwith the updated information
NOTE: the get_fields and get_items require that the project is fetched using get first and will throw an error otherwise.
Item
The Item module is used to represent an item in a project (an issue or draft issue record). It results in an instance with the following properties:
id(string): internal ID of the item recordtype(string): type of item (ex:ISSUE)created(string): A date/time of when the item was createdassignees(list): A set ofUserinstancestitle(string): Title of the item (issue)number(string): The public-facing number of the itemupdatedAt(string): A date/time of when the item was last updatedurl(string): The public-facing URLbody(string): Unrendered body contentclosed(boolean): Closed/not closed stateclosedAt(string): A date/time of when the issue was closedauthor(list): A set ofUserinstanceslabels(list): A set ofLabelinstancesprojectNodeId(string): The internal ID of the item (used when relating to a project, otherwiseNone)trackedIssues(list): A set ofIteminstancestrackedInIssues(list): A set ofIteminstancestimeline(list): A set of*Eventinstances (see below for which events are currently supported)
Methods
update_field_value(project, field, input): Update a single select field to a new value
Where:
project= aProjectinstancefield= aFieldinstance representing the field to update the value onoption= Either an anOptioninstance representing the new value or a string value
get(org, repo, itemId)
Where:
org(string): the name of the organizationrepo(string): the name of the repositoryitemId(string): the ID number of the item
clear_field_value(project, field)
Where:
project: aProjectinstancefield: aFieldinstance for the field to clear (a result of the objects loaded from aProject.get_fields()method call)
create(repository, data)
Where:
repository: aRepositoryinstancedata: a data set containing the details of the issue you want to create (see below for more detail)
The following are possible values for the data to contain:
body(string, required): the body contents for the issuetitle(string, required): the title of the issueassigneeIds(list, optional): a set of IDs relating to the users you want to assignassignees(list, optional): a set of usernames for the users you want to assignlabelIds(list, optional): a set of IDs related to the labels you want to apply to the issuelabels(list, optional): a set of label names to apply to the issuemilestoneId(string, optional): an ID related to the milestone to link to the issues
Note: if
assigneeIdsis set, it will overrideassignees. Likewise, iflabelIdsis set, it will override thelabelsvalue
add_label(label_name)
Where:
label_nameis the "name" of the label to add (not the ID)
close(reason)
Where:
reason(string, optional) eitherCOMPLETEDorNOT_PLANNED(default isCOMPLETED)
make_comment(comment)
Where:
comment(string) is the contents of the comment
find_field_by_name(name)
Where:
name(string) is the name of the field to find, works when pulled via projects andget_items(Noneif field not found)
add_subissue(item)
Where:
issue(Item) is an Item instance of the issue you want to add to the current one as a sub-issue
Option
The Option module is used to represent an option on a single-select field. It results in an instance with the following properties:
id(string): internal ID of the option recordname(string): the name of the option (this is the option's value)
Field
The Field module is used to represent a field in the project. It results in an instance with the following properties:
id(string): internal ID of the field recordname(string): name of the fielddataType(string): type of field (Ex:TEXTorSINGLE_SELECT)options(list): when thedataTypeisSINGLE_SELECTthe options array will be populated with the options records as instances ofOption
Methods
find_option(name)
Where:
nameis the name (value) of the option. NOTE: only works with single select fields and will throw an error otherwise
Label
The Label module is used to represent a label on an item. It results in an instance with the following properties:
id(string): internal ID of the label recordname(string): name of the labeldescription(string): description of the label
User
The User module is used to represent a user in the system. It results in an instance with the following properties:
id(string): internal ID of the user recordemail(string): email address of the userlogin(string): login/username of the username(string): user's name
Milestone
The Milestone module is used to represent a milestone in the system. It results in an instance with the following properties:
id(string): internal ID of the milestone recorddescription(string): description of the milestonenumber(integer): public-facing IDtitle(string): title of the milestonestate(string): open/closed statusdueOn(string): datetime string of when the milestone is
Methods
get(org)
Where:
org(string): the name of the organization
Repository
The Repository module is used to represent a repository in the system. It results in an instance with the following properties:
id(string): internal ID of the repository recordname(string): name of the repositorydescription(string): repository descriptionisPrivate(boolean): public/private statusisArchived(boolean): archived/not archivedisDisabled(boolean): disabled/not disabledisFork(boolean): is a fork/not a forkisLocked(boolean): is locked/not lockedisMirror(boolean): is a mirror/not a mirrorisTemplate(boolean): is a template/not a template
Methods
get(org, name)
Where:
org(string): organization namename(string): repository name
get_milestones()
NOTE: get_milestones requires that get() is called first
Comment
The Comment module is used to represent a comment instance on an item. It results in an instance with the following properties:
id(string) internal ID of the comment recordbody(string) the contents of the comment bodyupdatedAt(string) the timestamp when the comment was createdauthor(User) a User object instance for the author of the comment
Methods
delete()
Where:
It will delete the comment represented by the current instance
Organization
The Organization module is used to represent an organization in the system. It results in an instance with the following properties:
id(string): internal ID of the organization recordname(string): name of the organization (ex:GitHub)login(string): the login of the organization (ex:github)description(string): the description of the organizationcreatedAt(string): datetime stringlocation(string): location value of the organizationurl(string): external URL locationrepositories(list): a list of all repositories in the organization (loads asRepository objects)
NOTE: Repositories are not loaded by default. get_repositories must be called to load them. The method will also return the repository list.
Methods
get(login)
Where:
login(string) the name of the organization Returns:- A single object of type
Organization
get_repositories(login)
Where:
login(string): the name of the organization (nameis optional, but if not setgetmust be called first) Returns:- A set of
Repositoryclass objects populated with repository data
Search
The Search module is used to make searches using the search() method on the GraphQL API using a format similar to those used in the search on the website.
- No properties defined
Methods
issues
Where:
filter(string): the search filter string, passed using nameed parameterfilter=...slim(string): tell the search method to pull a "slim" version of the issues Returns:- Set of
Itemclass objects populated with matching issue data
View
The View module represents a view in the project (a tab). It results in an instance with the following properties:
id(string): internal ID of the viewnumber(string): the public ID of the viewsortBy(array): populated when a view is sorted (contains:field.name,field.id(internal),field.dataType,direction)groupBy(array): populated when a view is grouped (contains:id(internal),name)layout(string): Layout of the view (ex:TABLE_LAYOUTorBOARD_LAYOUT)
Resource: https://mathspp.com/blog/how-to-create-a-python-package-in-2022
Timeline Events
Several of the methods, including item.get and project.get_items (if the value for includeTimelineEvents is True) will also pull in the timeline events for an item. This timeline provides details about actions like: when an issue was labeled, when someone subscribed to an issue, and when a user was mentioned in an issue. We currently support several event types:
AddedToProjectEventAssignedEventClosedEventCommentDeletedEventCrossReferencedEventIssueCommentIssueTypeAddedEventIssueTypeChangedEventLabeledEventMentionedEventMovedColumnsInProjectEventParentIssueAddedEventParentIssueRemovedEventPinnedEventReferencedEventRenamedTitleEventReopenedEventSubIssueAddedEventSubIssueRemovedEventSubscribedEventUnassignedEventUnlabeledEventUnsubscribedEvent
You can find out more about what properties each of these support in the GitHub API object documentation.
Query Options
In some methods (such as project.get_items) use can used named arguments to configure the requests made to the API (see method definitions above to determine which support the options named variable)
Supported options:
includeTrackedInIssues: Includes information about the other item(s) the current item is tracked in (Values:True/False)includeTrackedIssues: Include information about the item(s) being tracked by this item (Values:True/False)includeTimelineEvents: Include the timeline events that were taken on the item (Values:True/False)includeFields: Include the field information in the item, works when pulled via a project (Values:True/False)useSlimIssue: Return the items with the "slim" version of the results (Values:True/False)
Development
This package makes use of the Poetry packaging tool. In order to do development work, you should perform the following steps:
cd projectv2
poetry shell
Then you can run your script from there. In my case, it's one called test.py that lives one directory up, so: python3 ../test.py
Then, to package, build, and push it up to the PyPi platform:
- Update the
versioninpyproject.toml - Commit the changes and add a new tag
- Push the updates to the repo (including the new tag)
- Run the build and push commands from outside of the
poetryshell:
poetry build
poetry publish
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 Distribution
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 github_projectv2-0.7.31.tar.gz.
File metadata
- Download URL: github_projectv2-0.7.31.tar.gz
- Upload date:
- Size: 26.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.13.5 Darwin/24.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f12ade4b6816028db72c13500575352ba9820c282c1ed80ec29bd3248796232
|
|
| MD5 |
e16cb2a86f927dba0b64e3b0f18c4d2d
|
|
| BLAKE2b-256 |
2307e6cdc40fcbe5ef8c6463cc738d5c09690b3228551a77dd7d1e94d3b22cf2
|
File details
Details for the file github_projectv2-0.7.31-py3-none-any.whl.
File metadata
- Download URL: github_projectv2-0.7.31-py3-none-any.whl
- Upload date:
- Size: 55.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.13.5 Darwin/24.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e9b63948968e2eee55ab51fac4c6a02c360ae612801dd40e53d26eccfa275536
|
|
| MD5 |
e83257aeadaccf34e1ef230ca7f61aba
|
|
| BLAKE2b-256 |
76cd3b774526a3b15772a38da7af38b1599996f21d664491a0b16007f5bc6c7e
|