pyszuru


Namepyszuru JSON
Version 0.3.0 PyPI version JSON
download
home_pagehttps://github.com/sgsunder/python-szurubooru
SummaryPython interface for szurubooru
upload_time2023-02-02 04:52:52
maintainer
docs_urlNone
authorShyam Sunder
requires_python>=3.8
license
keywords szurubooru booru
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pyszuru
Python interface for szurubooru

Installation: `pip install pyszuru`

# Usage

### Creating API Instance
```python
import pyszuru
mybooru = pyszuru.API(
    "https://example.com/booru",
    username="alice",
    # Authenticate with a password
    password="hunter2",
    # Or use a token
    token="my-token-string",
    # Optionally specify a API base URL if it differs from the default configuration
    # api_url="/booru-api", <-- relative to base URL
    # api_url="https://api.example.com/booru", <-- new absolute base
)
```

### Working with tags
Note: it is reccomended to use the factory functions outlined below instead of calling the `Tag`
constructor directly.

#### Get existing tag
Get an existing tag from the booru by referencing it by name
```python
marvel_comics_tag = mybooru.getTag("marvel_comics")
```

#### Create new tag
Create a new tag, must specifiy a primary name only
```python
spiderman_tag = mybooru.createTag("spiderman")
```

#### Alter properties of tag
```python
spiderman_tag.implications = spiderman_tag.implications + [marvel_comics_tag]
spiderman_tag.push()
```

### Working with posts
Note: it is reccomended to use the factory functions outlined below instead of calling the `Post`
constructor directly.

#### Get existing post
```python
my_old_post = mybooru.getPost(1337)
```

#### Create a post
```python
with open("image.jpg", "rb") as f:
    file_token = mybooru.upload_file(f)
my_new_post = mybooru.createPost(file_token, "safe")
```

#### Alter tags of a post
```python
my_new_post.tags = [marvel_comics_tag, spiderman_tag]
my_new_post.push()
```

### Searching

#### Searching across tags
```python
unused_tags = mybooru.search_tag("usages:0")
```

#### Searching across posts
```python
for post in mybooru.search_post(
    "marvel_comics type:image special:fav", show_progress_bar=True
):
    wget.download(post.content)
```

#### Reverse image search
```python
with open("similar.jpg", "rb") as f:
    similar_file_token = mybooru.upload_file(f)
result = mybooru.search_by_image(similar_file_token)
if result:
    if any(x.exact for x in result):
        raise Exception("Found an exact match")
    else:
        warnings.warn(f"Found {len(result)} similar posts")
```



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/sgsunder/python-szurubooru",
    "name": "pyszuru",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "szurubooru,booru",
    "author": "Shyam Sunder",
    "author_email": "sgsunder1@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/34/e5/3ad2cf356e59dec77cfef59d998bcb62f9a268b9ba7fa53295096d377c68/pyszuru-0.3.0.tar.gz",
    "platform": null,
    "description": "# pyszuru\nPython interface for szurubooru\n\nInstallation: `pip install pyszuru`\n\n# Usage\n\n### Creating API Instance\n```python\nimport pyszuru\nmybooru = pyszuru.API(\n    \"https://example.com/booru\",\n    username=\"alice\",\n    # Authenticate with a password\n    password=\"hunter2\",\n    # Or use a token\n    token=\"my-token-string\",\n    # Optionally specify a API base URL if it differs from the default configuration\n    # api_url=\"/booru-api\", <-- relative to base URL\n    # api_url=\"https://api.example.com/booru\", <-- new absolute base\n)\n```\n\n### Working with tags\nNote: it is reccomended to use the factory functions outlined below instead of calling the `Tag`\nconstructor directly.\n\n#### Get existing tag\nGet an existing tag from the booru by referencing it by name\n```python\nmarvel_comics_tag = mybooru.getTag(\"marvel_comics\")\n```\n\n#### Create new tag\nCreate a new tag, must specifiy a primary name only\n```python\nspiderman_tag = mybooru.createTag(\"spiderman\")\n```\n\n#### Alter properties of tag\n```python\nspiderman_tag.implications = spiderman_tag.implications + [marvel_comics_tag]\nspiderman_tag.push()\n```\n\n### Working with posts\nNote: it is reccomended to use the factory functions outlined below instead of calling the `Post`\nconstructor directly.\n\n#### Get existing post\n```python\nmy_old_post = mybooru.getPost(1337)\n```\n\n#### Create a post\n```python\nwith open(\"image.jpg\", \"rb\") as f:\n    file_token = mybooru.upload_file(f)\nmy_new_post = mybooru.createPost(file_token, \"safe\")\n```\n\n#### Alter tags of a post\n```python\nmy_new_post.tags = [marvel_comics_tag, spiderman_tag]\nmy_new_post.push()\n```\n\n### Searching\n\n#### Searching across tags\n```python\nunused_tags = mybooru.search_tag(\"usages:0\")\n```\n\n#### Searching across posts\n```python\nfor post in mybooru.search_post(\n    \"marvel_comics type:image special:fav\", show_progress_bar=True\n):\n    wget.download(post.content)\n```\n\n#### Reverse image search\n```python\nwith open(\"similar.jpg\", \"rb\") as f:\n    similar_file_token = mybooru.upload_file(f)\nresult = mybooru.search_by_image(similar_file_token)\nif result:\n    if any(x.exact for x in result):\n        raise Exception(\"Found an exact match\")\n    else:\n        warnings.warn(f\"Found {len(result)} similar posts\")\n```\n\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Python interface for szurubooru",
    "version": "0.3.0",
    "split_keywords": [
        "szurubooru",
        "booru"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bc034c42317ec2f58363047b947c92d8d3c9d9f09dad40605907ad0e4ff932d2",
                "md5": "7114932b4f641a67e0836b1b5a03b567",
                "sha256": "d0c31a543ea83d00f5771c6c3119e610cccd9e7c911f2cf21bd937fc021c7684"
            },
            "downloads": -1,
            "filename": "pyszuru-0.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7114932b4f641a67e0836b1b5a03b567",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 23688,
            "upload_time": "2023-02-02T04:52:50",
            "upload_time_iso_8601": "2023-02-02T04:52:50.365167Z",
            "url": "https://files.pythonhosted.org/packages/bc/03/4c42317ec2f58363047b947c92d8d3c9d9f09dad40605907ad0e4ff932d2/pyszuru-0.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "34e53ad2cf356e59dec77cfef59d998bcb62f9a268b9ba7fa53295096d377c68",
                "md5": "40a006af54ade7f5b6b8bbfba0db827d",
                "sha256": "5caa9175cc931c28b6d673d36f53ea33d471391028c49e90e3cd1eb7012395c3"
            },
            "downloads": -1,
            "filename": "pyszuru-0.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "40a006af54ade7f5b6b8bbfba0db827d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 22688,
            "upload_time": "2023-02-02T04:52:52",
            "upload_time_iso_8601": "2023-02-02T04:52:52.087121Z",
            "url": "https://files.pythonhosted.org/packages/34/e5/3ad2cf356e59dec77cfef59d998bcb62f9a268b9ba7fa53295096d377c68/pyszuru-0.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-02-02 04:52:52",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "sgsunder",
    "github_project": "python-szurubooru",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "pyszuru"
}
        
Elapsed time: 0.03642s