Media Cloud API Client Library
Project description
MediaCloud Python API Client
This is a python client for accessing the MediaCloud API v4. This allows you to perform cross-platform searches and also browse our collection/source/feed directory.
Usage
First sign up for an API key. Then
pip install mediacloud
Check CHANGELOG.md
for a detailed history of changes.
Examples
Take a look at the test in the mediacloud/test/
module for more detailed examples.
Count Stories Matching a Query
import mediacloud.api
US_NATIONAL_COLLECTION = 34412234
mc_search = mediacloud.api.SearchApi(YOUR_MC_API_KEY)
all_stories = []
pagination_token = None
more_stories = True
while more_stories:
page, pagination_token = mc_search.story_list('robots', start_date= , end_date= collection_ids=[US_NATIONAL_COLLECTION])
all_stories += page
more_stories = pagination_token is not None
print(f"Retrived {len(all_stories)} matching stories")
Page Through Stories Matching a Query
import mediacloud.api
INDIA_NATIONAL_COLLECTION = 34412118
mc_search = mediacloud.api.SearchApi(YOUR_MC_API_KEY)
all_stories = []
pagination_token = None
more_stories = True
while more_stories:
page, pagination_token = mc_search.story_list('modi AND biden', collection_ids=[INDIA_NATIONAL_COLLECTION],
pagination_token=pagination_token)
all_stories += page
more_stories = pagination_token is not None
print(f"Retrived {len(all_stories)} matching stories")
Fetch all Sources in a Collection
import mediacloud.api
INDIA_NATIONAL_COLLECTION = 34412118
SOURCES_PER_PAGE = 100 # the number of sources retrieved per page
mc_directory = mediacloud.api.DirectoryApi(YOUR_MC_API_KEY)
sources = []
offset = 0 # offset for paging through
while True:
# grab a page of sources in the collection
response = mc_directory.source_list(collection_id=INDIA_NATIONAL_COLLECTION, limit=SOURCES_PER_PAGE, offset=offset)
# add it to our running list of all the sources in the collection
sources += response['results']
# if there is no next page then we're done so bail out
if response['next'] is None:
break
# otherwise setup to fetch the next page of sources
offset += len(response['results'])
print("India National Collection has {} sources".format(len(sources)))
Development
If you are interested in adding code to this module, first clone the GitHub repository.
Installing
flit install
pre-commit install
Testing
pytest
Distributing a New Version
- Run
pytest
to make sure all the test pass - Update the version number in
pyproject.toml
- Make a brief note in the
CHANGELOG.md
about what changes - Commit changes, and tag comimt with version number
- Push to main
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
File details
Details for the file mediacloud-4.2.0.tar.gz
.
File metadata
- Download URL: mediacloud-4.2.0.tar.gz
- Upload date:
- Size: 17.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13936d2c2871146ad1e1c6a36d81221d83d985b7b6d435162442b9071a06091b |
|
MD5 | 28a51d216db7086c2cf5742394282f05 |
|
BLAKE2b-256 | df754bb187b53982337e0459070ff96d0f8a6122461fa8237453ad0ffeb02000 |
Provenance
The following attestation bundles were made for mediacloud-4.2.0.tar.gz
:
Publisher:
publish-to-pypi.yml
on mediacloud/api-client
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
mediacloud-4.2.0.tar.gz
- Subject digest:
13936d2c2871146ad1e1c6a36d81221d83d985b7b6d435162442b9071a06091b
- Sigstore transparency entry: 145904470
- Sigstore integration time:
- Predicate type:
File details
Details for the file mediacloud-4.2.0-py3-none-any.whl
.
File metadata
- Download URL: mediacloud-4.2.0-py3-none-any.whl
- Upload date:
- Size: 19.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58683304d64afcf6a494f446146334f828d62866a6b362bef3c227d6919d7238 |
|
MD5 | c13a1b13971d10143a1840aa46249e31 |
|
BLAKE2b-256 | dd44ce650d725097a5b7e081a8a28f8c3c52dafba2b43a37c9664b7d048a1d21 |
Provenance
The following attestation bundles were made for mediacloud-4.2.0-py3-none-any.whl
:
Publisher:
publish-to-pypi.yml
on mediacloud/api-client
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
mediacloud-4.2.0-py3-none-any.whl
- Subject digest:
58683304d64afcf6a494f446146334f828d62866a6b362bef3c227d6919d7238
- Sigstore transparency entry: 145904472
- Sigstore integration time:
- Predicate type: