discbase


Namediscbase JSON
Version 0.5.0 PyPI version JSON
download
home_pagehttps://github.com/joeyagreco/discbase
SummaryDiscord as a Service
upload_time2024-02-11 17:29:32
maintainer
docs_urlNone
authorJoey Greco
requires_python>=3.10
licenseMIT
keywords discord database db
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <div align="center">
    <img src="https://raw.githubusercontent.com/joeyagreco/discbase/main/img/discbase_1.png" alt="discbase logo" width="300"/>
<h1>Discbase</h1>
<h3>Discord as a Database</h3>

<a target="_blank" href="https://www.python.org/downloads/" title="Python version"><img src="https://img.shields.io/badge/python-%3E=_3.10-teal.svg"></a>
![Last Commit](https://img.shields.io/github/last-commit/joeyagreco/discbase)
<br>
![E2E Tests](https://github.com/joeyagreco/discbase/actions/workflows/e2e-tests.yml/badge.svg)
![Unit Tests](https://github.com/joeyagreco/discbase/actions/workflows/unit-tests.yml/badge.svg)
![Build](https://github.com/joeyagreco/discbase/actions/workflows/build.yml/badge.svg)
![Formatting Check](https://github.com/joeyagreco/discbase/actions/workflows/formatting-check.yml/badge.svg)
</div>

## Disclaimer
Use this library responsibly and be sure to read [Discord's Terms of Service](https://discord.com/terms) before using.

## Quickstart

Use the package manager [pip](https://pip.pypa.io/en/stable/) to install.

```bash
pip install discbase
```

### Set up a Discord bot

1. Navigate to the [Discord Developer Applications page](https://discord.com/developers/applications)

2. Create a new application and name it
<img src="https://raw.githubusercontent.com/joeyagreco/discbase/main/img/quickstart/create_an_application.png" width="500">

3. Navigate to `Settings/General Information` and save the `Application ID`
<img src="https://raw.githubusercontent.com/joeyagreco/discbase/main/img/quickstart/settings_general_information.png" width="500">
<img src="https://raw.githubusercontent.com/joeyagreco/discbase/main/img/quickstart/application_id.png" width="500">

4. Navigate to `Settings/Bot`
<img src="https://raw.githubusercontent.com/joeyagreco/discbase/main/img/quickstart/settings_bot.png" width="500">

5. Click `Reset Token`, and save the `Token`
<img src="https://raw.githubusercontent.com/joeyagreco/discbase/main/img/quickstart/reset_token.png" width="500">

6. Enable `Presence Intent`, `Server Members Intent`, and `Message Content Intent`
<img src="https://raw.githubusercontent.com/joeyagreco/discbase/main/img/quickstart/privileged_intents.png" width="500">

7. Paste the application ID you saved into the following URL and paste it into any browser: https://discord.com/api/oauth2/authorize?client_id=APPLICATION_ID_HERE&permissions=8&scope=bot

8. Select the server you would like to add this to and follow the prompts to authorize
<img src="https://raw.githubusercontent.com/joeyagreco/discbase/main/img/quickstart/add_bot_to_server.png" width="500">

### Pick a Channel to Use for Storage
1. Go to the server that you want to use. The bot you created should be there
<img src="https://raw.githubusercontent.com/joeyagreco/discbase/main/img/quickstart/offline_bot.png" width="500">

2. Find or create the channel you would like to use for storage, right click on the name and copy the channel ID
<img src="https://raw.githubusercontent.com/joeyagreco/discbase/main/img/quickstart/copy_channel_id.png" width="500">

### Run the Client

```python
import asyncio

from discbase.database.Client import Client

if __name__ == "__main__":
    # put your token here as a string
    TOKEN = "TOKEN_123"
    # put your channel id here as an integer
    CHANNEL_ID = 123
    client = Client(discord_client_token=TOKEN, discord_channel_id=CHANNEL_ID)
    
    async def main():
        # start the client
        await client.start()
        try:
            # store some text data and some media
            stored_record = await client.dump(value="some message", media_paths=["https://some_image.png"])
            # retrieve the data
            retrieved_record = await client.retrieve(record_id=stored_record.record_id)
            my_message = stored_record.text_data
            my_media_url = stored_record.media_urls[0]
        except Exception as e:
            print(e)
        # stop the client
        await client.stop()
    
    # run code asynchronously
    asyncio.run(main())
```

### Alternatively, Run the Client as a Context Manager

This is much slower as each time the context manager is used, it has to start up the client and connect first.

The advantage is closing will always be taken care of automatically.

```python
import asyncio

from discbase.database.Client import Client

if __name__ == "__main__":
    async def main():
        # this runs the client
        async with Client(discord_client_token="TOKEN_123", discord_channel_id=123) as client:
            await client.dump(value="foo")
        # the client is now closed automatically

    asyncio.run(main())
``` 

## Performance
**NOTE:** You will need to save environment variables for `BOT_TOKEN` and `CHANNEL_ID` before running this.
```bash
$ export BOT_TOKEN='token'            # your bot token here
$ export CHANNEL_ID=12345             # your discord channel id
$ make speedtest                      # run speedtest with default number of messages
$ make speedtest SPEEDTEST_COUNT=100  # run speedtest with 100 messages
```

## Development

_Run these commands from the root folder_
- Install Dependencies: `make deps`
- Format Code: `make fmt`
- Run Unit Tests: `make test-unit`
- Run E2E Tests: `make test-e2e`
- Run All Tests: `make test-all`

## Styling

Primary Color: `#8557BA`

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/joeyagreco/discbase",
    "name": "discbase",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "",
    "keywords": "discord database db",
    "author": "Joey Greco",
    "author_email": "joeyagreco@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/40/a5/6e24b2e92e6707039d3fc473cc0f5aa4d8327566de4915a62c87b681ffc9/discbase-0.5.0.tar.gz",
    "platform": null,
    "description": "<div align=\"center\">\n    <img src=\"https://raw.githubusercontent.com/joeyagreco/discbase/main/img/discbase_1.png\" alt=\"discbase logo\" width=\"300\"/>\n<h1>Discbase</h1>\n<h3>Discord as a Database</h3>\n\n<a target=\"_blank\" href=\"https://www.python.org/downloads/\" title=\"Python version\"><img src=\"https://img.shields.io/badge/python-%3E=_3.10-teal.svg\"></a>\n![Last Commit](https://img.shields.io/github/last-commit/joeyagreco/discbase)\n<br>\n![E2E Tests](https://github.com/joeyagreco/discbase/actions/workflows/e2e-tests.yml/badge.svg)\n![Unit Tests](https://github.com/joeyagreco/discbase/actions/workflows/unit-tests.yml/badge.svg)\n![Build](https://github.com/joeyagreco/discbase/actions/workflows/build.yml/badge.svg)\n![Formatting Check](https://github.com/joeyagreco/discbase/actions/workflows/formatting-check.yml/badge.svg)\n</div>\n\n## Disclaimer\nUse this library responsibly and be sure to read [Discord's Terms of Service](https://discord.com/terms) before using.\n\n## Quickstart\n\nUse the package manager [pip](https://pip.pypa.io/en/stable/) to install.\n\n```bash\npip install discbase\n```\n\n### Set up a Discord bot\n\n1. Navigate to the [Discord Developer Applications page](https://discord.com/developers/applications)\n\n2. Create a new application and name it\n<img src=\"https://raw.githubusercontent.com/joeyagreco/discbase/main/img/quickstart/create_an_application.png\" width=\"500\">\n\n3. Navigate to `Settings/General Information` and save the `Application ID`\n<img src=\"https://raw.githubusercontent.com/joeyagreco/discbase/main/img/quickstart/settings_general_information.png\" width=\"500\">\n<img src=\"https://raw.githubusercontent.com/joeyagreco/discbase/main/img/quickstart/application_id.png\" width=\"500\">\n\n4. Navigate to `Settings/Bot`\n<img src=\"https://raw.githubusercontent.com/joeyagreco/discbase/main/img/quickstart/settings_bot.png\" width=\"500\">\n\n5. Click `Reset Token`, and save the `Token`\n<img src=\"https://raw.githubusercontent.com/joeyagreco/discbase/main/img/quickstart/reset_token.png\" width=\"500\">\n\n6. Enable `Presence Intent`, `Server Members Intent`, and `Message Content Intent`\n<img src=\"https://raw.githubusercontent.com/joeyagreco/discbase/main/img/quickstart/privileged_intents.png\" width=\"500\">\n\n7. Paste the application ID you saved into the following URL and paste it into any browser: https://discord.com/api/oauth2/authorize?client_id=APPLICATION_ID_HERE&permissions=8&scope=bot\n\n8. Select the server you would like to add this to and follow the prompts to authorize\n<img src=\"https://raw.githubusercontent.com/joeyagreco/discbase/main/img/quickstart/add_bot_to_server.png\" width=\"500\">\n\n### Pick a Channel to Use for Storage\n1. Go to the server that you want to use. The bot you created should be there\n<img src=\"https://raw.githubusercontent.com/joeyagreco/discbase/main/img/quickstart/offline_bot.png\" width=\"500\">\n\n2. Find or create the channel you would like to use for storage, right click on the name and copy the channel ID\n<img src=\"https://raw.githubusercontent.com/joeyagreco/discbase/main/img/quickstart/copy_channel_id.png\" width=\"500\">\n\n### Run the Client\n\n```python\nimport asyncio\n\nfrom discbase.database.Client import Client\n\nif __name__ == \"__main__\":\n    # put your token here as a string\n    TOKEN = \"TOKEN_123\"\n    # put your channel id here as an integer\n    CHANNEL_ID = 123\n    client = Client(discord_client_token=TOKEN, discord_channel_id=CHANNEL_ID)\n    \n    async def main():\n        # start the client\n        await client.start()\n        try:\n            # store some text data and some media\n            stored_record = await client.dump(value=\"some message\", media_paths=[\"https://some_image.png\"])\n            # retrieve the data\n            retrieved_record = await client.retrieve(record_id=stored_record.record_id)\n            my_message = stored_record.text_data\n            my_media_url = stored_record.media_urls[0]\n        except Exception as e:\n            print(e)\n        # stop the client\n        await client.stop()\n    \n    # run code asynchronously\n    asyncio.run(main())\n```\n\n### Alternatively, Run the Client as a Context Manager\n\nThis is much slower as each time the context manager is used, it has to start up the client and connect first.\n\nThe advantage is closing will always be taken care of automatically.\n\n```python\nimport asyncio\n\nfrom discbase.database.Client import Client\n\nif __name__ == \"__main__\":\n    async def main():\n        # this runs the client\n        async with Client(discord_client_token=\"TOKEN_123\", discord_channel_id=123) as client:\n            await client.dump(value=\"foo\")\n        # the client is now closed automatically\n\n    asyncio.run(main())\n``` \n\n## Performance\n**NOTE:** You will need to save environment variables for `BOT_TOKEN` and `CHANNEL_ID` before running this.\n```bash\n$ export BOT_TOKEN='token'            # your bot token here\n$ export CHANNEL_ID=12345             # your discord channel id\n$ make speedtest                      # run speedtest with default number of messages\n$ make speedtest SPEEDTEST_COUNT=100  # run speedtest with 100 messages\n```\n\n## Development\n\n_Run these commands from the root folder_\n- Install Dependencies: `make deps`\n- Format Code: `make fmt`\n- Run Unit Tests: `make test-unit`\n- Run E2E Tests: `make test-e2e`\n- Run All Tests: `make test-all`\n\n## Styling\n\nPrimary Color: `#8557BA`\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Discord as a Service",
    "version": "0.5.0",
    "project_urls": {
        "Homepage": "https://github.com/joeyagreco/discbase"
    },
    "split_keywords": [
        "discord",
        "database",
        "db"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4db41e3fc8b88f2ed2b8c8e765b5400c36c7717a4dbef56767e3dde4c794aece",
                "md5": "8fe84673ed3ee64c41e91f2f58f482e7",
                "sha256": "21e52c73a5d092973e8987e077698afef89bd0d78a4f208cf38fa6fd8f1abd49"
            },
            "downloads": -1,
            "filename": "discbase-0.5.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8fe84673ed3ee64c41e91f2f58f482e7",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 17646,
            "upload_time": "2024-02-11T17:29:29",
            "upload_time_iso_8601": "2024-02-11T17:29:29.394075Z",
            "url": "https://files.pythonhosted.org/packages/4d/b4/1e3fc8b88f2ed2b8c8e765b5400c36c7717a4dbef56767e3dde4c794aece/discbase-0.5.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "40a56e24b2e92e6707039d3fc473cc0f5aa4d8327566de4915a62c87b681ffc9",
                "md5": "19753a284bb3b611996c9b06d32fee14",
                "sha256": "befcfe14ca34c304e006d2cbf6067477115e4ed66c704635c7564f2e7cbf3af6"
            },
            "downloads": -1,
            "filename": "discbase-0.5.0.tar.gz",
            "has_sig": false,
            "md5_digest": "19753a284bb3b611996c9b06d32fee14",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 14225,
            "upload_time": "2024-02-11T17:29:32",
            "upload_time_iso_8601": "2024-02-11T17:29:32.166993Z",
            "url": "https://files.pythonhosted.org/packages/40/a5/6e24b2e92e6707039d3fc473cc0f5aa4d8327566de4915a62c87b681ffc9/discbase-0.5.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-11 17:29:32",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "joeyagreco",
    "github_project": "discbase",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "discbase"
}
        
Elapsed time: 0.46130s