ruia-peewee-async
A Ruia plugin that uses peewee-async to store data to MySQL or PostgreSQL or both of them.
Installation
Using pip or pipenv or poetry to install.
pip install ruia-peewee-async[aiomysql]
pipenv install ruia-peewee-async[aiomysql]
poetry add ruia-peewee-async[aiomysql]
or
pip install ruia-peewee-async[aiopg]
pipenv install ruia-peewee-async[aiopg]
poetry add ruia-peewee-async[aiopg]
or
pip install ruia-peewee-async[all]
pipenv install ruia-peewee-async[all]
poetry install ruia-peewee-async[all]
ruia-peewee-async[all] means to install both aiomysql and aiopg.
Usage
A complete example is in the example directory.
There's a create_model method to create the Peewee model based on database configuration.
You can use the create_model method to manipulate tables before starting the spider.
from ruia_peewee_async import create_model
mysql_model, mysql_manager, postgres_model, postgres_manager = create_model(mysql=mysql) # or postgres=postgres or both
# create the table at the same time
mysql_model, mysql_manager, postgres_model, postgres_manager = create_model(mysql=mysql, create_table=True) # or postgres=postgres or both
rows = mysql_model.select().count()
print(rows)
And class Spider from ruia_peewee_async has attributes below related to database you can use.
from peewee import Model
from typing import Callable, Dict
from typing import Optional as TOptional
from peewee_async import (
AsyncQueryWrapper,
Manager,
MySQLDatabase,
PooledMySQLDatabase,
PooledPostgresqlDatabase,
PostgresqlDatabase,
)
from ruia import Spider as RuiaSpider
class Spider(RuiaSpider):
mysql_model: Union[Model, Dict] # It will be a Model instance after spider started.
mysql_manager: Manager
postgres_model: Union[Model, Dict] # same above
postgres_manager: Manager
mysql_db: MySQLDatabase
postgres_db: PostgresqlDatabase
mysql_filters: TOptional[AsyncQueryWrapper]
postgres_filters: TOptional[AsyncQueryWrapper]
For more information, check out peewee's documentation and peewee-async's documentation.
Development
Using pyenv to install the version of python that you need.
For example
pyenv install 3.7.9
Then go to the root of the project and run:
poetry install && poetry install -E aiomysql -E aiopg
to install all dependencies.
MacOS users have to run brew install postgresql to install postgresql and export the pg_config to the PATH,
so that the psycorg2 dependency can be installed successfully with pip.
- Using
poetry shellto enter the virtual environment. Or open your favorite editor and select the virtual environment to start coding. - Using
pytestto run unit tests undertestsfolder. - Using
pytest --cov .to run all tests and generate coverage report in terminal.
Thanks
Metadata
Release files for ruia-peewee-async 1.3.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ruia_peewee_async-1.3.3.tar.gz | 10.0 kB | Without provenance | Details for ruia_peewee_async-1.3.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ruia_peewee_async-1.3.3-py3-none-any.whl | Python 3 | none | any | Details for ruia_peewee_async-1.3.3-py3-none-any.whl |
Total release size: 22.0 kB
Release files / ruia_peewee_async-1.3.3.tar.gz
| Download URL | ruia_peewee_async-1.3.3.tar.gz |
|---|---|
| Size | 10.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
07fc951488806b9565745459025748a4b30b1281b853d20952dedb88da0966a4
|
|
BLAKE2b-256 checksum How to use checksums |
77d89901003d0fd2b5ff57381ace60839cdd01f8622690fe0936b7a880844a09
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.3 readme-renderer/37.3 requests/2.28.1 requests-toolbelt/0.10.1 urllib3/1.26.12 tqdm/4.64.1 importlib-metadata/5.0.0 keyring/23.11.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.9.15
|
Release files / ruia_peewee_async-1.3.3-py3-none-any.whl
| Download URL | ruia_peewee_async-1.3.3-py3-none-any.whl |
|---|---|
| Size | 12.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cbcc003c54670e27743c9139ecba9f6d3ff791bca860c7104c637c524e0dacf6
|
|
BLAKE2b-256 checksum How to use checksums |
ce753baf1f5783d05d71e9487aebf58110086226991f7bba3d1fef6a571c554c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.3 readme-renderer/37.3 requests/2.28.1 requests-toolbelt/0.10.1 urllib3/1.26.12 tqdm/4.64.1 importlib-metadata/5.0.0 keyring/23.11.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.9.15
|
Security for ruia-peewee-async 1.3.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.