Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-web-client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Platform
Development
swh-web-client
Commits
b921e208
Commit
b921e208
authored
5 years ago
by
Stefano Zacchiroli
Browse files
Options
Downloads
Patches
Plain Diff
client.py: make docstring start with uppercase letters
parent
0f8452d7
No related branches found
Branches containing commit
Tags
v0.1.0
Tags containing commit
1 merge request
!1
add Python client for the Web API
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
swh/web/client/client.py
+25
-25
25 additions, 25 deletions
swh/web/client/client.py
with
25 additions
and
25 deletions
swh/web/client/client.py
+
25
−
25
View file @
b921e208
...
...
@@ -44,7 +44,7 @@ PIDish = Union[PID, str]
def
_get_pid
(
pidish
:
PIDish
)
->
PID
:
"""
p
arse string to PID if needed
"""
"""
P
arse string to PID if needed
"""
if
isinstance
(
pidish
,
str
):
return
parse_pid
(
pidish
)
else
:
...
...
@@ -52,9 +52,9 @@ def _get_pid(pidish: PIDish) -> PID:
def
typify
(
data
:
Any
,
obj_type
:
str
)
->
Any
:
"""
t
ype API responses using pythonic types where appropriate
"""
T
ype API responses using pythonic types where appropriate
t
he following conversions are performed:
T
he following conversions are performed:
- identifiers are converted from strings to PersistentId instances
- timestamps are converted from strings to datetime.datetime objects
...
...
@@ -109,16 +109,16 @@ def typify(data: Any, obj_type: str) -> Any:
class
WebAPIClient
:
"""
c
lient for the Software Heritage archive Web API, see
"""
C
lient for the Software Heritage archive Web API, see
https://archive.softwareheritage.org/api/
"""
def
__init__
(
self
,
api_url
=
'
https://archive.softwareheritage.org/api/1
'
):
"""
c
reate a client for the Software Heritage Web API
"""
C
reate a client for the Software Heritage Web API
s
ee: https://archive.softwareheritage.org/api/
S
ee: https://archive.softwareheritage.org/api/
Args:
api_url: base URL for API calls (default:
...
...
@@ -141,7 +141,7 @@ class WebAPIClient:
def
_call
(
self
,
query
:
str
,
http_method
:
str
=
'
get
'
,
**
req_args
)
->
requests
.
models
.
Response
:
"""
d
ispatcher for archive API invocation
"""
D
ispatcher for archive API invocation
Args:
query: API method to be invoked, rooted at api_url
...
...
@@ -170,7 +170,7 @@ class WebAPIClient:
return
r
def
_get_snapshot
(
self
,
pid
:
PIDish
)
->
Dict
[
str
,
Any
]:
"""
a
nalogous to self.snapshot(), but zipping through partial snapshots,
"""
A
nalogous to self.snapshot(), but zipping through partial snapshots,
merging them together before returning
"""
...
...
@@ -181,14 +181,14 @@ class WebAPIClient:
return
snapshot
def
get
(
self
,
pid
:
PIDish
,
**
req_args
)
->
Any
:
"""
r
etrieve information about an object of any kind
"""
R
etrieve information about an object of any kind
d
ispatcher method over the more specific methods content(),
D
ispatcher method over the more specific methods content(),
directory(), etc.
n
ote that this method will buffer the entire output in case of long,
N
ote that this method will buffer the entire output in case of long,
iterable output (e.g., for snapshot()), see the iter() method for
streaming
streaming
.
"""
...
...
@@ -197,9 +197,9 @@ class WebAPIClient:
def
iter
(
self
,
pid
:
PIDish
,
**
req_args
)
->
Generator
[
Dict
[
str
,
Any
],
None
,
None
]:
"""
s
tream over the information about an object of any kind
"""
S
tream over the information about an object of any kind
s
treaming variant of get()
S
treaming variant of get()
"""
pid_
=
_get_pid
(
pid
)
...
...
@@ -218,7 +218,7 @@ class WebAPIClient:
raise
ValueError
(
f
'
invalid object type:
{
obj_type
}
'
)
def
content
(
self
,
pid
:
PIDish
,
**
req_args
)
->
Dict
[
str
,
Any
]:
"""
r
etrieve information about a content object
"""
R
etrieve information about a content object
Args:
pid: object identifier
...
...
@@ -234,7 +234,7 @@ class WebAPIClient:
CONTENT
)
def
directory
(
self
,
pid
:
PIDish
,
**
req_args
)
->
List
[
Dict
[
str
,
Any
]]:
"""
r
etrieve information about a directory object
"""
R
etrieve information about a directory object
Args:
pid: object identifier
...
...
@@ -250,7 +250,7 @@ class WebAPIClient:
DIRECTORY
)
def
revision
(
self
,
pid
:
PIDish
,
**
req_args
)
->
Dict
[
str
,
Any
]:
"""
r
etrieve information about a revision object
"""
R
etrieve information about a revision object
Args:
pid: object identifier
...
...
@@ -266,7 +266,7 @@ class WebAPIClient:
REVISION
)
def
release
(
self
,
pid
:
PIDish
,
**
req_args
)
->
Dict
[
str
,
Any
]:
"""
r
etrieve information about a release object
"""
R
etrieve information about a release object
Args:
pid: object identifier
...
...
@@ -283,7 +283,7 @@ class WebAPIClient:
def
snapshot
(
self
,
pid
:
PIDish
,
**
req_args
)
->
Generator
[
Dict
[
str
,
Any
],
None
,
None
]:
"""
r
etrieve information about a snapshot object
"""
R
etrieve information about a snapshot object
Args:
pid: object identifier
...
...
@@ -311,7 +311,7 @@ class WebAPIClient:
done
=
True
def
content_exists
(
self
,
pid
:
PIDish
,
**
req_args
)
->
bool
:
"""
c
heck if a content object exists in the archive
"""
C
heck if a content object exists in the archive
Args:
pid: object identifier
...
...
@@ -325,7 +325,7 @@ class WebAPIClient:
http_method
=
'
head
'
,
**
req_args
))
def
directory_exists
(
self
,
pid
:
PIDish
,
**
req_args
)
->
bool
:
"""
c
heck if a directory object exists in the archive
"""
C
heck if a directory object exists in the archive
Args:
pid: object identifier
...
...
@@ -339,7 +339,7 @@ class WebAPIClient:
http_method
=
'
head
'
,
**
req_args
))
def
revision_exists
(
self
,
pid
:
PIDish
,
**
req_args
)
->
bool
:
"""
c
heck if a revision object exists in the archive
"""
C
heck if a revision object exists in the archive
Args:
pid: object identifier
...
...
@@ -353,7 +353,7 @@ class WebAPIClient:
http_method
=
'
head
'
,
**
req_args
))
def
release_exists
(
self
,
pid
:
PIDish
,
**
req_args
)
->
bool
:
"""
c
heck if a release object exists in the archive
"""
C
heck if a release object exists in the archive
Args:
pid: object identifier
...
...
@@ -367,7 +367,7 @@ class WebAPIClient:
http_method
=
'
head
'
,
**
req_args
))
def
snapshot_exists
(
self
,
pid
:
PIDish
,
**
req_args
)
->
bool
:
"""
c
heck if a snapshot object exists in the archive
"""
C
heck if a snapshot object exists in the archive
Args:
pid: object identifier
...
...
@@ -382,7 +382,7 @@ class WebAPIClient:
def
content_raw
(
self
,
pid
:
PIDish
,
**
req_args
)
->
Generator
[
bytes
,
None
,
None
]:
"""
i
terate over the raw content of a content object
"""
I
terate over the raw content of a content object
Args:
pid: object identifier
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment