{ "info": { "author": "David Czarnecki", "author_email": "dczarnecki@agoragames.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: POSIX", "Programming Language :: Python", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Topic :: Communications", "Topic :: Software Development :: Libraries", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: System :: Distributed Computing" ], "description": "# amico\n\nRelationships (e.g. friendships) backed by Redis. This is a port of the [amico gem](https://github.com/agoragames/amico).\n\n## Installation\n\n`pip install amico`\n\nMake sure your redis server is running! Redis configuration is outside the scope of this README, but\ncheck out the [Redis documentation](http://redis.io/documentation).\n\n## Usage\n\nBe sure to import the Amico library:\n\n```python\nfrom amico import Amico\n```\n\nAmico is configured with a number of defaults:\n\n```python\n>>> Amico.DEFAULTS\n{'namespace': 'amico', 'pending_follow': False, 'reciprocated_key': 'reciprocated', 'followers_key': 'followers', 'pending_with_key': 'pending_with', 'following_key': 'following', 'page_size': 25, 'pending_key': 'pending', 'blocked_by_key': 'blocked_by', 'default_scope_key': 'default', 'blocked_key': 'blocked'}\n```\n\nThe initializer for Amico takes two optional parameters:\n\n* `options` : Dictionary of updated defaults\n* `redis_connection` : Connection to Redis\n\n```python\n>>> amico = Amico(redis_connection = redis)\n```\n\n```python\n>>> amico.follow(1, 11)\n>>> amico.is_following(1, 11)\nTrue\n>>> amico.is_following(11, 1)\nFalse\n>>> amico.follow(11, 1)\n>>> amico.is_following(11, 1)\nTrue\n>>> amico.following_count(1)\n1\n>>> amico.followers_count(1)\n1\n>>> amico.unfollow(11, 1)\n>>> amico.following_count(11)\n0\n>>> amico.following_count(1)\n1\n>>> amico.is_follower(1, 11)\nFalse\n>>> amico.following(1)\n['11']\n>>> amico.block(1, 11)\n>>> amico.is_following(11, 1)\nFalse\n>>> amico.is_blocked(1, 11)\nTrue\n>>> amico.is_blocked_by(11, 1)\nTrue\n>>> amico.unblock(1, 11)\n>>> amico.is_blocked(1, 11)\nFalse\n>>> amico.is_blocked_by(11, 1)\nFalse\n>>> amico.follow(11, 1)\n>>> amico.follow(1, 11)\n>>> amico.is_reciprocated(1, 11)\nTrue\n>>> amico.reciprocated(1)\n['11']\n```\n\nUse amico (with pending relationships for follow):\n\n```python\n>>> amico = Amico(options = {'pending_follow': True}, redis_connection = redis)\n>>> amico.follow(1, 11)\n>>> amico.follow(11, 1)\n>>> amico.is_pending(1, 11)\nTrue\n>>> amico.is_pending_with(11, 1)\nTrue\n>>> amico.is_pending(11, 1)\nTrue\n>>> amico.is_pending_with(1, 11)\nTrue\n>>> amico.accept(1, 11)\n>>> amico.is_pending(1, 11)\nFalse\n>>> amico.is_pending_with(11, 1)\nFalse\n>>> amico.is_pending(11, 1)\nTrue\n>>> amico.is_pending_with(1, 11)\nTrue\n>>> amico.is_following(1, 11)\nTrue\n>>> amico.is_following(11, 1)\nFalse\n>>> amico.is_follower(11, 1)\nTrue\n>>> amico.is_follower(1, 11)\nFalse\n>>> amico.accept(11, 1)\n>>> amico.is_pending(1, 11)\nFalse\n>>> amico.is_pending_with(11, 1)\nFalse\n>>> amico.is_pending(11, 1)\nFalse\n>>> amico.is_pending_with(1, 11)\nFalse\n>>> amico.is_following(1, 11)\nTrue\n>>> amico.is_following(11, 1)\nTrue\n>>> amico.is_follower(11, 1)\nTrue\n>>> amico.is_follower(1, 11)\nTrue\n>>> amico.is_reciprocated(1, 11)\nTrue\n>>> amico.follow(1, 12)\n>>> amico.is_following(1, 12)\nFalse\n>>> amico.is_pending(1, 12)\nTrue\n>>> amico.deny(1, 12)\n>>> amico.is_following(1, 12)\nFalse\n>>> amico.is_pending(1, 12)\nFalse\n```\n\nAll of the calls support a `scope` parameter to allow you to scope the calls to express relationships for different types of things. For example:\n\n```python\n>>> amico = Amico(options = {'default_scope_key': 'user'}, redis_connection = redis)\n>>> amico.follow(1, 11)\n>>> amico.is_following(1, 11)\nTrue\n>>> amico.is_following(1, 11, scope = 'user')\nTrue\n>>> amico.following(1)\n['11']\n>>> amico.following(1, scope = 'user')\n['11']\n>>> amico.is_following(1, 11, scope = 'project')\nFalse\n>>> amico.follow(1, 11, scope = 'project')\n>>> amico.is_following(1, 11, scope = 'project')\nTrue\n>>> amico.following(1, scope = 'project')\n['11']\n```\n\nYou can retrieve all of a particular type of relationship using the `all(id, type, scope)` call. For example:\n\n```python\n>>> amico.follow(1, 11)\n>>> amico.follow(1, 12)\n>>> amico.all(1, 'following')\n['12', '11']\n```\n\n`type` can be one of 'following', 'followers', 'blocked', 'blocked_by', reciprocated', 'pending' and 'pending_with'. Use this with caution as there may potentially be a large number of items that could be returned from this call.\n\nYou can clear all relationships that have been set for an ID by calling `clear(id, scope)`. You may wish to do this if you allow records to be deleted and you wish to prevent orphaned IDs and inaccurate follower/following counts. Note that this clears *all* relationships in either direction - including blocked and pending. An example:\n\n```python\n>>> amico.follow(11, 1)\n>>> amico.block(12, 1)\n>>> amico.following(11)\n['1']\n>>> amico.blocked(12)\n['1']\n>>> amico.clear(1)\n>>> amico.following(11)\n[]\n>>> amico.blocked(12)\n[]\n```\n\n## FAQ?\n\n### Why use Redis sorted sets and not Redis sets?\n\nBased on the work I did in developing [leaderboard](https://github.com/agoragames/leaderboard),\nleaderboards backed by Redis, I know I wanted to be able to page through the various relationships.\nThis does not seem to be possible given the current set of commands for Redis sets.\n\nAlso, by using the \"score\" in Redis sorted sets that is based on the time of when a relationship\nis established, we can get our \"recent friends\". It is possible that the scoring function may be\nuser-defined in the future to allow for some specific ordering.\n\n## Contributing to amico\n\n* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet\n* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it\n* Fork the project\n* Start a feature/bugfix branch\n* Commit and push until you are happy with your contribution\n* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.\n* Please try not to mess with the version or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.\n\n## Copyright\n\nCopyright (c) 2013 David Czarnecki. See LICENSE.txt for further details.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/agoragames/amico-python", "keywords": "python,redis,friendships", "license": "LICENSE.txt", "maintainer": null, "maintainer_email": null, "name": "amico", "package_url": "https://pypi.org/project/amico/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/amico/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/agoragames/amico-python" }, "release_url": "https://pypi.org/project/amico/1.0.1/", "requires_dist": null, "requires_python": null, "summary": "Relationships (e.g. friendships) backed by Redis.", "version": "1.0.1" }, "last_serial": 786254, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "f7ce88dd550aff6d3bcab105ae1c1fd4", "sha256": "1937b9b5f7ad6688554cee74e5cc98a35567b71ae46b62f6814de8701d2cfc6e" }, "downloads": -1, "filename": "amico-1.0.0.tar.gz", "has_sig": false, "md5_digest": "f7ce88dd550aff6d3bcab105ae1c1fd4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7862, "upload_time": "2013-01-08T02:34:58", "url": "https://files.pythonhosted.org/packages/02/b0/36582f2cc9fdaaf072bde255f6f7266b26abf07d92633829502ea4fae749/amico-1.0.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "ed201e0e9adb30221ab25801c708f3f8", "sha256": "c465985d15f151be4e78221fdf00fdee797ac1d39ce8c4a2acad2132b5b13180" }, "downloads": -1, "filename": "amico-1.0.1.tar.gz", "has_sig": false, "md5_digest": "ed201e0e9adb30221ab25801c708f3f8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7930, "upload_time": "2013-01-08T05:40:37", "url": "https://files.pythonhosted.org/packages/37/96/0f30e738994ae9f4fd9ebcab5f4c5e9ffad6ec0387239a4cf33c222b7cd9/amico-1.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "ed201e0e9adb30221ab25801c708f3f8", "sha256": "c465985d15f151be4e78221fdf00fdee797ac1d39ce8c4a2acad2132b5b13180" }, "downloads": -1, "filename": "amico-1.0.1.tar.gz", "has_sig": false, "md5_digest": "ed201e0e9adb30221ab25801c708f3f8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7930, "upload_time": "2013-01-08T05:40:37", "url": "https://files.pythonhosted.org/packages/37/96/0f30e738994ae9f4fd9ebcab5f4c5e9ffad6ec0387239a4cf33c222b7cd9/amico-1.0.1.tar.gz" } ] }