{"id":17024949,"url":"https://github.com/devatreides/algorithmia-lib","last_synced_at":"2026-05-03T16:33:37.678Z","repository":{"id":143574568,"uuid":"478824506","full_name":"devatreides/algorithmia-lib","owner":"devatreides","description":"A PHP Client for Algorithmia","archived":false,"fork":false,"pushed_at":"2022-04-07T04:29:35.000Z","size":392,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-22T18:44:49.133Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","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/devatreides.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,"roadmap":null,"authors":null}},"created_at":"2022-04-07T04:20:15.000Z","updated_at":"2022-04-08T04:26:46.000Z","dependencies_parsed_at":null,"dependency_job_id":"7f6b8436-9747-43c2-b3f9-3f4b73f32baf","html_url":"https://github.com/devatreides/algorithmia-lib","commit_stats":null,"previous_names":["devatreides/algorithmia-lib"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/devatreides/algorithmia-lib","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devatreides%2Falgorithmia-lib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devatreides%2Falgorithmia-lib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devatreides%2Falgorithmia-lib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devatreides%2Falgorithmia-lib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devatreides","download_url":"https://codeload.github.com/devatreides/algorithmia-lib/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devatreides%2Falgorithmia-lib/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32577122,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-03T06:36:36.687Z","status":"ssl_error","status_checked_at":"2026-05-03T06:36:09.306Z","response_time":103,"last_error":"SSL_read: 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":[],"created_at":"2024-10-14T07:27:33.890Z","updated_at":"2026-05-03T16:33:37.657Z","avatar_url":"https://github.com/devatreides.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://banners.beyondco.de/Algorithmia%20Lib.png?theme=light\u0026packageManager=composer+require\u0026packageName=tombenevides%2Falgorithmia\u0026pattern=architect\u0026style=style_1\u0026description=fork+of+gorithmiaio\u0026md=1\u0026showWatermark=0\u0026fontSize=100px\u0026images=code\" width=\"600\" alt=\"PHP-Video-Maker\"\u003e\n\u003c/p\u003e\n================================\n\nPHP client library for accessing the Algorithmia API\nFor API documentation, see the [PHPDocs](https://algorithmia.com/developers/clients/php/)\n\n## Installation\nUsing the package manager [Composer](https://packagist.org), run:\n```bash\ncomposer require algorithmia/algorithmia\n```\n\nFor non-Composer system, use the [source](https://github.com/algorithmiaio/algorithmia-php)\n\n## Authentication\nFirst, create an Algorithmia client and authenticate with your API key. You must replace YOUR_API_KEY with your personal key:\n\n```PHP\nrequire_once \"vendor/autoload.php\";\n\n$client = Algorithmia::client('YOUR_API_KEY');\n```\n\nNote that you can also set the api key as an environment variable:\n\n```php\n//run the script with with:\nphp -dALGORITHMIA_API_KEY=ABC12345567483 myAI.php\n\n//and then in myAI.php\n$client = Algorithmia::client();\n\n```\n\nNow you're ready to call AI algorithms from your code. \n\n## Calling algorithms\n\nThe following examples of calling algorithms are organized by type of input/output which vary between algorithms.\n\nNote: a single algorithm may have different input and output types, or accept multiple types of input,\nso consult the algorithm's description for usage examples specific to that algorithm.\n\n### Text input/output\n\nCall an algorithm with text input by simply passing a string into its `pipe` method.\nIf the algorithm output is text, then the `result` field of the response will be a string.\n\n```PHP\n$algo = $client-\u003ealgo('demo/Hello/0.1.1');\n$response = $algo-\u003epipe(\"HAL 9000\");\necho $response-\u003eresult;    # Hello HAL 9000\necho $response-\u003emetadata-\u003econtent_type;  # text\necho $response-\u003emetadata-\u003eduration; # 0.0002127 (just for example; this will vary, of course)\n```\n\nYou can also call algorithms asynchronously and get back a promise:\n\n```PHP\n$algo = $client-\u003ealgo('demo/Hello/0.1.1');\n$async_promise = $algo-\u003epipeAsync(\"HAL 9001\");\n$promise = $async_promise-\u003ethen(function($server_response){\n    //do something when the server returns a response\n    return $server_response;\n});\n$response = $promise-\u003ewait(); //now lets wait for it to finish\necho $response-\u003eresult;   #Hello HAL 9001\n\n//or all at once... but generally you're wanting to do something when the response comes back like above...\n$promise = $algo-\u003epipeAsync(\"HAL 9001\");\n$response = $promise-\u003ewait(); //now lets wait for it to finish\necho $response-\u003eresult;   #Hello HAL 9001\n\n```\n\n\n\n### JSON input/output\n\nCall an algorithm with JSON input by passing in any object that can be serialized to JSON such as strings or arrays. \nFor algorithms that return JSON, the `result` field of the response will be the appropriate\ndeserialized type.\n\n```PHP\n$algo = $client-\u003ealgo('WebPredict/ListAnagrams/0.1.0');\n$result = $algo-\u003epipe([\"transformer\", \"terraforms\", \"retransform\"])-\u003eresult;\n# -\u003e [\"transformer\",\"retransform\"]\n```\n\n### Binary input/output\n\nCall an algorithm with binary input by passing the binary file contents wrapped in an Algorithmia\\ByteArray into the `pipe` method.\nSimilarly, if the algorithm response is binary data, then the `result` field of the response\nwill be binary.\n\n```PHP\n$input = new Algorithmia\\ByteArray(file_get_contents(\"/path/to/myimage.png\"));\n$result = $client-\u003ealgo(\"opencv/SmartThumbnail/0.1\")-\u003epipe($input)-\u003eresult;\n# -\u003e [binary byte sequence]\n\n//if you want to write the result as a file:\nfile_put_contents('/path/to/destination/myimage_output.png', $result);\n```\n\n### Error handling\n\nAPI errors and Algorithm exceptions will result in throwing an `AlgoException`:\n\n```PHP\n$client-\u003ealgo('util/whoopsWrongAlgo')-\u003epipe('Hello, world!')  \n# Algorithmia\\AlgoException: algorithm algo://util/whoopsWrongAlgo not found\n```\n\n### Request options\n\nThe client exposes options that can configure algorithm requests.\nThis includes support for changing the timeout or indicating that the API should include stdout in the response.\n\n```PHP\n$client-\u003esetOptions(['timeout' =\u003e 60]); //all subsequent calls to the client will have this new timeout\n//or \n$response = $client-\u003ealgo('util/echo')-\u003esetOptions(['timeout' =\u003e 60])-\u003epipe($input); //set and call all in one fell swoop!\n\n```\n\n## Working with data\nThe Algorithmia client also provides a way to manage both Algorithmia hosted data\nand data from Dropbox or S3 accounts that you've connected to you Algorithmia account.\n\n### List items in a directory\nWork with a directory by instantiating a `DataDirectory` object.\n\n```PHP\n$foo = $client-\u003edir(\"data://.my/foo\");\n\n//now you can iterate files, folders or all items:\n\n// List files in \"foo\"\nforeach($foo-\u003efiles() as $file){\n    echo $file-\u003egetPath();\n}\n\n// List directories in \"foo\"\nforeach ($foo-\u003efolders() as $dir){\n    echo $dir-\u003egetPath();\n}\n\n// List everything in \"foo\"\nforeach ($foo-\u003elist() as $item) {\n    echo $item-\u003egetPath();\n}\n\n//Does it have this child folder?\n$home = $client-\u003edir(\"data://.my\");\nif($home-\u003econtainsFolder(\"foo\")) {...}\n\n//or does a certain folder exist?\nif($client-\u003edir(\"data://.my/foo2\")-\u003eexists()) { ... }\n\n```\n\n\n### Create directories\nCreate directories by instantiating a `DataDirectory` object and calling `create()`.\n\n```PHP\n$foo = $client-\u003edir(\"data://.my/foo\");\nif(!$foo-\u003eexists()) {\n    $foo-\u003ecreate();\n}\n\n//or just try to create it directly:\n$client-\u003edir(\"dropbox://mynewfolder\")-\u003ecreate();\n\n//note that the default permission is for only your own algorithms to view the directory. \n// if you want to let anyone view it:\n$newdir = $client-\u003edir(\"data://.my/mynewfolder\")-\u003ecreate(ACL::ANYONE); \n\n//check the permission on a folder like so:\nif($newdir-\u003egetReadAcl() == ACL::ANYONE) { ... }\n\n\n```\n\n### Upload files to a directory\n\nUpload files by calling `put` on a `DataFile` object, \nor by calling `putFile` on a `DataDirectory` object.\n\n```PHP\n$foo = $client-\u003edir(\"data://.my/foo\");\n\n//file.csv will be put into \"foo\" directory\n$foo-\u003eputFile(\"/path/to/my/file.csv\"); \n\n//you can also put a file directly to a folder with the name you want:\n$client-\u003efile(\"data://.my/foo/my_new_file.txt\")-\u003eput(\"/path/to/thefile.txt\");\n\n//put text directly into a new text file\n$foo-\u003efile(\"sample.txt\")-\u003eput(\"sample text information\"); //write a new \"sample.txt\" in \"foo\" that has this text\n\n//upload a binary file with a different name\n$file = $client-\u003efile(\"data://.my/foo/binary_test.png\")-\u003eputFile('/path/to/binary/file.png');\nif($file-\u003eresponse-\u003egetStatusCode() !== 200) {...}; //you can also check the result of your action\n\n\n```\n\nNote: you can also instantiate a `DataFile` by either `$client-\u003efile('/path/to/file')` or `$client-\u003edir('path')-\u003efile('filename')`\n\n\n### Download contents of file\n\nDownload files by calling `getString`, `getBytes`, `getJson`, or `getFile` on a `DataFile` object:\n\n```PHP\n$foo_dir = $client-\u003edir(\"data://.my/foo\");\n$file_content_text = $foo_dir-\u003efile(\"sample.txt\")-\u003egetString();  # String object\n$binary_content = $foo_dir-\u003efile(\"binary_file.jpg\")-\u003egetBytes();  # Binary data\n$json_object = $foo_dir-\u003efile(\"myfile.json\")-\u003egetJson(); #Json object\n$temp_file_name = $foo_dir-\u003efile(\"myfile.csv\")-\u003egetFile();   # Download file to a temp file on the filesystem\n$specified_file_name = $foo_dir-\u003efile(\"myfile.csv\")-\u003egetFile('/path/to/file');   # Download file to a specified file location\n\n$file_contents = file_get_contents($temp_file_name); //read the contents of the temp file you downloaded\n```\n\nNote: the `getFile()` method uses streams, so if you're getting large files, that's the way you'll want to do it to avoid memory issues.\n\n### Delete files and directories\n\nDelete files and directories by calling `delete` on their respective `DataFile` or `DataDirectory` object.\nDataDirectories take an optional `force` parameter that indicates whether the directory should be deleted\nif it contains files or other directories.\n\n```PHP\n$foo_dir = $client-\u003edir(\"data://.my/foo\");\n$foo_dir-\u003efile(\"sample.txt\")-\u003edelete(); \n$foo_dir-\u003edelete(); //will fail if the collection isn't empty\n$foo_dir-\u003edelete(true); // true forces deleting the directory and its contents\n```\n\n\n\n### Directory permissions\n\nDirectory permissions may be set when creating a directory, or may be updated on already existing directories.\n\n```PHP\n$foo = $client-\u003edir(\"data://.my/foo_public\");\n\n//create the foo_public directory if it doesn't exist\nif(!$foo-\u003eexists()){\n    $foo-\u003ecreate(ACL::ANYONE);\n}\n\n//check our permission\nif($foo-\u003egetReadAcl() == ACL::ANYONE) { ... } //true\n\n$client-\u003edir(\"data://.my/foo_myalgos\")-\u003ecreate(ACL::MY_ALGORITHMS);   \n$client-\u003edir(\"data://.my/foo_private\")-\u003ecreate(ACL::FULLY_PRIVATE);   \n\n\n```\n\n# Running the tests\n\nRunning the tests will connect to the Algorithmia server and execute a variety of connections and exercises to validate the client. You'll need to provide your API KEY to run the tests in a file called \"apikey.txt\" in the /tests directory. Just create that file and paste in your API KEY with nothing else in the file.\n\nThen you can run the tests by executing:\n`./vendor/bin/phpunit -v tests`\n\nReading the tests is also a great way to see code examples.\n\n# Enjoy!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevatreides%2Falgorithmia-lib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevatreides%2Falgorithmia-lib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevatreides%2Falgorithmia-lib/lists"}