This is an un-official Python package built with Openverse API, currently we only provide image search api in this beta version. The audio search api will be updated in near future.
Explore the docs »
Report Bug
·
Request Feature
Table of Contents
Please follow the instructions to install and set up the environment for this project.
- Clone the repo
git clone https://github.com/Ryotess/PyOpenverse.git
- Move to the project
cd ./PyOpenverse
- Build environment
pip install -r requirements.txt
You can follow the sample code to get the sample usage of this package.
You can directly copy the folder pyopenverse to your project, here is an example structure design:
.
└── your-project/
├── your_custom_module/
│ ├── your_function_1.py
│ └── your_function_2.py
├── PyOpenverse/ <--- Copy & Paste the entire pyopenverse folder here.
│ ├── auth.py
│ ├── config.py
│ └── engine.py
└── your_main.py
If you already have a credential of Openverse API, please put your credential into an .env
file with keys OPENVERSE_CLIENT_ID
and OPENVERSE_CLIENT_SECRET
before the following instruction
If you don't have a credential of Openverse API, we provide an function for you to get your own API's id and secret key.
# import packages and create a pyopenverse engine
from pyopenverse.engine import PyOpenverse
openverse = PyOpenverse()
# Register for API access if not already registered
name = "My amazing project"
description = "To access Openverse API"
email = "user@example.com"
openverse.register(name, description, email)
This method creates a credential for you(and also create a .env
file in the work directory) and loads it into the engine, thus you can use the engine without insert the credential info again.
# import packages and create a pyopenverse engine
from pyopenverse.engine import PyOpenverse
openverse = PyOpenverse()
The engine loads the creadential from the .env
file you just created.
If you don't want to use .env
file, you can also insert the creadential by the following code
openverse = PyOpenverse(client_id="your_client_id", client_secret="your_client_secret")
Now we can use this engine to search images by query (currently only support image search api)
query = "sunset" # Please change the query into what you wanna search
image_urls = openverse.img_search(query=query) # This will return a list of URL of images
Moreover, you can also check the information (ex. status, usage,...) of your account by using get_info()
# Check API information
openverse.get_info()
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the Apache 2.0 License. See LICENSE.txt
for more information.
E-Mail: jessforwork2023@gmail.com
Project Link: https://github.com/Ryotess/PyOpenverse