Pygithub: Is there a way to get raw format of a ContentFile?

Created on 6 May 2017  ·  14Comments  ·  Source: PyGithub/PyGithub

ContentFile.content returns the base64-encoded content from the API. The API also supports getting the raw format of the file.

These API methods let you retrieve the contents of files within a repository as Base64 encoded content. See media types for requesting the raw format or rendered HTML (when supported).

READMEs, files, and symlinks support the following custom media types:

application/vnd.github.VERSION.raw
application/vnd.github.VERSION.html

Use the .raw media type to retrieve the contents of the file.

Is there any way to do this via the library today? If not, would you be open to adding support for it?

stale

Most helpful comment

Have you tried this:

f = repo.get_file_contents("/path/to/file", ref)
raw_data = f.decoded_content

All 14 comments

curl example of getting file's raw content.

curl -H 'Accept: application/vnd.github.v3.raw' \
https://api.github.com/repositories/40143493/git/blobs/8ae96e4096e66c97be4fde1356a971cbb99928e1'

Have you tried this:

f = repo.get_file_contents("/path/to/file", ref)
raw_data = f.decoded_content

@mikeage Thanks. That works. How come decoded_content and some other ContentFile attributes aren't in the docs here? Can we update the docs?

No idea; I'm just a user, like you. Seems like the dev may be away (temporarily?), given how many open PRs there are that haven't gotten any responses.

Documentation needs updates.

@davidxia As you also suffered from the lacking docs, then this issue should have not been closed, IMO

Two years later, the page is still silent about decode_content, so it may be overlooked because nobody reported it :-)
https://pygithub.readthedocs.io/en/latest/github_objects/ContentFile.html

I'm also reading this just now, and its very useful, it gets me the file text content.
No one ever thought about updating the file on the basis of the existing content, I guess

Documentation PR welcome

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Hi stale_bot !

Thx to you to don't close this issue, we really need this documentation update.

;)

+1ing this, faced the same issue and stumbled on this issue via search

Hi @thomas-bouhon , @abhn -- I submitted a PR couple of months ago for this issue. Now stale_bot has marked it as stale -- would you know how can we get my PR reviewed so it can be merged before it is closed by stale_bot?

We can fork this and make a new repo with a new python module ?

If anyone is agreed to me, then contact me on Telegram :- @jainamoswal

@mloskot @mikeage @davidxia @sfdye @mrodozov

@hostingthepage Although I'm not an active contributor, I don't mind any motion for sustainable development of any project I use or contribute to.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gschaffner picture gschaffner  ·  24Comments

OlegYurchik picture OlegYurchik  ·  10Comments

mattroid picture mattroid  ·  12Comments

pconrad picture pconrad  ·  14Comments

lost-a-tooth picture lost-a-tooth  ·  17Comments