Skip to main content

A python wrapper for the Gitea API

Project description

py-gitea

A very simple API client for Gitea > 1.16.1

This has been somewhat tested (and used), so most things should work as expected.

Note that not the full Swagger-API is accessible. The whole implementation is focused on making access and working with Organizations, Teams, Repositories and Users as pain free as possible.

Originally forked from https://github.com/m301/py-gitea.

Usage

First get a gitea object wrapping access and authentication (via an api token) for your gitea instance:

from gitea import *

gitea = Gitea(URL, TOKEN)

Operations like requesting the Gitea version or authentication user can be requested directly from the gitea object:

print("Gitea Version: " + gitea.get_version())
print("API-Token belongs to user: " + gitea.get_user().username)

Adding entities like Users, Organizations, ... also is done via the gitea object.

user = gitea.create_user("Test Testson", "test@test.test", "password")

All operations on entities in gitea are then accomplished via the according wrapper objects for those entities. Each of those objects has a .request method that creates an entity according to your gitea instance.

other_user = User.request(gitea, "OtherUserName")
print(other_user.username)

Note that the fields of the User, Organization,... classes are dynamically created at runtime, and thus not visible during divelopment. Refer to the Gitea-API documentation for the fields names.

Fields that can not be altered via gitea-api, are read only. After altering a field, the .commit method of the according object must be called to synchronize the changed fields with your gitea instance.

org = Organization.request(gitea, test_org)
org.description = "some new description"
org.location = "some new location"
org.commit()

An entity in gitea can be deleted by calling delete.

org.delete()

All entity objects do have methods to execute some of the requests possible though the gitea-api:

org = Organization.request(gitea, ORGNAME)
teams = org.get_teams()
for team in teams:
    repos = team.get_repos()
    for repo in repos:
        print(repo.name)

Installation

Use pip install py-gitea to install.

Tests

Tests can be run with:

python3 -m pytest test_api.py

Make sure to have a gitea-instance running on http://localhost:3000, and an admin-user token at .token. The admin user must be named test, with email secondarytest@test.org.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py-gitea-0.2.9.tar.gz (20.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_gitea-0.2.9-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file py-gitea-0.2.9.tar.gz.

File metadata

  • Download URL: py-gitea-0.2.9.tar.gz
  • Upload date:
  • Size: 20.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.1

File hashes

Hashes for py-gitea-0.2.9.tar.gz
Algorithm Hash digest
SHA256 9373fc77236a3437949a50c305384d29221348009fd8582f91408627f32d7f5e
MD5 212a5703ae3515240c8a3cc3b66f811d
BLAKE2b-256 5d7cf024b92a29ddfe8b23c43879160871cfc3dd3506747423b1d1c01da56420

See more details on using hashes here.

File details

Details for the file py_gitea-0.2.9-py3-none-any.whl.

File metadata

  • Download URL: py_gitea-0.2.9-py3-none-any.whl
  • Upload date:
  • Size: 16.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.1

File hashes

Hashes for py_gitea-0.2.9-py3-none-any.whl
Algorithm Hash digest
SHA256 70e2a083d6bfedabb4f2a3a914145f2e0945849e9b940470589239982dbdbec1
MD5 aa47b37c23810aff7aca8bd5403aaafa
BLAKE2b-256 674706f08cbb525283623dd30adc8430bd40b1f28dfc80bcbdf6ef51776c1a4d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page