{"id":37078612,"url":"https://github.com/roshaka/samplr","last_synced_at":"2026-01-14T09:12:08.605Z","repository":{"id":183948467,"uuid":"620952308","full_name":"roshaka/samplr","owner":"roshaka","description":"Samplr is a Python decorator for selecting a subset of items from a list, with options for customisation and informative console printouts.","archived":false,"fork":false,"pushed_at":"2023-04-01T16:05:53.000Z","size":7460,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-23T04:55:59.832Z","etag":null,"topics":["data","data-analysis","data-engineering","decorators","list","python","sampling"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/roshaka.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-03-29T17:38:53.000Z","updated_at":"2023-04-01T16:27:51.000Z","dependencies_parsed_at":"2023-07-26T14:03:51.522Z","dependency_job_id":null,"html_url":"https://github.com/roshaka/samplr","commit_stats":null,"previous_names":["roshaka/samplr"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/roshaka/samplr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roshaka%2Fsamplr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roshaka%2Fsamplr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roshaka%2Fsamplr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roshaka%2Fsamplr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/roshaka","download_url":"https://codeload.github.com/roshaka/samplr/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roshaka%2Fsamplr/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28414905,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T08:38:59.149Z","status":"ssl_error","status_checked_at":"2026-01-14T08:38:43.588Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data","data-analysis","data-engineering","decorators","list","python","sampling"],"created_at":"2026-01-14T09:12:07.836Z","updated_at":"2026-01-14T09:12:08.599Z","avatar_url":"https://github.com/roshaka.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ***S A M P L R***\n`@samplr` is a tiny decorator that provides options for returning a subset of items from a list. It also prints useful information about this sampling process to the terminal for debugging.\n\n# Installation\nInstall `samplr` using pip:\n\n```python\npip install samplr\n```\n\n# Usage\nTo use, decorate a function that returns a list with `@samplr()`. For example:\n\n```python\nfrom samplr import samplr\n\n@samplr(count=3)\ndef get_data():\n    # ... code that returns a list of 10 items of data ...\n```\n\n`get_data()` will now return a list containing just the first 3 items of the original return list, instead of all 100.\n\nThe arguments of `samplr()` are:\n\n- `count` (optional, default `'all'`): The number of items to return. This can be an integer or the string 'all'.\n    - If `count` is a positive integer, the decorated function's returned list will be that length.\n\n    - If `count` is 'all', all items will be returned.\n\n    - If `count` is a negative integer that many items will be ommited from the returned list.\n\n    *Also note:*\n\n    - If `count` \u003e len(original_list), count = 'all'\n\n    - If `count` \u003c -len(original_list), count = 0\n\n- `sample_type` (optional, default `'head'`): The method for selecting the subset of items. The available options are:\n\n    - `'head'`: Select the first *`count`* items in the list.\n\n    - `'tail'`: Select the last *`count`* items in the list.\n\n    - `'random'`: Sample a random subset of *`count`* items from the list.\n\n- `expand` (optional, default `True`): Whether to expand each item in the console print output. Helps with the readability of deeply nested objects.\n\n- `info` (optional, default `True`): Whether to output to the console additional information about the sampling process.\n\n\n\n# Examples\n1. An example of using `@samplr` to select a random subset of 3 items from a list returned by a function:\n\n```python\nfrom samplr import samplr\n\n@samplr(count=3, sample_type='random')\ndef get_data():\n    return [\n        {'name': 'Alice', 'age': 32},\n        {'name': 'Bob', 'age': 25},\n        {'name': 'Charlie', 'age': 41},\n        {'name': 'David', 'age': 19},\n        {'name': 'Eve', 'age': 56},\n        {'name': 'Frank', 'age': 28},\n        {'name': 'Grace', 'age': 39},\n        {'name': 'Heidi', 'age': 22},\n        {'name': 'Isaac', 'age': 47},\n        {'name': 'Jen', 'age': 31},\n    ]\n\nsampled_data = get_data()\n```\n\nThis will return a list of items and output something like this to the terminal:\n\n```python\n◆   ◇   ◆  S A M P L R  ◆   ◇   ◆\n\n◇ @samplr(count = 3, sample_type = random)\n  get_data()\n◆ items returned: 3/10\n\n◇ 0: : {\n    \"name\": \"Alice\",\n    \"age\": 32\n}\n◆ 3: : {\n    \"name\": \"David\",\n    \"age\": 19\n}\n◇ 4: : {\n    \"name\": \"Eve\",\n    \"age\": 56\n}\n\n◆   ◇   ◆  end  ◆   ◇   ◆\n```\n\n*Note the enumeration in the printout shows each item's index in the original list.*\n\n---\n2. An example of using `@samplr` to exclude the last 2 items (with `expand` and `info` set to `False`):\n\n```python\n@samplr(count=-2, sample_type='tail', expand=False, info=False)\ndef get_data():\n    return [\"zero\", \"one\", \"two\", \"three\", \"four\", \"five\", \"six\"]\n```\nThis returns a list of length 5, and outputs a shorter statement to the terminal:\n\n```python\n◆ 0: : \"zero\"\n◇ 1: : \"one\"\n◆ 2: : \"two\"\n◆ 3: : \"three\"\n◆ 4: : \"four\"\n```\n\n---","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froshaka%2Fsamplr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Froshaka%2Fsamplr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froshaka%2Fsamplr/lists"}